Skip to content

Commit

Permalink
feat(langs): Prep Spanish challenges for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouncey authored and raisedadead committed Oct 10, 2018
1 parent be04413 commit aa668ca
Show file tree
Hide file tree
Showing 8 changed files with 3,001 additions and 5,470 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ node_modules
.DS_Store

curriculum/dist
curriculum/build
curriculum/curricula.json
client/static/js/frame-runner.js
client/static/js/frame-runner.js.map
client/static/_redirects
client/static/_redirects
env.json
4 changes: 0 additions & 4 deletions config/env.js

This file was deleted.

20 changes: 14 additions & 6 deletions curriculum/getChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,43 @@ 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);
curriculum[superBlock] = { superBlock, order, blocks: {} };
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;
}
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;
Expand Down
25 changes: 11 additions & 14 deletions curriculum/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
const fs = require('fs-extra');
const gulp = require('gulp');

const { locale } = require('../config/env.json');

const { getChallengesForLang } = require('./getChallenges');
const { supportedLangs } = require('./utils');

function generateCurricula(done) {
const promises = supportedLangs.map(lang => getChallengesForLang(lang));
return Promise.all(promises)
.then(allLangCurriculum =>
allLangCurriculum.reduce(
(map, current, i) => ({ ...map, [supportedLangs[i]]: current }),
{}
function generateCurriculum(done) {
return getChallengesForLang(locale)
.then(curriculum =>
fs.writeFile(
`./build/curriculum-${locale}.json`,
JSON.stringify(curriculum)
)
)
.then(curricula =>
fs.writeFile('./curricula.json', JSON.stringify(curricula))
)
.then(done);
}

function watchFiles() {
return gulp.watch('./challenges/**/*.md', generateCurricula);
return gulp.watch('./challenges/**/*.md', generateCurriculum);
}

const defaultTask = gulp.series(generateCurricula, watchFiles);
const defaultTask = gulp.series(generateCurriculum, watchFiles);

gulp.task('default', defaultTask);
gulp.task('build', generateCurricula);
gulp.task('build', generateCurriculum);
4 changes: 2 additions & 2 deletions curriculum/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function validateLang(lang) {

function getCurriculum(lang) {
validateLang(lang);
const curricula = require('./curricula.json');
return curricula[lang];
const curriculum = require(`./build/curriculum-${lang}.json`);
return curriculum;
}

exports.getChallengesForLang = getCurriculum;
Loading

0 comments on commit aa668ca

Please sign in to comment.