refactor(multi) move preparation into curriculum

This commit is contained in:
Oliver Eyton-Williams
2020-06-08 15:01:48 +02:00
committed by Mrugesh Mohapatra
parent 88de5bc602
commit 754a33970e
3 changed files with 53 additions and 43 deletions

View File

@@ -5,18 +5,13 @@ const {
createChallenge,
getChallengesDirForLang
} = require('../../curriculum/getChallenges');
const { dasherize, nameify } = require('../../utils/slugs');
const { locale } = require('../config/env.json');
const { blockNameify } = require('../../utils/block-nameify');
const arrToString = arr =>
Array.isArray(arr) ? arr.join('\n') : _.toString(arr);
exports.localeChallengesRootDir = getChallengesDirForLang(locale);
exports.replaceChallengeNode = locale => {
return async function replaceChallengeNode(fullFilePath) {
return prepareChallenge(await createChallenge(fullFilePath, null, locale));
return await createChallenge(fullFilePath, null, locale);
};
};
@@ -32,29 +27,7 @@ exports.buildChallenges = async function buildChallenges() {
const builtChallenges = blocks
.filter(block => !block.isPrivate)
.map(({ challenges }) => challenges.map(prepareChallenge))
.map(({ challenges }) => challenges)
.reduce((accu, current) => accu.concat(current), []);
return builtChallenges;
};
function prepareChallenge(challenge) {
challenge.name = nameify(challenge.title);
if (challenge.files) {
challenge.files = _.reduce(
challenge.files,
(map, file) => {
map[file.key] = {
...file,
head: arrToString(file.head),
contents: arrToString(file.contents),
tail: arrToString(file.tail)
};
return map;
},
{}
);
}
challenge.block = dasherize(challenge.block);
challenge.superBlock = blockNameify(challenge.superBlock);
return challenge;
}