feat(langs): Prep Spanish challenges for parsing
This commit is contained in:
committed by
mrugesh mohapatra
parent
be04413f4d
commit
aa668ca30e
2
.gitignore
vendored
2
.gitignore
vendored
@ -16,7 +16,9 @@ node_modules
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
curriculum/dist
|
curriculum/dist
|
||||||
|
curriculum/build
|
||||||
curriculum/curricula.json
|
curriculum/curricula.json
|
||||||
client/static/js/frame-runner.js
|
client/static/js/frame-runner.js
|
||||||
client/static/js/frame-runner.js.map
|
client/static/js/frame-runner.js.map
|
||||||
client/static/_redirects
|
client/static/_redirects
|
||||||
|
env.json
|
@ -1,4 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
homeLocation: process.env.HOME_LOCATION,
|
|
||||||
apiLocation: process.env.API_LOCATION
|
|
||||||
};
|
|
@ -4,17 +4,20 @@ const readDirP = require('readdirp-walk');
|
|||||||
|
|
||||||
const { parseMarkdown } = require('@freecodecamp/challenge-md-parser');
|
const { parseMarkdown } = require('@freecodecamp/challenge-md-parser');
|
||||||
|
|
||||||
|
const challengesDir = path.resolve(__dirname, './challenges');
|
||||||
|
|
||||||
exports.getChallengesForLang = function getChallengesForLang(lang) {
|
exports.getChallengesForLang = function getChallengesForLang(lang) {
|
||||||
let curriculum = {};
|
let curriculum = {};
|
||||||
return new Promise(resolve =>
|
return new Promise(resolve =>
|
||||||
readDirP({ root: path.resolve(__dirname, `./challenges/${lang}`) })
|
readDirP({ root: path.resolve(challengesDir, `./${lang}`) })
|
||||||
.on('data', file => buildCurriculum(file, curriculum))
|
.on('data', file => buildCurriculum(file, curriculum))
|
||||||
.on('end', () => resolve(curriculum))
|
.on('end', () => resolve(curriculum))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function buildCurriculum(file, 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()) {
|
if (depth === 1 && stat.isDirectory()) {
|
||||||
// extract the superBlock info
|
// extract the superBlock info
|
||||||
const { order, name: superBlock } = superBlockInfo(name);
|
const { order, name: superBlock } = superBlockInfo(name);
|
||||||
@ -22,8 +25,13 @@ async function buildCurriculum(file, curriculum) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (depth === 2 && stat.isDirectory()) {
|
if (depth === 2 && stat.isDirectory()) {
|
||||||
const blockMeta = require(`${fullPath}/meta.json`);
|
const blockName = getBlockNameFromPath(filePath);
|
||||||
const { name: superBlock } = superBlockInfoFromPath(path);
|
const metaPath = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
`./challenges/_meta/${blockName}/meta.json`
|
||||||
|
);
|
||||||
|
const blockMeta = require(metaPath);
|
||||||
|
const { name: superBlock } = superBlockInfoFromPath(filePath);
|
||||||
const blockInfo = { meta: blockMeta, challenges: [] };
|
const blockInfo = { meta: blockMeta, challenges: [] };
|
||||||
curriculum[superBlock].blocks[name] = blockInfo;
|
curriculum[superBlock].blocks[name] = blockInfo;
|
||||||
return;
|
return;
|
||||||
@ -31,8 +39,8 @@ async function buildCurriculum(file, curriculum) {
|
|||||||
if (name === 'meta.json') {
|
if (name === 'meta.json') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const block = getBlockNameFromPath(path);
|
const block = getBlockNameFromPath(filePath);
|
||||||
const { name: superBlock } = superBlockInfoFromPath(path);
|
const { name: superBlock } = superBlockInfoFromPath(filePath);
|
||||||
const challenge = await parseMarkdown(fullPath);
|
const challenge = await parseMarkdown(fullPath);
|
||||||
const challengeBlock = curriculum[superBlock].blocks[block];
|
const challengeBlock = curriculum[superBlock].blocks[block];
|
||||||
const { meta } = challengeBlock;
|
const { meta } = challengeBlock;
|
||||||
|
@ -1,29 +1,26 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
|
|
||||||
const { getChallengesForLang } = require('./getChallenges');
|
const { locale } = require('../config/env.json');
|
||||||
const { supportedLangs } = require('./utils');
|
|
||||||
|
|
||||||
function generateCurricula(done) {
|
const { getChallengesForLang } = require('./getChallenges');
|
||||||
const promises = supportedLangs.map(lang => getChallengesForLang(lang));
|
|
||||||
return Promise.all(promises)
|
function generateCurriculum(done) {
|
||||||
.then(allLangCurriculum =>
|
return getChallengesForLang(locale)
|
||||||
allLangCurriculum.reduce(
|
.then(curriculum =>
|
||||||
(map, current, i) => ({ ...map, [supportedLangs[i]]: current }),
|
fs.writeFile(
|
||||||
{}
|
`./build/curriculum-${locale}.json`,
|
||||||
|
JSON.stringify(curriculum)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(curricula =>
|
|
||||||
fs.writeFile('./curricula.json', JSON.stringify(curricula))
|
|
||||||
)
|
|
||||||
.then(done);
|
.then(done);
|
||||||
}
|
}
|
||||||
|
|
||||||
function watchFiles() {
|
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('default', defaultTask);
|
||||||
gulp.task('build', generateCurricula);
|
gulp.task('build', generateCurriculum);
|
||||||
|
@ -16,8 +16,8 @@ function validateLang(lang) {
|
|||||||
|
|
||||||
function getCurriculum(lang) {
|
function getCurriculum(lang) {
|
||||||
validateLang(lang);
|
validateLang(lang);
|
||||||
const curricula = require('./curricula.json');
|
const curriculum = require(`./build/curriculum-${lang}.json`);
|
||||||
return curricula[lang];
|
return curriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getChallengesForLang = getCurriculum;
|
exports.getChallengesForLang = getCurriculum;
|
||||||
|
8387
curriculum/package-lock.json
generated
8387
curriculum/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -26,8 +26,12 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@freecodecamp/challenge-md-parser": "^1.0.0",
|
"@freecodecamp/challenge-md-parser": "^1.0.0",
|
||||||
"invariant": "^2.2.4",
|
"invariant": "^2.2.4"
|
||||||
"readdirp-walk": "^1.6.0",
|
},
|
||||||
|
"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/changelog": "^2.0.2",
|
||||||
"@semantic-release/git": "^5.0.0",
|
"@semantic-release/git": "^5.0.0",
|
||||||
"babel-cli": "^6.3.17",
|
"babel-cli": "^6.3.17",
|
||||||
@ -56,6 +60,7 @@
|
|||||||
"lodash": "^4.17.10",
|
"lodash": "^4.17.10",
|
||||||
"prettier": "^1.13.5",
|
"prettier": "^1.13.5",
|
||||||
"prettier-package-json": "^1.6.0",
|
"prettier-package-json": "^1.6.0",
|
||||||
|
"readdirp-walk": "^1.6.0",
|
||||||
"rx": "^4.1.0",
|
"rx": "^4.1.0",
|
||||||
"semantic-release": "^15.6.0",
|
"semantic-release": "^15.6.0",
|
||||||
"tap-spec": "^5.0.0",
|
"tap-spec": "^5.0.0",
|
||||||
|
@ -6,5 +6,5 @@ exports.dasherize = function dasherize(name) {
|
|||||||
.replace(/\:/g, '');
|
.replace(/\:/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const supportedLangs = ['english'];
|
const supportedLangs = ['english', 'spanish'];
|
||||||
exports.supportedLangs = supportedLangs;
|
exports.supportedLangs = supportedLangs;
|
||||||
|
Reference in New Issue
Block a user