-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgulpfile.js
81 lines (69 loc) · 2.24 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
/* jshint node:true */
var isparta = require('isparta');
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
// Remove the built files
gulp.task('clean', function(callback) {
var del = require('del');
del(['dist'], callback);
});
// Send a notification when JSHint fails,
// so that you know your changes didn't build
function ding(file) {
return file.jshint.success ? false : 'JSHint failed';
};
// Lint our source code
gulp.task('lint:src', function() {
return gulp.src(['src/**/*.js', '!src/wrapper.js'])
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify(ding))
.pipe($.jshint.reporter('fail'));
});
// Lint our test code
gulp.task('lint:test', function() {
return gulp.src(['test/unit/**/*.js'])
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify(ding))
.pipe($.jshint.reporter('fail'));
});
// Compile library to ECMAScript 5
gulp.task('build', ['lint:src', 'clean'], function() {
return gulp.src('src/**/*.js')
.pipe($.babel({blacklist: ['useStrict'], modules: 'common'}))
.pipe(gulp.dest('dist'))
});
// Create a coverage report
gulp.task('coverage', function(done) {
require('babel/register')({ modules: 'common' });
gulp.src(['src/**/*.js'])
.pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
.on('finish', function() {
return test()
.pipe($.istanbul.writeReports())
.on('end', done);
});
});
// Lint and run our tests
gulp.task('test', ['lint:src', 'lint:test'], function() {
require('babel/register')({modules: 'common'});
return test();
});
// Lint and run our tests. It creates a xunit report also
gulp.task('test:ci', ['lint:src', 'lint:test'], function() {
require('babel/register')({modules: 'common'});
return test('xunit-file');
});
function test(reporterName) {
reporterName = !reporterName ? 'spec' : reporterName;
return gulp.src(['test/setup.js', 'test/unit/**/*.js'], {read: false})
.pipe($.mocha({reporter: reporterName, growl: true}));
};
// Watch files for changes & reload
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['lint:src', 'test']);
gulp.watch('test/**/*.js', ['lint:test', 'test']);
});
// An alias of test
gulp.task('default', ['test', 'watch']);