/
programs.ts
79 lines (68 loc) · 2.23 KB
/
programs.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { deepStrictEqual as equal } from "assert";
import { join } from "path";
import * as ts from "typescript";
import { Application, EntryPointStrategy, TSConfigReader } from "..";
let converterApp: Application | undefined;
let converterProgram: ts.Program | undefined;
let converter2App: Application | undefined;
let converter2Program: ts.Program | undefined;
export function getConverterBase() {
return join(__dirname, "converter");
}
export function getConverterApp() {
if (!converterApp) {
converterApp = new Application();
converterApp.options.addReader(new TSConfigReader());
converterApp.bootstrap({
logger: "none",
name: "typedoc",
excludeExternals: true,
disableSources: true,
tsconfig: join(getConverterBase(), "tsconfig.json"),
externalPattern: ["**/node_modules/**"],
plugin: [],
entryPointStrategy: EntryPointStrategy.Expand,
});
}
return converterApp;
}
export function getConverterProgram() {
if (!converterProgram) {
const app = getConverterApp();
converterProgram = ts.createProgram(
app.options.getFileNames(),
app.options.getCompilerOptions()
);
const errors = ts.getPreEmitDiagnostics(converterProgram);
equal(errors, []);
}
return converterProgram;
}
export function getConverter2Base() {
return join(__dirname, "converter2");
}
export function getConverter2App() {
if (!converter2App) {
converter2App = new Application();
converter2App.options.addReader(new TSConfigReader());
converter2App.bootstrap({
excludeExternals: true,
tsconfig: join(getConverter2Base(), "tsconfig.json"),
plugin: [],
validation: true,
});
}
return converter2App;
}
export function getConverter2Program() {
if (!converter2Program) {
const app = getConverter2App();
converter2Program = ts.createProgram(
app.options.getFileNames(),
app.options.getCompilerOptions()
);
const errors = ts.getPreEmitDiagnostics(converter2Program);
equal(errors, []);
}
return converter2Program;
}