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

View File

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