2021-06-28 08:08:11 +00:00
|
|
|
const path = require('path');
|
2021-08-09 08:30:31 +00:00
|
|
|
|
2021-08-02 13:39:40 +00:00
|
|
|
const _ = require('lodash');
|
2018-09-30 10:37:19 +00:00
|
|
|
|
2021-08-02 13:39:40 +00:00
|
|
|
const envData = require('../../config/env.json');
|
2018-11-16 18:22:52 +00:00
|
|
|
const {
|
|
|
|
getChallengesForLang,
|
2022-04-15 14:17:49 +00:00
|
|
|
generateChallengeCreator,
|
|
|
|
CHALLENGES_DIR,
|
|
|
|
META_DIR,
|
2018-11-18 18:04:04 +00:00
|
|
|
getChallengesDirForLang
|
2018-11-16 18:22:52 +00:00
|
|
|
} = require('../../curriculum/getChallenges');
|
2021-03-25 19:13:43 +00:00
|
|
|
|
2022-03-22 06:05:38 +00:00
|
|
|
const { curriculumLocale } = envData;
|
2018-09-30 10:37:19 +00:00
|
|
|
|
2020-12-16 08:02:52 +00:00
|
|
|
exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale);
|
2018-11-16 18:22:52 +00:00
|
|
|
|
2020-09-02 09:31:10 +00:00
|
|
|
exports.replaceChallengeNode = () => {
|
|
|
|
return async function replaceChallengeNode(filePath) {
|
2021-06-28 08:08:11 +00:00
|
|
|
// get the meta so that challengeOrder is accurate
|
|
|
|
const blockNameRe = /\d\d-[-\w]+\/([^/]+)\//;
|
2021-07-06 06:40:53 +00:00
|
|
|
const posix = path.normalize(filePath).split(path.sep).join(path.posix.sep);
|
|
|
|
const blockName = posix.match(blockNameRe)[1];
|
2022-05-06 11:44:14 +00:00
|
|
|
const metaPath = path.resolve(META_DIR, `${blockName}/meta.json`);
|
2021-06-28 08:08:11 +00:00
|
|
|
delete require.cache[require.resolve(metaPath)];
|
|
|
|
const meta = require(metaPath);
|
2021-12-21 18:35:51 +00:00
|
|
|
// TODO: reimplement hot-reloading of certifications
|
2022-04-15 14:17:49 +00:00
|
|
|
return await createChallenge(filePath, meta);
|
2020-05-28 15:24:29 +00:00
|
|
|
};
|
2019-02-18 19:32:49 +00:00
|
|
|
};
|
2018-11-16 18:22:52 +00:00
|
|
|
|
2022-04-15 14:17:49 +00:00
|
|
|
const createChallenge = generateChallengeCreator(
|
|
|
|
CHALLENGES_DIR,
|
|
|
|
curriculumLocale
|
|
|
|
);
|
|
|
|
|
2018-10-04 13:47:55 +00:00
|
|
|
exports.buildChallenges = async function buildChallenges() {
|
2020-12-16 08:02:52 +00:00
|
|
|
const curriculum = await getChallengesForLang(curriculumLocale);
|
2018-10-04 13:47:55 +00:00
|
|
|
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-09-30 10:37:19 +00:00
|
|
|
|
2018-11-16 18:22:52 +00:00
|
|
|
const builtChallenges = blocks
|
|
|
|
.filter(block => !block.isPrivate)
|
2020-06-08 13:01:48 +00:00
|
|
|
.map(({ challenges }) => challenges)
|
2018-11-16 18:22:52 +00:00
|
|
|
.reduce((accu, current) => accu.concat(current), []);
|
2018-10-04 13:47:55 +00:00
|
|
|
return builtChallenges;
|
2018-09-30 10:37:19 +00:00
|
|
|
};
|