-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
52 lines (43 loc) · 1.2 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
/*eslint strict: [2, "global"]*/
'use strict';
var fs = require('fs');
var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var eslint = require('gulp-eslint');
var through = require('through2');
var MAIN_FILES = './*.js';
// provides pipe to log stuff to console when certain task finishes
function logPipe(str) {
return through.obj(function (file, enc, cb) {
cb();
}, function (cb) {
gutil.log(str);
cb();
});
}
// helper for linting files
function doEslint(globs, singleFile) {
if (singleFile) {
gutil.log(gutil.colors.magenta('Start ESLint ' + globs[0]));
}
var task = gulp.src(globs)
.pipe(eslint())
.pipe(eslint.format());
return singleFile ?
task.pipe(logPipe(gutil.colors.magenta('Finish ESLint ' + globs[0]))) :
task.pipe(eslint.failAfterError());
}
gulp.task('eslint', function () {
return doEslint([MAIN_FILES], false);
});
gulp.task('watch', function () {
gulp.watch([MAIN_FILES]).on('change', function (event) {
var filePath = path.relative(__dirname, event.path);
if (fs.statSync(filePath).isFile()) {
doEslint([filePath], true);
}
});
});
gulp.task('test', ['eslint']);
gulp.task('default', ['test']);