forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
50 lines (41 loc) · 1.16 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require('fs-extra');
const gulp = require('gulp');
const through2 = require('through2');
const { locale } = require('../config/env.json');
const { getChallengesForLang } = require('./getChallenges');
const { testedLangs } = require('./utils');
const lintMarkdown = require('../tools/scripts/lint');
/**
* Tasks
**/
function generateCurriculum(done) {
return getChallengesForLang(locale)
.then(curriculum => {
fs.ensureFileSync(`./build/curriculum-${locale}.json`);
fs.writeFile(
`./build/curriculum-${locale}.json`,
JSON.stringify(curriculum)
);
})
.then(done);
}
function watchFiles() {
return gulp.watch('./challenges/**/*.md', generateCurriculum);
}
function lint() {
return gulp.src(globLangs(testedLangs()), { read: false }).pipe(
through2.obj(function obj(file, enc, next) {
lintMarkdown(file, next);
})
);
}
const defaultTask = gulp.series(generateCurriculum, watchFiles);
/**
* Helper functions
**/
function globLangs(langs) {
return langs.map(lang => `./challenges/${lang}/**/*.md`);
}
gulp.task('default', defaultTask);
gulp.task('build', generateCurriculum);
gulp.task('lint', lint);