-
Notifications
You must be signed in to change notification settings - Fork 55
/
watch.js
42 lines (37 loc) · 1.05 KB
/
watch.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
var utils = require('./_utils'),
eslint = require('./eslint'),
build = require('./build'),
chokidar = require('chokidar')
module.exports = function(options) {
options = utils.extend({
// chokidar events we are going to watch
// generally you should not touch them
watchEvents: [
'change',
'add',
'unlink',
'unlinkDir',
'addDir'
]
}, options)
// return a promise based on a certain task triggered
var runOnlyOn = function(event) {
if (~options.watchEvents.indexOf(event)) {
// go to the next task
return Promise.resolve()
} else {
return Promise.reject()
}
}
// run eslint when a source file gets updated
utils.print('Watching the files in the src/**/**/*.js path', 'cool')
chokidar.watch('src/**/**/*.js', {
ignoreInitial: true
}).on('all', function(event) {
// this tasks will run only if the current event matches the ones in the watchEvents array
runOnlyOn(event)
.then(eslint)
.then(build)
.catch(e => utils.print(e, 'error'))
})
}