-
Notifications
You must be signed in to change notification settings - Fork 2k
/
gulpfile.js
48 lines (40 loc) · 1.19 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
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const shell = require('gulp-shell');
const yaml = require('js-yaml');
gulp.task('lint', () => gulp.src([
'./source/js/**/*.js',
'./scripts/**/*.js'
]).pipe(eslint())
.pipe(eslint.format()));
gulp.task('lint:stylus', shell.task([
'npx stylint ./source/css/'
]));
gulp.task('validate:config', cb => {
const themeConfig = fs.readFileSync(path.join(__dirname, '_config.yml'));
try {
yaml.safeLoad(themeConfig);
return cb();
} catch (error) {
return cb(new Error(error));
}
});
gulp.task('validate:languages', cb => {
const languagesPath = path.join(__dirname, 'languages');
const languages = fs.readdirSync(languagesPath);
const errors = [];
languages.forEach(lang => {
const languagePath = path.join(languagesPath, lang);
try {
yaml.safeLoad(fs.readFileSync(languagePath), {
filename: path.relative(__dirname, languagePath)
});
} catch (error) {
errors.push(error);
}
});
return errors.length === 0 ? cb() : cb(errors);
});
gulp.task('default', gulp.series('lint', 'validate:config', 'validate:languages'));