-
Notifications
You must be signed in to change notification settings - Fork 25
/
gulpfile.js
81 lines (65 loc) · 2.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
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
/**
* Created by michbil on 23.11.15.
*/
var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var mocha = require('gulp-mocha');
var eslint = require('gulp-eslint');
function restart_nodemon () {
if (nodemon_instance) {
console.log("Restarting nodemon");
nodemon_instance.emit('restart');
} else {
console.log("Nodemon isntance not ready yet")
}
}
gulp.task('test', function() {
return gulp.src('test/**/*.js', {read: false})
// gulp-mocha needs filepaths so you can't have any plugins before it
.pipe(mocha({
reporter: 'dot',
timeout: 20000
}))
.once('error', function (err) {
console.log("Tests failed",err);
process.exit(1);
})
.once('end', function () {
process.exit();
});
});
gulp.task('lint', function () {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src(['./src/**/*.js*'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
var nodemon_instance;
gulp.task('nodemon', function() {
if (!nodemon_instance) {
nodemon_instance = nodemon({
script: 'server.js',
watch: 'src/__manual_watch__',
ext: '__manual_watch__',
verbose: false
}).on('restart', function() {
console.log('~~~ restart server ~~~');
});
} else {
nodemon_instance.emit('restart');
}
});
gulp.task('default', ['lint']);
gulp.task('watch', ['default', 'nodemon'], function() {
gulp.watch(['./src/**/*.js'], restart_nodemon);
});