* fix: fallback to english challenges All challenges will use the english version if a translated file is not available. SHOW_NEW_CURRICULUM still gates what's shown in the client. * refactor: use closures to simplify createChallenge * refactor: remove messy destructure * refactor: add meta via helper * fix: fallback to [] for meta.required * fix: repair challenge.block * refactor: use CONST_CASE for meta + challenge dirs * fix: catch empty superblocks immediately * fix: clean up path.resolves * fix: invalid syntax in JS project steps * fix: default to english comments and relax tests Instead of always throwing errors when a comment is not translated, the tests now warn while SHOW_UPCOMING_CHANGES is true, so that tests will pass while we're developing and allow translators time to work. They still throw when SHOW_UPCOMING_CHANGES is false to catch issues in production * test: update createCommentMap test * refactor: delete stale comment * refactor: clarify validate with explanatory consts * feat: throw if audited cert falls back to english * fix: stop testing upcoming localized curriculum
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
const path = require('path');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const envData = require('../../config/env.json');
|
|
const {
|
|
getChallengesForLang,
|
|
generateChallengeCreator,
|
|
CHALLENGES_DIR,
|
|
META_DIR,
|
|
getChallengesDirForLang
|
|
} = require('../../curriculum/getChallenges');
|
|
|
|
const { curriculumLocale } = envData;
|
|
|
|
exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale);
|
|
|
|
exports.replaceChallengeNode = () => {
|
|
return async function replaceChallengeNode(filePath) {
|
|
// get the meta so that challengeOrder is accurate
|
|
const blockNameRe = /\d\d-[-\w]+\/([^/]+)\//;
|
|
const posix = path.normalize(filePath).split(path.sep).join(path.posix.sep);
|
|
const blockName = posix.match(blockNameRe)[1];
|
|
const metaPath = path.resolve(META_DIR, `/${blockName}/meta.json`);
|
|
delete require.cache[require.resolve(metaPath)];
|
|
const meta = require(metaPath);
|
|
// TODO: reimplement hot-reloading of certifications
|
|
return await createChallenge(filePath, meta);
|
|
};
|
|
};
|
|
|
|
const createChallenge = generateChallengeCreator(
|
|
CHALLENGES_DIR,
|
|
curriculumLocale
|
|
);
|
|
|
|
exports.buildChallenges = async function buildChallenges() {
|
|
const curriculum = await getChallengesForLang(curriculumLocale);
|
|
const superBlocks = Object.keys(curriculum);
|
|
const blocks = superBlocks
|
|
.map(superBlock => curriculum[superBlock].blocks)
|
|
.reduce((blocks, superBlock) => {
|
|
const currentBlocks = Object.keys(superBlock).map(key => superBlock[key]);
|
|
return blocks.concat(_.flatten(currentBlocks));
|
|
}, []);
|
|
|
|
const builtChallenges = blocks
|
|
.filter(block => !block.isPrivate)
|
|
.map(({ challenges }) => challenges)
|
|
.reduce((accu, current) => accu.concat(current), []);
|
|
return builtChallenges;
|
|
};
|