feat(langs): Prep Spanish challenges for parsing

This commit is contained in:
Bouncey
2018-10-09 20:26:37 +01:00
committed by mrugesh mohapatra
parent be04413f4d
commit aa668ca30e
8 changed files with 2998 additions and 5467 deletions

View File

@ -4,17 +4,20 @@ const readDirP = require('readdirp-walk');
const { parseMarkdown } = require('@freecodecamp/challenge-md-parser');
const challengesDir = path.resolve(__dirname, './challenges');
exports.getChallengesForLang = function getChallengesForLang(lang) {
let curriculum = {};
return new Promise(resolve =>
readDirP({ root: path.resolve(__dirname, `./challenges/${lang}`) })
readDirP({ root: path.resolve(challengesDir, `./${lang}`) })
.on('data', file => buildCurriculum(file, curriculum))
.on('end', () => resolve(curriculum))
);
};
async function buildCurriculum(file, curriculum) {
const { name, depth, path, fullPath, stat } = file;
const { name, depth, path: filePath, fullPath, stat } = file;
if (depth === 1 && stat.isDirectory()) {
// extract the superBlock info
const { order, name: superBlock } = superBlockInfo(name);
@ -22,8 +25,13 @@ async function buildCurriculum(file, curriculum) {
return;
}
if (depth === 2 && stat.isDirectory()) {
const blockMeta = require(`${fullPath}/meta.json`);
const { name: superBlock } = superBlockInfoFromPath(path);
const blockName = getBlockNameFromPath(filePath);
const metaPath = path.resolve(
__dirname,
`./challenges/_meta/${blockName}/meta.json`
);
const blockMeta = require(metaPath);
const { name: superBlock } = superBlockInfoFromPath(filePath);
const blockInfo = { meta: blockMeta, challenges: [] };
curriculum[superBlock].blocks[name] = blockInfo;
return;
@ -31,8 +39,8 @@ async function buildCurriculum(file, curriculum) {
if (name === 'meta.json') {
return;
}
const block = getBlockNameFromPath(path);
const { name: superBlock } = superBlockInfoFromPath(path);
const block = getBlockNameFromPath(filePath);
const { name: superBlock } = superBlockInfoFromPath(filePath);
const challenge = await parseMarkdown(fullPath);
const challengeBlock = curriculum[superBlock].blocks[block];
const { meta } = challengeBlock;