From bd195846b9fca83ca50ad1904445a975e2d8b69a Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Sun, 10 Dec 2023 19:16:55 +0200 Subject: [PATCH] refactor: refactoring gatsby node utils --- .../createCssUtilityClassNodes.js | 0 www/{utils => gatsby-node-functions}/createPages.js | 3 +-- www/gatsby-node-functions/index.js | 9 +++++++++ www/{utils => gatsby-node-functions}/onCreateNode.js | 0 www/{utils => gatsby-node-functions}/onCreatePage.js | 0 .../onCreateWebpackConfig.js | 0 .../utils/component-page-tabs.js} | 0 www/gatsby-node-functions/utils/index.js | 6 ++++++ .../utils/theme-variables.js} | 8 +++----- www/gatsby-node.js | 12 +++++++----- 10 files changed, 26 insertions(+), 12 deletions(-) rename www/{utils => gatsby-node-functions}/createCssUtilityClassNodes.js (100%) rename www/{utils => gatsby-node-functions}/createPages.js (95%) create mode 100644 www/gatsby-node-functions/index.js rename www/{utils => gatsby-node-functions}/onCreateNode.js (100%) rename www/{utils => gatsby-node-functions}/onCreatePage.js (100%) rename www/{utils => gatsby-node-functions}/onCreateWebpackConfig.js (100%) rename www/{utils/tabs-utils.js => gatsby-node-functions/utils/component-page-tabs.js} (100%) create mode 100644 www/gatsby-node-functions/utils/index.js rename www/{theme-utils.js => gatsby-node-functions/utils/theme-variables.js} (93%) diff --git a/www/utils/createCssUtilityClassNodes.js b/www/gatsby-node-functions/createCssUtilityClassNodes.js similarity index 100% rename from www/utils/createCssUtilityClassNodes.js rename to www/gatsby-node-functions/createCssUtilityClassNodes.js diff --git a/www/utils/createPages.js b/www/gatsby-node-functions/createPages.js similarity index 95% rename from www/utils/createPages.js rename to www/gatsby-node-functions/createPages.js index 63c1dd4306..5a602dc6b1 100644 --- a/www/utils/createPages.js +++ b/www/gatsby-node-functions/createPages.js @@ -1,9 +1,8 @@ const path = require('path'); const fs = require('fs'); -const { getThemesSCSSVariables, processComponentSCSSVariables } = require('../theme-utils'); +const { getThemesSCSSVariables, processComponentSCSSVariables, retrieveRootFiles } = require('./utils'); const { INSIGHTS_PAGES } = require('../src/config'); const componentsUsage = require('../src/utils/componentsUsage'); -const { retrieveRootFiles } = require('./tabs-utils'); async function createPages(graphql, actions, reporter) { // Destructure the createPage function from the actions object diff --git a/www/gatsby-node-functions/index.js b/www/gatsby-node-functions/index.js new file mode 100644 index 0000000000..3a2ba839dd --- /dev/null +++ b/www/gatsby-node-functions/index.js @@ -0,0 +1,9 @@ +const createPages = require('./createPages'); +const onCreateNode = require('./onCreateNode'); +const onCreateWebpackConfig = require('./onCreateWebpackConfig'); +const createCssUtilityClassNodes = require('./createCssUtilityClassNodes'); +const onCreatePage = require('./onCreatePage'); + +module.exports = { + createPages, onCreateNode, onCreateWebpackConfig, createCssUtilityClassNodes, onCreatePage, +}; diff --git a/www/utils/onCreateNode.js b/www/gatsby-node-functions/onCreateNode.js similarity index 100% rename from www/utils/onCreateNode.js rename to www/gatsby-node-functions/onCreateNode.js diff --git a/www/utils/onCreatePage.js b/www/gatsby-node-functions/onCreatePage.js similarity index 100% rename from www/utils/onCreatePage.js rename to www/gatsby-node-functions/onCreatePage.js diff --git a/www/utils/onCreateWebpackConfig.js b/www/gatsby-node-functions/onCreateWebpackConfig.js similarity index 100% rename from www/utils/onCreateWebpackConfig.js rename to www/gatsby-node-functions/onCreateWebpackConfig.js diff --git a/www/utils/tabs-utils.js b/www/gatsby-node-functions/utils/component-page-tabs.js similarity index 100% rename from www/utils/tabs-utils.js rename to www/gatsby-node-functions/utils/component-page-tabs.js diff --git a/www/gatsby-node-functions/utils/index.js b/www/gatsby-node-functions/utils/index.js new file mode 100644 index 0000000000..44887eb630 --- /dev/null +++ b/www/gatsby-node-functions/utils/index.js @@ -0,0 +1,6 @@ +const { retrieveRootFiles } = require('./component-page-tabs'); +const { getThemesSCSSVariables, processComponentSCSSVariables } = require('./theme-variables'); + +module.exports = { + retrieveRootFiles, getThemesSCSSVariables, processComponentSCSSVariables, +}; diff --git a/www/theme-utils.js b/www/gatsby-node-functions/utils/theme-variables.js similarity index 93% rename from www/theme-utils.js rename to www/gatsby-node-functions/utils/theme-variables.js index 249784e145..520c3a7087 100644 --- a/www/theme-utils.js +++ b/www/gatsby-node-functions/utils/theme-variables.js @@ -1,3 +1,4 @@ +/* eslint-disable no-restricted-syntax */ /** * This module contains utilities functions * which deal with displaying multiple themes on docs site. @@ -6,7 +7,7 @@ const path = require('path'); const fs = require('fs'); const readline = require('readline'); -const { THEMES } = require('./theme-config'); +const { THEMES } = require('../../theme-config'); /** * Parses SCSS variables stylesheet into JS object of the form {variable: value} @@ -30,7 +31,6 @@ async function parseSCSSIntoObject(pathToVariables) { let currentVariable = ''; let currentValue = ''; - // eslint-disable-next-line no-restricted-syntax for await (const line of rl) { // we encountered new variable if (line.startsWith('$')) { @@ -64,11 +64,10 @@ async function parseSCSSIntoObject(pathToVariables) { async function getThemesSCSSVariables() { const themeSCSSVariables = {}; - // eslint-disable-next-line no-restricted-syntax for (const { id, pathToVariables } of THEMES) { if (pathToVariables) { // eslint-disable-next-line no-await-in-loop - themeSCSSVariables[id] = await parseSCSSIntoObject(path.resolve(__dirname, '../node_modules', pathToVariables)); + themeSCSSVariables[id] = await parseSCSSIntoObject(path.resolve(__dirname, '../../../node_modules', pathToVariables)); } else { themeSCSSVariables[id] = {}; } @@ -110,7 +109,6 @@ async function processComponentSCSSVariables(pathToStylesheet, themesData) { }); } - // eslint-disable-next-line no-restricted-syntax for await (const line of rl) { if (line.startsWith('$')) { if (currentVar && currentValue) { diff --git a/www/gatsby-node.js b/www/gatsby-node.js index 3400d41792..9b702126b4 100644 --- a/www/gatsby-node.js +++ b/www/gatsby-node.js @@ -4,11 +4,13 @@ * See: https://www.gatsbyjs.com/docs/node-apis/ */ -const createPages = require('./utils/createPages'); -const onCreateNode = require('./utils/onCreateNode'); -const onCreateWebpackConfig = require('./utils/onCreateWebpackConfig'); -const createCssUtilityClassNodes = require('./utils/createCssUtilityClassNodes'); -const onCreatePage = require('./utils/onCreatePage'); +const { + createPages, + onCreateNode, + onCreateWebpackConfig, + createCssUtilityClassNodes, + onCreatePage, +} = require('./gatsby-node-functions'); exports.onCreateWebpackConfig = ({ actions }) => onCreateWebpackConfig(actions);