forked from darrylwest/go-unique
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher.js
executable file
·63 lines (48 loc) · 1.43 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
// dpw@alameda.local
// 2015.03.04
'use strict';
const fs = require('fs');
const spawn = require('child_process').spawn;
const clearScreen = '[H[2J';
let files = [];
let tid;
let lastRun;
const run = function() {
process.stdout.write( clearScreen );
try {
var cmd = 'make';
var runner = spawn( cmd, [ '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) {
if (code !== 0) {
console.log( cmd, ' did not exit correctly, code: ', code);
}
console.log( '------------------------------------ last run: ', new Date().toISOString() );
tid = null;
files.splice( 0 );
});
} catch (err) {
console.log( err );
}
};
const changeHandler = function(event, filename) {
if (filename.endsWith( '.go') > 0) {
console.log( 'file change: ', filename);
files.push( filename );
if (!tid) {
tid = setTimeout(function() {
run();
}, 500);
}
}
};
fs.watch( './src/', { recursive:true}, changeHandler );
fs.watch( './test/', { recursive:true}, changeHandler );
process.stdout.write( clearScreen );
console.log('watching go files...');