-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevelop.js
More file actions
56 lines (46 loc) · 1.43 KB
/
develop.js
File metadata and controls
56 lines (46 loc) · 1.43 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
const { spawn } = require("child_process");
const path = require("path");
const ts = require("typescript");
function main() {
const tsConfigPath = path.resolve("tsconfig.json");
const host = ts.createWatchCompilerHost(
tsConfigPath,
{},
ts.sys,
ts.createEmitAndSemanticDiagnosticsBuilderProgram,
handleDiagnostic,
handleDiagnostic,
);
ts.createWatchProgram(host);
}
const BEGIN_CODES = [6031, 6032];
const END_CODES = [6193, 6194];
let errors;
function handleDiagnostic(diagnostic) {
if (BEGIN_CODES.includes(diagnostic.code)) {
process.stdout.write("\n-----------------------------------------------------------------\n\n");
errors = [];
} else if (END_CODES.includes(diagnostic.code)) {
if (errors.length === 0) {
process.stdout.write("TypeScript: OK\n");
const npm = spawn("npm", ["run", "test"], { stdio: "inherit" });
npm.on("close", code => {
console.log(`jest exited with code ${code}`);
});
npm.on("error", err => {
console.log(`Tests failed: ${err}`);
});
} else {
process.stdout.write("\nTypeScript: failed\n");
}
} else {
const formatDiagnosticHost = {
getCanonicalFileName: path => path,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine,
};
process.stdout.write(ts.formatDiagnostic(diagnostic, formatDiagnosticHost));
errors.push(diagnostic);
}
}
main();