fix(client): source super block structure in graphql and store in redux (#62613)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Huyen Nguyen
2025-10-17 10:19:19 +07:00
committed by GitHub
parent ed568658c1
commit c29d161a75
8 changed files with 204 additions and 67 deletions
@@ -1,9 +1,11 @@
const path = require('path');
const chokidar = require('chokidar');
const { getSuperblockStructure } = require('../../../curriculum/file-handler');
const { createChallengeNode } = require('./create-challenge-nodes');
exports.sourceNodes = function sourceChallengesSourceNodes(
{ actions, reporter },
{ actions, reporter, createNodeId, createContentDigest },
pluginOptions
) {
const { source, onSourceChange, curriculumPath } = pluginOptions;
@@ -67,9 +69,13 @@ exports.sourceNodes = function sourceChallengesSourceNodes(
function sourceAndCreateNodes() {
return source()
.then(challenges => Promise.all(challenges))
.then(challenges =>
challenges.map(challenge => createVisibleChallenge(challenge))
)
.then(challenges => {
// create challenge nodes
challenges.forEach(challenge => createVisibleChallenge(challenge));
// create superblock structure nodes
createSuperBlockStructureNodes();
return Promise.resolve();
})
.catch(e => {
console.log(e);
reporter.panic(`fcc-source-challenges
@@ -84,6 +90,50 @@ exports.sourceNodes = function sourceChallengesSourceNodes(
createNode(createChallengeNode(challenge, reporter, options));
}
function createSuperBlockStructureNodes() {
const buildCurriculumPath = path.resolve(
curriculumPath,
'..',
'..',
'build-curriculum'
);
const buildCurriculum = require(buildCurriculumPath);
const superBlockToFilename = buildCurriculum.superBlockToFilename;
if (!superBlockToFilename) {
reporter.panic(
'superBlockToFilename is missing from build-curriculum. This map is required.'
);
}
Object.keys(superBlockToFilename).forEach(superBlock => {
const filename = superBlockToFilename[superBlock] || superBlock;
try {
const structure = getSuperblockStructure(filename);
const nodeId = createNodeId(`SuperBlockStructure-${superBlock}`);
const nodeContent = JSON.stringify(structure);
createNode({
...structure,
superBlock,
id: nodeId,
parent: null,
children: [],
internal: {
type: 'SuperBlockStructure',
content: nodeContent,
contentDigest: createContentDigest(structure)
}
});
} catch (err) {
reporter.warn(
`Could not load structure for ${superBlock} (${filename}): ${err.message}`
);
}
});
}
return new Promise((resolve, reject) => {
watcher.on('ready', () => sourceAndCreateNodes().then(resolve, reject));
});