forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsc-to-mocha-watch.js
More file actions
57 lines (53 loc) · 1.6 KB
/
tsc-to-mocha-watch.js
File metadata and controls
57 lines (53 loc) · 1.6 KB
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
// Run "tsc" with watch, upon successful compilation run mocha tests.
var child_process = require("child_process");
var spawn = child_process.spawn;
var readline = require("readline");
var chalk = require("chalk");
var mocha = null;
var mochal = null;
var errors = 0;
function compilationStarted() {
if (mocha) {
mocha.kill('SIGINT');
}
mocha = null;
mochal = null;
errors = 0;
}
function foundErrors() {
errors ++;
}
function compilationComplete() {
if (errors) {
console.log(" " + chalk.red("TS errors. Will not start mocha."));
return;
} else {
console.log(" " + chalk.gray("Run mocha."));
}
mocha = spawn("./node_modules/.bin/mocha", ["--colors"]);
mocha.on('close', code => {
if (code) {
console.log(chalk.gray("mocha: ") + "Exited with " + code);
} else {
console.log(chalk.gray("mocha: ") + chalk.red("Exited with " + code));
}
mocha = null;
mochal = null;
});
mochal = readline.createInterface({ input: mocha.stdout });
mochal.on('line', line => {
console.log(chalk.gray('mocha: ') + line);
});
}
var tsc = spawn("./node_modules/.bin/tsc", ["--watch"]);
var tscl = readline.createInterface({ input: tsc.stdout });
tscl.on('line', line => {
console.log(chalk.gray(" tsc: ") + line);
if (line.indexOf("Compilation complete.") >= 0) {
compilationComplete();
} else if (line.indexOf("File change detected.") >= 0) {
compilationStarted();
} else if (line.indexOf(": error TS") >= 0) {
foundErrors();
}
});