-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
92 lines (79 loc) · 2.12 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
/* Workaround for `possible EventEmitter memory leak detected. 11 listeners added`` */
process.stdout.setMaxListeners(Infinity)
/* Dependencies */
var gulp = require('gulp')
var jshint = require('gulp-jshint')
var mocha = require('gulp-mocha')
var to5 = require('gulp-babel')
var plumber = require('gulp-plumber')
var runSequence = require('run-sequence')
var del = require('del')
/* Directories to watch */
var sourceDir = 'src/**/*.js'
var testDir = 'test/scripts/**/*.js'
var distDir = 'dist'
/* if watching, do not exit the application if a test failed */
var watching = false
/* remove everything inside dist/ directory */
gulp.task('clean', function(callback) {
del([
distDir+'/**'
], callback)
})
/* Compile ES6 to ES5 */
gulp.task('babel', function() {
return gulp
.src([sourceDir])
.pipe(plumber())
.pipe(to5())
.pipe(gulp.dest(distDir))
})
/* Mocha Unit Tests */
gulp.task('mocha', function(){
var reporter = 'spec'
if (watching) {
reporter = 'nyan'
}
return gulp
.src('test/index.js')
.pipe(mocha({
reporter : reporter,
ignoreLeaks : true,
asyncOnly : true,
timeout : 5000,
debug : true
}).on('error', function(err) {
console.log(err.toString())
if (watching) {
this.emit('end') // will not close the watcher
} else {
process.exit(1) // return an error code. useful for CI
}
}))
})
/* JSHint */
gulp.task('jshint', function(){
return gulp
.src(sourceDir)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('default'))
})
/* Execute in order */
gulp.task('compile-then-test', function(callback) {
runSequence(
'clean',
'babel',
'jshint',
'mocha',
callback
)
})
/* Watch for file changes, then perform the tests */
gulp.task('watch', function(){
watching = true
gulp.watch(sourceDir, ['compile-then-test']) // on every change, run tasks in order
gulp.watch(['test/index.js', testDir], ['compile-then-test'])
})
gulp.task('test', ['compile-then-test'])
gulp.task('default', ['babel', 'watch'])