mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(dev): preserve step order during hot reload by reloading all chal… (#62048)
This commit is contained in:
@@ -2,43 +2,69 @@ const path = require('path');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const envData = require('../config/env.json');
|
||||
const { getChallengesForLang } = require('../../curriculum/get-challenges');
|
||||
|
||||
const {
|
||||
getContentDir,
|
||||
getBlockCreator
|
||||
getBlockCreator,
|
||||
getSuperblocks,
|
||||
superBlockToFilename
|
||||
} = require('../../curriculum/build-curriculum');
|
||||
const { getBlockStructure } = require('../../curriculum/file-handler');
|
||||
const { getSuperblocks } = require('../../curriculum/build-curriculum');
|
||||
const {
|
||||
getBlockStructure,
|
||||
getSuperblockStructure
|
||||
} = require('../../curriculum/file-handler');
|
||||
const { transformSuperBlock } = require('../../curriculum/build-superblock');
|
||||
const { getSuperOrder } = require('../../curriculum/utils');
|
||||
|
||||
const { curriculumLocale } = envData;
|
||||
const curriculumLocale = process.env.CURRICULUM_LOCALE || 'english';
|
||||
|
||||
exports.localeChallengesRootDir = getContentDir(curriculumLocale);
|
||||
|
||||
const blockCreator = getBlockCreator(curriculumLocale);
|
||||
|
||||
function getBlockMetadata(block, superBlock) {
|
||||
// Compute metadata for the given block in the specified superblock
|
||||
const sbFilename = superBlockToFilename[superBlock];
|
||||
const sbData = getSuperblockStructure(sbFilename);
|
||||
const blocks = transformSuperBlock(sbData, {
|
||||
showComingSoon: process.env.SHOW_UPCOMING_CHANGES === 'true'
|
||||
});
|
||||
|
||||
const order = blocks.findIndex(b => b.dashedName === block);
|
||||
const superOrder = getSuperOrder(superBlock);
|
||||
|
||||
if (order === -1) {
|
||||
throw new Error(`Block ${block} not found in superblock ${superBlock}`);
|
||||
}
|
||||
|
||||
return { order, superOrder };
|
||||
}
|
||||
|
||||
exports.replaceChallengeNodes = () => {
|
||||
return async function replaceChallengeNodes(filePath) {
|
||||
const parentDir = path.dirname(filePath);
|
||||
const block = path.basename(parentDir);
|
||||
const filename = path.basename(filePath);
|
||||
|
||||
console.log(`Replacing challenge node for ${filePath}`);
|
||||
console.log(`Replacing challenge nodes for ${filePath}`);
|
||||
const meta = getBlockStructure(block);
|
||||
const superblocks = getSuperblocks(block);
|
||||
|
||||
const challenge = await blockCreator.createChallenge({
|
||||
filename,
|
||||
block,
|
||||
meta,
|
||||
isAudited: true
|
||||
});
|
||||
// Create a challenge for each superblock containing this block
|
||||
const challenges = await Promise.all(
|
||||
superblocks.map(async superBlock => {
|
||||
const { order, superOrder } = getBlockMetadata(block, superBlock);
|
||||
return blockCreator.createChallenge({
|
||||
filename,
|
||||
block,
|
||||
meta: { ...meta, superBlock, order, superOrder },
|
||||
isAudited: true
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return superblocks.map(superBlock => ({
|
||||
...challenge,
|
||||
superBlock
|
||||
}));
|
||||
return challenges;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user