1 | var trackDir = require('./track-dir')
|
2 | var utils = require('./utils')
|
3 | var path = require('path')
|
4 |
|
5 | var dirs = [
|
6 | 'assets',
|
7 | 'content',
|
8 | 'public'
|
9 | ]
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | module.exports = node
|
23 |
|
24 | function node (state, createEdge) {
|
25 | var basedir = utils.dirname(state.metadata.entry)
|
26 | var self = this
|
27 |
|
28 | if (state.tracker) return
|
29 | var tracker = state.tracker = trackDir()
|
30 |
|
31 | tracker.start(basedir, dirs, { watch: state.metadata.watch })
|
32 | state.metadata.assets = tracker.files
|
33 |
|
34 | tracker.on('error', function (err) {
|
35 | self.emit('error', 'assets', 'tracker', err)
|
36 | })
|
37 |
|
38 | tracker.on('change', function () {
|
39 | var list = tracker.list().map(function (file) {
|
40 | return path.posix.format(path.parse(path.relative(basedir, file)))
|
41 | })
|
42 | createEdge('list', Buffer.from(list.join(',')))
|
43 | })
|
44 |
|
45 | tracker.on('progress', function (progress) {
|
46 |
|
47 | })
|
48 |
|
49 | this.on('close', function () {
|
50 | tracker.unwatch()
|
51 | })
|
52 | }
|