2018-09-30 11:37:19 +01:00
|
|
|
const _ = require('lodash');
|
|
|
|
|
2018-11-16 18:22:52 +00:00
|
|
|
const {
|
|
|
|
getChallengesForLang,
|
|
|
|
createChallenge,
|
2018-11-18 21:04:04 +03:00
|
|
|
getChallengesDirForLang
|
2018-11-16 18:22:52 +00:00
|
|
|
} = require('../../curriculum/getChallenges');
|
2018-10-09 16:46:14 +05:30
|
|
|
const { locale } = require('../config/env.json');
|
2018-09-30 11:37:19 +01:00
|
|
|
|
2018-11-18 21:04:04 +03:00
|
|
|
exports.localeChallengesRootDir = getChallengesDirForLang(locale);
|
2018-11-16 18:22:52 +00:00
|
|
|
|
2020-05-28 17:24:29 +02:00
|
|
|
exports.replaceChallengeNode = locale => {
|
|
|
|
return async function replaceChallengeNode(fullFilePath) {
|
2020-06-08 15:01:48 +02:00
|
|
|
return await createChallenge(fullFilePath, null, locale);
|
2020-05-28 17:24:29 +02:00
|
|
|
};
|
2019-02-18 19:32:49 +00:00
|
|
|
};
|
2018-11-16 18:22:52 +00:00
|
|
|
|
2018-10-04 14:47:55 +01:00
|
|
|
exports.buildChallenges = async function buildChallenges() {
|
2018-11-16 18:22:52 +00:00
|
|
|
const curriculum = await getChallengesForLang(locale);
|
2018-10-04 14:47:55 +01: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 11:37:19 +01:00
|
|
|
|
2018-11-16 18:22:52 +00:00
|
|
|
const builtChallenges = blocks
|
|
|
|
.filter(block => !block.isPrivate)
|
2020-06-08 15:01:48 +02:00
|
|
|
.map(({ challenges }) => challenges)
|
2018-11-16 18:22:52 +00:00
|
|
|
.reduce((accu, current) => accu.concat(current), []);
|
2018-10-04 14:47:55 +01:00
|
|
|
return builtChallenges;
|
2018-09-30 11:37:19 +01:00
|
|
|
};
|