Files
freeCodeCamp/client/utils/buildChallenges.js
2021-02-03 15:22:07 +05:30

35 lines
1.1 KiB
JavaScript

const _ = require('lodash');
const {
getChallengesForLang,
createChallenge,
challengesDir,
getChallengesDirForLang
} = require('../../curriculum/getChallenges');
const { curriculumLocale } = require('../../config/env.json');
exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale);
exports.replaceChallengeNode = () => {
return async function replaceChallengeNode(filePath) {
return await createChallenge(challengesDir, filePath, curriculumLocale);
};
};
exports.buildChallenges = async function buildChallenges() {
const curriculum = await getChallengesForLang(curriculumLocale);
const superBlocks = Object.keys(curriculum);
const blocks = superBlocks
.map(superBlock => curriculum[superBlock].blocks)
.reduce((blocks, superBlock) => {
const currentBlocks = Object.keys(superBlock).map(key => superBlock[key]);
return blocks.concat(_.flatten(currentBlocks));
}, []);
const builtChallenges = blocks
.filter(block => !block.isPrivate)
.map(({ challenges }) => challenges)
.reduce((accu, current) => accu.concat(current), []);
return builtChallenges;
};