2018-10-05 12:20:51 +01:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const gulp = require('gulp');
|
2019-04-12 16:44:14 +02:00
|
|
|
const through2 = require('through2');
|
|
|
|
const markdownlint = require('markdownlint');
|
2018-10-05 12:20:51 +01:00
|
|
|
|
2019-02-18 19:32:49 +00:00
|
|
|
const { locale } = require('../config/env.json');
|
|
|
|
const { getChallengesForLang } = require('./getChallenges');
|
2019-04-12 16:44:14 +02:00
|
|
|
const { testedLangs } = require('./utils');
|
|
|
|
const lintYAML = require('./tools/markdown-yaml');
|
|
|
|
const lintConfig = require('./tools/.markdownlintrc.js');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tasks
|
|
|
|
**/
|
2018-10-05 12:20:51 +01:00
|
|
|
|
2018-10-09 20:26:37 +01:00
|
|
|
function generateCurriculum(done) {
|
|
|
|
return getChallengesForLang(locale)
|
2018-10-10 16:20:40 -04:00
|
|
|
.then(curriculum => {
|
|
|
|
fs.ensureFileSync(`./build/curriculum-${locale}.json`);
|
2018-10-09 20:26:37 +01:00
|
|
|
fs.writeFile(
|
|
|
|
`./build/curriculum-${locale}.json`,
|
|
|
|
JSON.stringify(curriculum)
|
2019-02-16 08:37:36 +00:00
|
|
|
);
|
2018-10-10 16:20:40 -04:00
|
|
|
})
|
2018-10-05 12:20:51 +01:00
|
|
|
.then(done);
|
|
|
|
}
|
|
|
|
|
|
|
|
function watchFiles() {
|
2018-10-09 20:26:37 +01:00
|
|
|
return gulp.watch('./challenges/**/*.md', generateCurriculum);
|
2018-10-05 12:20:51 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 16:44:14 +02:00
|
|
|
function lint() {
|
|
|
|
return gulp.src(globLangs(testedLangs()), { read: false }).pipe(
|
|
|
|
through2.obj(function obj(file, enc, next) {
|
|
|
|
const options = {
|
|
|
|
files: [file.path],
|
|
|
|
config: lintConfig,
|
|
|
|
customRules: [lintYAML]
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, result) {
|
|
|
|
const resultString = (result || '').toString();
|
|
|
|
if (resultString) {
|
|
|
|
process.exitCode = 1;
|
|
|
|
console.log(resultString);
|
|
|
|
}
|
|
|
|
next(err, file);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-09 20:26:37 +01:00
|
|
|
const defaultTask = gulp.series(generateCurriculum, watchFiles);
|
2018-10-05 12:20:51 +01:00
|
|
|
|
2019-04-12 16:44:14 +02:00
|
|
|
/**
|
|
|
|
* Helper functions
|
|
|
|
**/
|
|
|
|
|
|
|
|
function globLangs(langs) {
|
|
|
|
return langs.map(lang => `./challenges/${lang}/**/*.md`);
|
|
|
|
}
|
|
|
|
|
2018-10-05 12:20:51 +01:00
|
|
|
gulp.task('default', defaultTask);
|
2018-10-09 20:26:37 +01:00
|
|
|
gulp.task('build', generateCurriculum);
|
2019-04-12 16:44:14 +02:00
|
|
|
gulp.task('lint', lint);
|