-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (34 loc) · 941 Bytes
/
index.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
'use strict'
const arrify = require("arrify")
const types = {
add: "added",
change: "changed",
unlink: "removed"
}
module.exports = function (fly) {
fly.plugin('watch', {every: 0, files: 0}, function * (_, globs, tasks, opts) {
globs = arrify(globs)
tasks = arrify(tasks)
opts = opts || {}
// announce start
this.emit("fly_watch")
return require("chokidar")
.watch(globs, {ignoreInitial: 1})
.on("error", this.$.error)
.on("all", (event, filepath) => {
// store previous globs (`prevs`)
// used within `target` for `trims`
this._.prevs = globs
// also update ALL chained `tasks` for their own `target`
tasks.forEach(k => {
fly.tasks[k].data.prevs = globs
})
// broadcast
this.emit("fly_watch_event", {action: types[event], file: filepath})
// pass single file to task params
opts.src = filepath
// re-run task chain
return this.serial(tasks, opts)
})
})
}