-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
55 lines (46 loc) · 1.68 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
51
52
53
54
55
const gulp = require('gulp');
const fs = require('fs');
const del = require('del');
const $ = require('gulp-load-plugins')();
// Utility to ignore unnecessary files
// when generating the glob patterns array for gulp.src()
function addDefSrcIgnore (srcArr) {
return srcArr.concat([
'!node_modules{,/**}',
'!private{,/**}',
'!dist{,/**}',
'!.git{,/**}',
'!**/.DS_Store'
]);
}
// JavaScript and JSON linter
gulp.task('lint', function () {
return gulp.src(addDefSrcIgnore(['**/*.js', '*.json']), {dot: true})
.pipe($.eslint({dotfiles: true}))
.pipe($.eslint.format())
.pipe($.eslint.failAfterError());
});
// Remove solutions from exercises
gulp.task('remove-solutions', ['lint'], function () {
del.sync('dist');
return gulp.src(addDefSrcIgnore(['**']), {dot: true})
.pipe($.replace(/^\s*(\/\/|<!--|\/\*)\s*REMOVE-START[\s\S]*?REMOVE-END\s*(\*\/|-->)?\s*$/gm, ''))
.pipe(gulp.dest('dist'));
});
// Prepare for distribution to students
gulp.task('dist', ['remove-solutions'], function () {
function removeMaster (str) {
var strArr = str.split('-');
strArr[strArr.length - 1] === 'master' && strArr.pop();
return strArr.join('-');
}
const npmConfig = require('./package.json');
npmConfig.name = removeMaster(npmConfig.name);
npmConfig.repository.url = removeMaster(npmConfig.repository.url);
npmConfig.scripts['precommit'] = 'gulp lint';
fs.writeFileSync('dist/package.json', JSON.stringify(npmConfig, null, 2));
const esLintConfig = require('./.eslintrc.json');
esLintConfig.rules['no-undef'] = 'off';
esLintConfig.rules['no-unused-vars'] = 'off';
fs.writeFileSync('dist/.eslintrc.json', JSON.stringify(esLintConfig, null, 2));
});