This repository has been archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
/
gulpfile.js
90 lines (79 loc) · 2.27 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
// tasks based on : https://github.com/youngmountain/generator-node-gulp/blob/master/gulpfile.js
var path = require('path');
var gulp = require('gulp');
var nsp = require('gulp-nsp');
var $ = require('gulp-load-plugins')();
// ADD PATHS AUTOMATICALLY
var paths = {
coverage: [ // code actually run by the generator
'generators/*/index.js',
'utils/**/*.js'
],
lint: [ // code to lint
'./gulpfile.js',
'generators/*/index.js',
'generators/*/templates/**/!(_)*.js',
'utils/**/*.js',
],
watch: [ // code that should be watched
'./gulpfile.js',
'generators/**/*',
'utils/**/*'
],
test: [
'./test/**/*.js',
'!./test/temp/**/*.js'
],
extra: [
'generators/app/sources/**/*.js',
]
};
// add extra files
paths.coverage = paths.coverage.concat(paths.extra);
paths.lint = paths.lint.concat(paths.extra);
paths.watch = paths.watch.concat(paths.extra);
// add test files
paths.lint = paths.lint.concat(paths.test);
paths.watch = paths.watch.concat(paths.test);
// when running in CI environment (Travis), abort and throw error on error
var plumberConf = {};
if (process.env.CI) {
plumberConf.errorHandler = function (err) {
throw err;
};
}
gulp.task('nsp', function (cb) {
nsp({package: path.resolve('package.json')}, cb);
});
// will run istanbul & lint while you develop
gulp.task('watch', ['lint', 'istanbul'], function () {
gulp.watch(paths.watch, ['lint', 'istanbul']);
});
// will run coding style checks
gulp.task('lint', ['istanbul'], function () {
return gulp.src(paths.lint)
.pipe($.plumber(plumberConf))
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
});
// will run mocha and print reports
gulp.task('istanbul', function (cb) {
gulp.src(paths.coverage)
.pipe($.istanbul()) // Covering files
.pipe($.istanbul.hookRequire())
.on('finish', function () {
gulp.src(paths.test, {cwd: __dirname})
.pipe($.plumber(plumberConf))
.pipe($.mocha())
.pipe($.istanbul.writeReports()) // Creating the reports after tests ran
.on('finish', function () {
process.chdir(__dirname);
cb();
});
});
});
gulp.task('test', ['lint', 'istanbul']);
gulp.task('prepublish', ['nsp']);
gulp.task('default', ['test']);