forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
50 lines (41 loc) · 1.14 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 { testedLang } = 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(globLang(testedLang()), { read: false }).pipe(
through2.obj(function obj(file, enc, next) {
lintMarkdown(file, next);
})
);
}
const defaultTask = gulp.series(generateCurriculum, watchFiles);
/**
* Helper functions
**/
function globLang(lang) {
return `./challenges/${lang}/**/*.md`;
}
gulp.task('default', defaultTask);
gulp.task('build', generateCurriculum);
gulp.task('lint', lint);