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

View File

@ -904,6 +904,14 @@
"prop-types": "^15.5.7" "prop-types": "^15.5.7"
} }
}, },
"@freecodecamp/curriculum": {
"version": "0.0.0-next.1",
"resolved": "https://registry.npmjs.org/@freecodecamp/curriculum/-/curriculum-0.0.0-next.1.tgz",
"integrity": "sha512-DGJTEguAS67h8Nb9etpjJNvp1Ceh6flTVWXMavlnpnaiTqGpb7Yb+vn22nM94JFAuwHLGxUIVj0mpuL2WF2Vdw==",
"requires": {
"invariant": "^2.2.4"
}
},
"@freecodecamp/gatsby-source-filesystem": { "@freecodecamp/gatsby-source-filesystem": {
"version": "2.0.1-beta.3", "version": "2.0.1-beta.3",
"resolved": "https://registry.npmjs.org/@freecodecamp/gatsby-source-filesystem/-/gatsby-source-filesystem-2.0.1-beta.3.tgz", "resolved": "https://registry.npmjs.org/@freecodecamp/gatsby-source-filesystem/-/gatsby-source-filesystem-2.0.1-beta.3.tgz",

View File

@ -13,7 +13,7 @@
"@fortawesome/free-regular-svg-icons": "^5.2.0", "@fortawesome/free-regular-svg-icons": "^5.2.0",
"@fortawesome/free-solid-svg-icons": "^5.2.0", "@fortawesome/free-solid-svg-icons": "^5.2.0",
"@fortawesome/react-fontawesome": "0.0.20", "@fortawesome/react-fontawesome": "0.0.20",
"@freecodecamp/curriculum": "^3.2.1", "@freecodecamp/curriculum": "0.0.0-next.1",
"@freecodecamp/gatsby-source-filesystem": "^2.0.1-beta.3", "@freecodecamp/gatsby-source-filesystem": "^2.0.1-beta.3",
"@freecodecamp/react-bootstrap": "^0.32.3", "@freecodecamp/react-bootstrap": "^0.32.3",
"@reach/router": "^1.1.1", "@reach/router": "^1.1.1",

View File

@ -1,3 +1,4 @@
* *
!dist/*.js !lib.js
!dist/challenges/**/*.json !utils.js
!getChallenges.js

View File

@ -1,26 +1,10 @@
const path = require('path'); const path = require('path');
const { findIndex } = require('lodash'); const { findIndex } = require('lodash');
const invariant = require('invariant');
const readDirP = require('readdirp-walk'); const readDirP = require('readdirp-walk');
const { parseMarkdown } = require('../tools/challenge-md-parser'); const { parseMarkdown } = require('../tools/challenge-md-parser');
const supportedLangs = ['english'];
function validateLang(lang) {
invariant(lang, 'Please provide a language');
invariant(
supportedLangs.includes(lang),
`${lang} is not supported
Supported languages: ${JSON.stringify(supportedLangs, null, 2)}
`
);
}
exports.getChallengesForLang = function getChallengesForLang(lang) { exports.getChallengesForLang = function getChallengesForLang(lang) {
validateLang(lang);
let curriculum = {}; let curriculum = {};
return new Promise(resolve => return new Promise(resolve =>
readDirP({ root: path.resolve(__dirname, `./challenges/${lang}`) }) readDirP({ root: path.resolve(__dirname, `./challenges/${lang}`) })
@ -87,4 +71,3 @@ function getBlockNameFromPath(filePath) {
const [, block] = filePath.split('/'); const [, block] = filePath.split('/');
return block; return block;
} }

View File

@ -1,20 +0,0 @@
const gulp = require('gulp');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
gulp.task('babel-getChallenges', () =>
gulp.src('./getChallenges.js')
.pipe(babel({
presets: ['env']
}))
.pipe(gulp.dest('dist'))
);
gulp.task('babel', ['babel-getChallenges'], () =>
gulp.src('./package-entry.js')
.pipe(rename('./index.js'))
.pipe(babel({
presets: ['env']
}))
.pipe(gulp.dest('dist/'))
);

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;

File diff suppressed because it is too large Load Diff

View File

@ -3,24 +3,22 @@
"description": "freeCodeCamp's curriculum seed files", "description": "freeCodeCamp's curriculum seed files",
"license": "(BSD-3-Clause AND CC-BY-SA-4.0)", "license": "(BSD-3-Clause AND CC-BY-SA-4.0)",
"author": "freeCodeCamp <team@freecodecamp.org>", "author": "freeCodeCamp <team@freecodecamp.org>",
"homepage": "https://github.com/freeCodeCamp/curriculum#readme", "homepage": "https://github.com/freeCodeCamp/freeCodeCamp#readme",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/freeCodeCamp/curriculum.git" "url": "https://github.com/freeCodeCamp/freeCodeCamp.git"
}, },
"bugs": { "bugs": {
"url": "https://github.com/freeCodeCamp/curriculum/issues" "url": "https://github.com/freeCodeCamp/freeCodeCamp/issues"
}, },
"version": "3.2.1", "version": "0.0.0-next.1",
"main": "getChallenges.js", "main": "lib.js",
"scripts": { "scripts": {
"build": "gulp babel",
"precommit": "lint-staged", "precommit": "lint-staged",
"commit": "git-cz", "commit": "git-cz",
"commitmsg": "commitlint -e", "commitmsg": "commitlint -e",
"format": "prettier --write es5 './**/*.{js,json}' && npm run lint", "format": "prettier --write es5 './**/*.{js,json}' && npm run lint",
"lint": "eslint ./**/*.js --fix", "lint": "eslint ./**/*.js --fix",
"prepack": "npm run build",
"repack": "babel-node ./repack.js", "repack": "babel-node ./repack.js",
"semantic-release": "semantic-release", "semantic-release": "semantic-release",
"test": "babel-node ./test-challenges.js | tap-spec", "test": "babel-node ./test-challenges.js | tap-spec",
@ -62,9 +60,6 @@
"eslint-plugin-prefer-object-spread": "^1.2.1", "eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-react": "^7.7.0", "eslint-plugin-react": "^7.7.0",
"fs-extra": "^6.0.1", "fs-extra": "^6.0.1",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.1",
"gulp-rename": "^1.3.0",
"husky": "^0.14.3", "husky": "^0.14.3",
"joi": "^13.3.0", "joi": "^13.3.0",
"joi-objectid": "^2.0.0", "joi-objectid": "^2.0.0",

View File

@ -4,4 +4,7 @@ exports.dasherize = function dasherize(name) {
.replace(/\s/g, '-') .replace(/\s/g, '-')
.replace(/[^a-z0-9\-\.]/gi, '') .replace(/[^a-z0-9\-\.]/gi, '')
.replace(/\:/g, ''); .replace(/\:/g, '');
} };
const supportedLangs = ['english'];
exports.supportedLangs = supportedLangs;