-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.ts
43 lines (36 loc) · 968 Bytes
/
bin.ts
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
#!/usr/bin/env node
import ts from 'typescript';
import { compile, getWriteDiagnostics } from './compile';
import { DiagnosticsError } from './tools/diagnostics-error';
import { workarounds } from './workarounds';
const compileFromCommandLine = async () => {
const args = ts.sys.args;
try {
const parsedCommandLine = workarounds.parsePatchedCommandLine(
args,
ts.sys.readFile
);
const logger = parsedCommandLine.options.verbose
? console.log
: () => void 0;
return await compile({
parsedCommandLine,
logger,
});
} catch (error) {
if (error instanceof DiagnosticsError) {
return {
hasErrors: true,
diagnostics: error.diagnostics,
writeDiagnostics: getWriteDiagnostics(error.diagnostics),
};
}
throw error;
}
};
compileFromCommandLine().then(({ hasErrors, writeDiagnostics }) => {
writeDiagnostics();
if (hasErrors) {
process.exit(1);
}
});