diff --git a/client/utils/buildChallenges.js b/client/utils/buildChallenges.js index 1d00fb49e4..db62929153 100644 --- a/client/utils/buildChallenges.js +++ b/client/utils/buildChallenges.js @@ -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; +} diff --git a/curriculum/getChallenges.js b/curriculum/getChallenges.js index 0d105e5483..76ed421e23 100644 --- a/curriculum/getChallenges.js +++ b/curriculum/getChallenges.js @@ -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; }