Skip to content

Commit

Permalink
refactor: refactoring gatsby node utils
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Dec 10, 2023
1 parent 8fe98a8 commit bd19584
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 12 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions www/gatsby-node-functions/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions www/gatsby-node-functions/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { retrieveRootFiles } = require('./component-page-tabs');
const { getThemesSCSSVariables, processComponentSCSSVariables } = require('./theme-variables');

module.exports = {
retrieveRootFiles, getThemesSCSSVariables, processComponentSCSSVariables,
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-syntax */
/**
* This module contains utilities functions
* which deal with displaying multiple themes on docs site.
Expand All @@ -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}
Expand All @@ -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('$')) {
Expand Down Expand Up @@ -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] = {};
}
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit bd19584

Please sign in to comment.