feat: watch challenges (#34321)
This commit is contained in:
committed by
mrugesh mohapatra
parent
82ec250c75
commit
cee98aef43
@@ -1,7 +1,12 @@
|
||||
const { getChallengesForLang } = require('@freecodecamp/curriculum');
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
|
||||
const utils = require('../utils');
|
||||
const {
|
||||
getChallengesForLang,
|
||||
createChallenge,
|
||||
localeChallengesRootDir
|
||||
} = require('../../curriculum/getChallenges');
|
||||
const utils = require('./');
|
||||
const { locale } = require('../config/env.json');
|
||||
|
||||
const dasherize = utils.dasherize;
|
||||
@@ -10,8 +15,18 @@ const nameify = utils.nameify;
|
||||
const arrToString = arr =>
|
||||
Array.isArray(arr) ? arr.join('\n') : _.toString(arr);
|
||||
|
||||
exports.localeChallengesRootDir = localeChallengesRootDir;
|
||||
|
||||
exports.replaceChallengeNode = function replaceChallengeNode(fullFilePath) {
|
||||
const relativeChallengePath = fullFilePath.replace(
|
||||
localeChallengesRootDir + path.sep,
|
||||
''
|
||||
);
|
||||
return createChallenge(relativeChallengePath);
|
||||
};
|
||||
|
||||
exports.buildChallenges = async function buildChallenges() {
|
||||
const curriculum = await getChallengesForLang( locale );
|
||||
const curriculum = await getChallengesForLang(locale);
|
||||
const superBlocks = Object.keys(curriculum);
|
||||
const blocks = superBlocks
|
||||
.map(superBlock => curriculum[superBlock].blocks)
|
||||
@@ -20,54 +35,57 @@ exports.buildChallenges = async function buildChallenges() {
|
||||
return blocks.concat(_.flatten(currentBlocks));
|
||||
}, []);
|
||||
|
||||
const builtChallenges = blocks.filter(block => !block.isPrivate).map(({ meta, challenges }) => {
|
||||
const {
|
||||
order,
|
||||
time,
|
||||
template,
|
||||
required,
|
||||
superBlock,
|
||||
superOrder,
|
||||
isPrivate,
|
||||
dashedName: blockDashedName,
|
||||
fileName
|
||||
} = meta;
|
||||
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);
|
||||
return challenges.map(challenge => {
|
||||
challenge.name = nameify(challenge.title);
|
||||
|
||||
challenge.dashedName = dasherize(challenge.name);
|
||||
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;
|
||||
});
|
||||
}).reduce((accu, current) => accu.concat(current), [])
|
||||
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;
|
||||
});
|
||||
})
|
||||
.reduce((accu, current) => accu.concat(current), []);
|
||||
return builtChallenges;
|
||||
};
|
||||
|
Reference in New Issue
Block a user