From 918b44cb4d8a48cac74290cc879140d59ddb0ed0 Mon Sep 17 00:00:00 2001 From: rakannimer Date: Thu, 28 Nov 2019 17:32:09 +0200 Subject: [PATCH] feat(docz-core): add all gatsby node apis to generated gatsby-node Reference : https://www.gatsbyjs.org/docs/node-apis #1285 --- core/docz-core/templates/gatsby-node.tpl.js | 134 ++++++++++++++++++-- 1 file changed, 124 insertions(+), 10 deletions(-) diff --git a/core/docz-core/templates/gatsby-node.tpl.js b/core/docz-core/templates/gatsby-node.tpl.js index d53fa15fd..bd0f18182 100644 --- a/core/docz-core/templates/gatsby-node.tpl.js +++ b/core/docz-core/templates/gatsby-node.tpl.js @@ -2,22 +2,50 @@ const get = require('lodash/get') const NO_OP = () => {} -let gatsbyNodeCustom +const DEFAULT_RESOLVABLE_EXTENSIONS = () => [`.js`, `.jsx`] + +let gatsbyNodeCustom = {} try { gatsbyNodeCustom = require('./gatsby-node.custom') -} catch (err) { - gatsbyNodeCustom = { - onCreateWebpackConfig: NO_OP, - } +} catch (err) {} + +// https://www.gatsbyjs.org/docs/node-apis/ + +exports.createPages = args => { + const createPages = get(gatsbyNodeCustom, 'createPages', NO_OP) + return createPages(args) } -exports.onCreateWebpackConfig = args => { - const onCreateWebpackConfig = get( +exports.createPagesStatefully = args => { + const createPagesStatefully = get( gatsbyNodeCustom, - 'onCreateWebpackConfig', + 'createPagesStatefully', + NO_OP + ) + return createPagesStatefully(args) +} + +exports.createResolvers = args => { + const createResolvers = get(gatsbyNodeCustom, 'createResolvers', NO_OP) + return createResolvers(args) +} + +exports.createSchemaCustomization = args => { + const createSchemaCustomization = get( + gatsbyNodeCustom, + 'createSchemaCustomization', + NO_OP + ) + return createSchemaCustomization(args) +} + +exports.generateSideEffects = args => { + const generateSideEffects = get( + gatsbyNodeCustom, + 'generateSideEffects', NO_OP ) - onCreateWebpackConfig(args) + return generateSideEffects(args) } exports.onCreateBabelConfig = args => { @@ -26,5 +54,91 @@ exports.onCreateBabelConfig = args => { 'onCreateBabelConfig', NO_OP ) - onCreateBabelConfig(args) + return onCreateBabelConfig(args) +} + +exports.onCreateDevServer = args => { + const onCreateDevServer = get(gatsbyNodeCustom, 'onCreateDevServer', NO_OP) + return onCreateDevServer(args) +} + +exports.onCreateNode = args => { + const onCreateNode = get(gatsbyNodeCustom, 'onCreateNode', NO_OP) + return onCreateNode(args) +} + +exports.onCreatePage = args => { + const onCreatePage = get(gatsbyNodeCustom, 'onCreatePage', NO_OP) + return onCreatePage(args) +} + +exports.onCreateWebpackConfig = args => { + const onCreateWebpackConfig = get( + gatsbyNodeCustom, + 'onCreateWebpackConfig', + NO_OP + ) + return onCreateWebpackConfig(args) +} + +exports.onPostBootstrap = args => { + const onPostBootstrap = get(gatsbyNodeCustom, 'onPostBootstrap', NO_OP) + return onPostBootstrap(args) +} + +exports.onPostBuild = args => { + const onPostBuild = get(gatsbyNodeCustom, 'onPostBuild', NO_OP) + return onPostBuild(args) +} + +exports.onPreBootstrap = args => { + const onPreBootstrap = get(gatsbyNodeCustom, 'onPreBootstrap', NO_OP) + return onPreBootstrap(args) +} + +exports.onPreBuild = args => { + const onPreBuild = get(gatsbyNodeCustom, 'onPreBuild', NO_OP) + return onPreBuild(args) +} + +exports.onPreExtractQueries = args => { + const onPreExtractQueries = get( + gatsbyNodeCustom, + 'onPreExtractQueries', + NO_OP + ) + return onPreExtractQueries(args) +} + +exports.onPreInit = args => { + const onPreInit = get(gatsbyNodeCustom, 'onPreInit', NO_OP) + return onPreInit(args) +} + +exports.preprocessSource = args => { + const preprocessSource = get(gatsbyNodeCustom, 'preprocessSource', NO_OP) + return preprocessSource(args) +} + +exports.resolvableExtensions = args => { + const resolvableExtensions = get( + gatsbyNodeCustom, + 'resolvableExtensions', + DEFAULT_RESOLVABLE_EXTENSIONS + ) + return resolvableExtensions(args) +} + +exports.setFieldsOnGraphQLNodeType = args => { + const setFieldsOnGraphQLNodeType = get( + gatsbyNodeCustom, + 'setFieldsOnGraphQLNodeType', + () => ({}) + ) + return setFieldsOnGraphQLNodeType(args) +} + +exports.sourceNodes = args => { + const sourceNodes = get(gatsbyNodeCustom, 'sourceNodes', NO_OP) + return sourceNodes(args) }