-
Notifications
You must be signed in to change notification settings - Fork 36
/
watcher.js
executable file
·49 lines (37 loc) · 1021 Bytes
/
watcher.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
#!/usr/bin/env node
// 2015.03.04
'use strict';
const fs = require('fs');
const spawn = require('child_process').spawn;
const clearScreen = '[H[2J';
let files = new Set();
let tid;
const run = function() {
process.stdout.write( clearScreen );
console.log('Changed files: ', files);
let runner = spawn( 'make', [ 'test' ] );
runner.stdout.on('data', function( data ) {
process.stdout.write( data );
});
runner.stderr.on('data', function( data ) {
process.stdout.write( data );
});
runner.on('close', function(code) {
tid = null;
files.clear();
});
};
const changeHandler = function(event, filename) {
if ( filename.endsWith('.js') ) {
files.add( filename );
if (!tid) {
tid = setTimeout(function() {
run();
}, 250);
}
}
};
// run();
fs.watch( './lib', { recursive:true }, changeHandler );
fs.watch( './test', { recursive:true }, changeHandler );