-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
98 lines (82 loc) · 2.65 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
91
92
93
94
95
96
97
98
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
const path = require('path');
const mkdirp = require('mkdirp');
const isparta = require('isparta');
const manifest = require('./package.json');
const config = manifest.nodeBoilerplateOptions;
const mainFile = manifest.main;
const destinationFolder = path.dirname(mainFile);
// Remove the built files
gulp.task('clean', function(cb) {
del([destinationFolder], cb);
});
// Send a notification when JSHint fails,
// so that you know your changes didn't build
function jshintNotify(file) {
if (!file.jshint) { return; }
return file.jshint.success ? false : 'JSHint failed';
}
function jscsNotify(file) {
if (!file.jscs) { return; }
return file.jscs.success ? false : 'JSCS failed';
}
function createLintTask(taskName, files) {
gulp.task(taskName, function() {
return gulp.src(files)
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify(jshintNotify))
.pipe($.jscs())
.pipe($.notify(jscsNotify))
// .pipe($.jshint.reporter('fail'));
});
}
// Lint our source code
createLintTask('lint-src', ['src/**/*.js'])
// Lint our test code
createLintTask('lint-test', ['test/**/*.js'])
// Build two versions of the library
gulp.task('build', ['lint-src', 'clean'], function() {
// Create our output directory
mkdirp.sync(destinationFolder);
return gulp.src('src/**/*.js')
.pipe($.plumber())
.pipe($.babel({ blacklist: ['useStrict'] }))
.pipe(gulp.dest(destinationFolder));
});
function test(type) {
return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
.pipe($.plumber())
.pipe($.mocha({reporter: 'dot', globals: config.mochaGlobals}));
}
// Make babel preprocess the scripts the user tries to import from here on.
require('babel/register');
gulp.task('coverage', function(done) {
gulp.src(['src/*.js'])
.pipe($.plumber())
.pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
.pipe($.istanbul.hookRequire())
.on('finish', function() {
return test()
.pipe($.istanbul.writeReports())
.on('end', done);
});
});
gulp.task('babel', function () {
return gulp.src('src/**/*.js')
.pipe($.plumber())
.pipe($.babel())
.pipe(gulp.dest(destinationFolder));
});
// Lint and run our tests
// gulp.task('test', ['lint-src', 'lint-test'], test);
gulp.task('test', test);
// Run the headless unit tests as you make changes.
gulp.task('watch', ['debug'], function() {
gulp.watch(['src/**/*', 'test/**/*', 'package.json', '**/.jshintrc', '.jscsrc'], ['nodemon']);
});
// An alias of test
gulp.task('default', ['test']);