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

4
.gitignore vendored
View File

@ -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 File

@ -1,4 +0,0 @@
module.exports = {
homeLocation: process.env.HOME_LOCATION,
apiLocation: process.env.API_LOCATION
};

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;

View File

@ -1,29 +1,26 @@
const fs = require('fs-extra');
const gulp = require('gulp');
const { getChallengesForLang } = require('./getChallenges');
const { supportedLangs } = require('./utils');
const { locale } = require('../config/env.json');
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 }),
{}
const { getChallengesForLang } = require('./getChallenges');
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 File

@ -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;

File diff suppressed because it is too large Load Diff

View File

@ -26,8 +26,12 @@
},
"dependencies": {
"@freecodecamp/challenge-md-parser": "^1.0.0",
"invariant": "^2.2.4",
"readdirp-walk": "^1.6.0",
"invariant": "^2.2.4"
},
"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"@commitlint/travis-cli": "^7.0.0",
"@semantic-release/changelog": "^2.0.2",
"@semantic-release/git": "^5.0.0",
"babel-cli": "^6.3.17",
@ -56,6 +60,7 @@
"lodash": "^4.17.10",
"prettier": "^1.13.5",
"prettier-package-json": "^1.6.0",
"readdirp-walk": "^1.6.0",
"rx": "^4.1.0",
"semantic-release": "^15.6.0",
"tap-spec": "^5.0.0",

View File

@ -6,5 +6,5 @@ exports.dasherize = function dasherize(name) {
.replace(/\:/g, '');
};
const supportedLangs = ['english'];
const supportedLangs = ['english', 'spanish'];
exports.supportedLangs = supportedLangs;