1 | import Compiler from "./compiler";
|
2 | import DiagnosticsHandler from "./diagnostics-handler";
|
3 | import { toAbsolutePath } from "./fs/path-utils";
|
4 | import { BroccoliPlugin, heimdall } from "./helpers";
|
5 | import { NormalizedOptions, TypescriptCompilerOptions } from "./interfaces";
|
6 | import normalizeOptions from "./normalize-options";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export function typescript(
|
26 | inputNode: any,
|
27 | options?: TypescriptCompilerOptions
|
28 | ) {
|
29 | return new TypescriptCompiler(inputNode, options);
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | export class TypescriptCompiler extends BroccoliPlugin {
|
36 | private compiler: Compiler | undefined;
|
37 | private diagnosticHandler: DiagnosticsHandler;
|
38 | private options: NormalizedOptions;
|
39 |
|
40 | constructor(inputNode: any, options?: TypescriptCompilerOptions) {
|
41 | super([inputNode], {
|
42 | annotation: options && options.annotation,
|
43 | name: "broccoli-typescript-compiler",
|
44 | persistentOutput: true,
|
45 | });
|
46 | const normalizedOptions = normalizeOptions(options || {});
|
47 | this.options = normalizedOptions;
|
48 | this.diagnosticHandler = new DiagnosticsHandler(normalizedOptions);
|
49 | }
|
50 |
|
51 | public build() {
|
52 | const token = heimdall.start("TypeScript:compile");
|
53 | let compiler = this.compiler;
|
54 | if (!compiler) {
|
55 | compiler = this.compiler = new Compiler(
|
56 | toAbsolutePath(this.inputPaths[0]),
|
57 | toAbsolutePath(this.outputPath),
|
58 | this.options,
|
59 | this.diagnosticHandler
|
60 | );
|
61 | }
|
62 | compiler.compile();
|
63 | heimdall.stop(token);
|
64 | }
|
65 |
|
66 | public setDiagnosticWriter(write: (message: string) => void) {
|
67 | this.diagnosticHandler.setWrite(write);
|
68 | }
|
69 | }
|