mirror of
https://github.com/Teamlinker/Teamlinker.git
synced 2025-06-03 03:00:17 +00:00
23 lines
681 B
TypeScript
23 lines
681 B
TypeScript
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'));
|
|
}
|
|
}
|