Permalink
Browse files

feat(langs): Prep Spanish challenges for parsing

  • Loading branch information...
Bouncey authored and raisedadead committed Oct 9, 2018
1 parent be04413 commit aa668ca30e4114076596dadddc6e6681c56889d0
Showing with 3,001 additions and 5,470 deletions.
  1. +3 −1 .gitignore
  2. +0 −4 config/env.js
  3. +14 −6 curriculum/getChallenges.js
  4. +11 −14 curriculum/gulpfile.js
  5. +2 −2 curriculum/lib.js
  6. +2,963 −5,440 curriculum/package-lock.json
  7. +7 −2 curriculum/package.json
  8. +1 −1 curriculum/utils.js
View
@@ -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
View

This file was deleted.

Oops, something went wrong.
@@ -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;
View
@@ -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);
View
@@ -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;
Oops, something went wrong.

0 comments on commit aa668ca

Please sign in to comment.