forked from gilamran/tsc-watch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsc-watch-client-example.js
43 lines (36 loc) · 965 Bytes
/
tsc-watch-client-example.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
const readline = require('readline');
const TscWatchClient = require('./client');
const client = new TscWatchClient();
client.on('started', () => {
console.log('Compilation started');
});
client.on('first_success', () => {
console.log('Interactive mode');
console.log(' Press "r" to re-run the onSuccess command, esc to exit.\n');
});
client.on('success', () => {
console.log('Yey success!');
});
client.on('compile_errors', () => {
console.log('Ho no!');
});
client.start(
'--onSuccess',
'node ./example/main.js',
'--noClear',
'--project',
'./example/tsconfig.json',
);
readline.emitKeypressEvents(process.stdin);
process.stdin.on('keypress', (str, key) => {
if (key.name == 'escape' || (key && key.ctrl && key.name == 'c')) {
client.kill();
process.stdin.pause();
} else {
if (str && str.toLowerCase() === 'r') {
client.runOnSuccessCommand();
}
}
});
process.stdin.setRawMode(true);
process.stdin.resume();