forked from bevry/watchr
/
watchr.js
62 lines (55 loc) · 2.24 KB
/
watchr.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
/* Require */
var watchr = require('watchr'),
exec = require('child_process').exec;
/* Watch a directory or file */
console.log('--------------------------------------------------------------');
console.log('-------- Watching /less/ directory for changes -------');
console.log('--------------------------------------------------------------');
watchr.watch({
paths: ['../content/bootstrap/less'],
listeners: {
log: function(logLevel){
//console.log('a log message occured:', arguments);
},
error: function(err){
console.log('an error occured:', err);
},
watching: function(err,watcherInstance,isWatching){
if (err) {
// console.log("watching the path " + watcherInstance.path + " failed with error", err);
} else {
// console.log("watching the path " + watcherInstance.path + " completed");
}
},
change: function(changeType,filePath,fileCurrentStat,filePreviousStat){
//console.log('a change event occured:',arguments);
console.log("Modified file: "+ filePath);
var command = "bundler";
exec(command, function (error, stdout, stderr){
console.log(stdout);
if (error !== null) {
console.log('exec error: ' + error);
console.log("stdout : "+stdout)
console.log("stderr : "+stderr)
}
});
}
},
next: function(err,watchers){
if (err) {
// return console.log("watching everything failed with error", err);
} else {
// console.log('watching everything completed', watchers);
}
// Close watchers after 10 Minutes
setTimeout(function(){
var i;
console.log('--------------------------------------------------------------');
console.log('--------------- Stopped watchers, run cmd again --------------');
console.log('--------------------------------------------------------------');
for ( i=0; i<watchers.length; i++ ) {
watchers[i].close();
}
},600000);
}
});