fix: watch challenges

This commit is contained in:
Valeriy
2018-11-18 21:16:09 +03:00
committed by Stuart Taylor
parent 4c1b8ce52c
commit 088cbb684e
2 changed files with 43 additions and 53 deletions

View File

@ -16,9 +16,10 @@ const arrToString = arr =>
exports.localeChallengesRootDir = getChallengesDirForLang(locale);
exports.replaceChallengeNode = function replaceChallengeNode(fullFilePath) {
return createChallenge(fullFilePath);
};
exports.replaceChallengeNode =
async function replaceChallengeNode(fullFilePath) {
return prepareChallenge(await createChallenge(fullFilePath));
};
exports.buildChallenges = async function buildChallenges() {
const curriculum = await getChallengesForLang(locale);
@ -32,24 +33,13 @@ exports.buildChallenges = async function buildChallenges() {
const builtChallenges = blocks
.filter(block => !block.isPrivate)
.map(({ meta, challenges }) => {
const {
order,
time,
template,
required,
superBlock,
superOrder,
isPrivate,
dashedName: blockDashedName,
fileName
} = meta;
.map(({ challenges }) => challenges.map(prepareChallenge))
.reduce((accu, current) => accu.concat(current), []);
return builtChallenges;
};
return challenges.map(challenge => {
function prepareChallenge(challenge) {
challenge.name = nameify(challenge.title);
challenge.dashedName = dasherize(challenge.name);
if (challenge.files) {
challenge.files = _.reduce(
challenge.files,
@ -65,22 +55,10 @@ exports.buildChallenges = async function buildChallenges() {
{}
);
}
challenge.fileName = fileName;
challenge.order = order;
challenge.block = blockDashedName;
challenge.isPrivate = challenge.isPrivate || isPrivate;
challenge.isRequired = !!challenge.isRequired;
challenge.time = time;
challenge.superOrder = superOrder;
challenge.superBlock = superBlock
challenge.block = dasherize(challenge.block);
challenge.superBlock = challenge.superBlock
.split('-')
.map(word => _.capitalize(word))
.join(' ');
challenge.required = required;
challenge.template = template;
return challenge;
});
})
.reduce((accu, current) => accu.concat(current), []);
return builtChallenges;
};
}

View File

@ -83,13 +83,25 @@ async function createChallenge(fullPath, maybeMeta) {
meta.challengeOrder,
([id]) => id === challenge.id
);
const { name: blockName, order, superOrder } = meta;
const {
name: blockName,
order,
superOrder,
isPrivate,
required = [],
template,
time
} = meta;
challenge.block = blockName;
challenge.dashedName = dasherize(challenge.title);
challenge.order = order;
challenge.superOrder = superOrder;
challenge.superBlock = superBlock;
challenge.challengeOrder = challengeOrder;
challenge.isPrivate = challenge.isPrivate || isPrivate;
challenge.required = required.concat(challenge.required || []);
challenge.template = template;
challenge.time = time;
return challenge;
}