fix: watch challenges
This commit is contained in:
@ -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,55 +33,32 @@ 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;
|
||||
|
||||
return challenges.map(challenge => {
|
||||
challenge.name = nameify(challenge.title);
|
||||
|
||||
challenge.dashedName = dasherize(challenge.name);
|
||||
|
||||
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.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
|
||||
.split('-')
|
||||
.map(word => _.capitalize(word))
|
||||
.join(' ');
|
||||
challenge.required = required;
|
||||
challenge.template = template;
|
||||
return challenge;
|
||||
});
|
||||
})
|
||||
.map(({ challenges }) => challenges.map(prepareChallenge))
|
||||
.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 = challenge.superBlock
|
||||
.split('-')
|
||||
.map(word => _.capitalize(word))
|
||||
.join(' ');
|
||||
return challenge;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user