forked from karma-runner/karma-closure
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (31 loc) · 903 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
var chokidar = require('chokidar');
var fs = require('q-io/fs');
// inputs
var WATCH = ['test-app/js', 'test-app/test'];
var INCLUDE = ['test-app/test/main.js'];
var DependencyResolver = require('./lib/resolver');
var resolver = new DependencyResolver();
var pendingTimer = null;
var scheduleResolving = function() {
if (pendingTimer) {
return;
}
pendingTimer = setTimeout(function() {
pendingTimer = null;
console.log('RESOLVED FILES');
console.log(resolver.resolveFiles(INCLUDE));
}, 500);
};
// kick off watching
var watcher = chokidar.watch(WATCH, {persistent: true});
['change', 'add'].forEach(function(eventName) {
watcher.on(eventName, function(path) {
console.log(eventName, path);
fs.read(path).then(function(content) {
resolver.updateFile(path, content);
scheduleResolving();
});
}, function(e) {
console.error(e.stack);
});
});