Files
freeCodeCamp/client/utils/buildChallenges.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

const _ = require('lodash');
2018-11-16 18:22:52 +00:00
const {
getChallengesForLang,
createChallenge,
getChallengesDirForLang
2018-11-16 18:22:52 +00:00
} = require('../../curriculum/getChallenges');
const { locale } = require('../config/env.json');
exports.localeChallengesRootDir = getChallengesDirForLang(locale);
2018-11-16 18:22:52 +00:00
exports.replaceChallengeNode = locale => {
return async function replaceChallengeNode(fullFilePath) {
return await createChallenge(fullFilePath, null, locale);
};
};
2018-11-16 18:22:52 +00:00
exports.buildChallenges = async function buildChallenges() {
2018-11-16 18:22:52 +00:00
const curriculum = await getChallengesForLang(locale);
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));
}, []);
2018-11-16 18:22:52 +00:00
const builtChallenges = blocks
.filter(block => !block.isPrivate)
.map(({ challenges }) => challenges)
2018-11-16 18:22:52 +00:00
.reduce((accu, current) => accu.concat(current), []);
return builtChallenges;
};