feat(next): BREAKING New curriculum package

This commit is contained in:
Bouncey
2018-10-04 17:36:00 +01:00
committed by Stuart Taylor
parent 6ba31ae5d1
commit 3151390be4
9 changed files with 2213 additions and 3506 deletions

33
curriculum/lib.js Normal file
View File

@ -0,0 +1,33 @@
const invariant = require('invariant');
const { getChallengesForLang } = require('./getChallenges');
const { supportedLangs } = require('./utils');
const promises = supportedLangs.map(lang => getChallengesForLang(lang));
const curricula = Promise.all(promises).then(allLangCurriculum =>
allLangCurriculum.reduce(
(map, current, i) => ({ ...map, [supportedLangs[i]]: current }),
{}
)
);
function validateLang(lang) {
invariant(lang, 'Please provide a language');
invariant(
supportedLangs.includes(lang),
`${lang} is not supported
Supported languages: ${JSON.stringify(supportedLangs, null, 2)}
`
);
}
async function getCurriculum(lang) {
validateLang(lang);
const allCurriculum = await curricula;
const requested = allCurriculum[lang];
return requested;
}
exports.getChallengesForLang = getCurriculum;