forked from nullcc/ts-interface-keys-transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.ts
More file actions
22 lines (18 loc) · 681 Bytes
/
compile.ts
File metadata and controls
22 lines (18 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import * as ts from 'typescript';
import transformer from './transformer';
export default function compile(filePaths: string[], writeFileCallback?: ts.WriteFileCallback) {
const program = ts.createProgram(filePaths, {
strict: true,
noEmitOnError: true,
suppressImplicitAnyIndexErrors: true,
target: ts.ScriptTarget.ES5,
});
const transformers: ts.CustomTransformers = {
before: [transformer(program)],
after: [],
};
const { emitSkipped, diagnostics } = program.emit(undefined, writeFileCallback, undefined, false, transformers);
if (emitSkipped) {
throw new Error(diagnostics.map(diagnostic => diagnostic.messageText).join('\n'));
}
}