forked from TypeStrong/typedoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild_specs.js
125 lines (115 loc) · 3.43 KB
/
rebuild_specs.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// @ts-check
"use strict";
Error.stackTraceLimit = 50;
const ts = require("typescript");
const fs = require("fs");
const path = require("path");
const TypeDoc = require("..");
const { getExpandedEntryPointsForPaths } = require("../dist/lib/utils");
const { ok } = require("assert");
const { SourceReference } = require("..");
const base = path.join(__dirname, "../src/test/converter");
const app = new TypeDoc.Application();
app.options.addReader(new TypeDoc.TSConfigReader());
app.bootstrap({
name: "typedoc",
excludeExternals: true,
disableSources: false,
tsconfig: path.join(base, "tsconfig.json"),
externalPattern: ["**/node_modules/**"],
entryPointStrategy: TypeDoc.EntryPointStrategy.Expand,
logLevel: TypeDoc.LogLevel.Warn,
gitRevision: "fake",
});
app.serializer.addSerializer({
priority: -1,
supports(obj) {
return obj instanceof SourceReference;
},
/**
* @param {SourceReference} ref
*/
toObject(ref, obj, _serializer) {
if (obj.url) {
obj.url = `typedoc://${obj.url.substring(
obj.url.indexOf(ref.fileName)
)}`;
}
return obj;
},
});
/** @type {[string, () => void, () => void][]} */
const conversions = [
[
"specs",
() => {
// nop
},
() => {
// nop
},
],
[
"specs-with-lump-categories",
() => app.options.setValue("categorizeByGroup", false),
() => app.options.setValue("categorizeByGroup", true),
],
[
"specs.nodoc",
() => app.options.setValue("excludeNotDocumented", true),
() => app.options.setValue("excludeNotDocumented", false),
],
];
/**
* Rebuilds the converter specs for the provided dirs.
* @param {string[]} dirs
*/
function rebuildConverterTests(dirs) {
const program = ts.createProgram(app.options.getFileNames(), {
...app.options.getCompilerOptions(),
noEmit: true,
});
const errors = ts.getPreEmitDiagnostics(program);
if (errors.length) {
app.logger.diagnostics(errors);
return;
}
for (const fullPath of dirs) {
console.log(fullPath);
for (const [file, before, after] of conversions) {
const out = path.join(fullPath, `${file}.json`);
if (fs.existsSync(out)) {
TypeDoc.resetReflectionID();
before();
const entry = getExpandedEntryPointsForPaths(
app.logger,
[fullPath],
app.options,
[program]
);
ok(entry, "Missing entry point");
const result = app.converter.convert(entry);
const serialized = app.serializer.toObject(result);
const data = JSON.stringify(serialized, null, " ") + "\n";
after();
fs.writeFileSync(out, data);
}
}
}
}
async function main(filter = "") {
console.log("Base directory is", base);
const dirs = await fs.promises.readdir(base, { withFileTypes: true });
await rebuildConverterTests(
dirs
.filter((dir) => {
if (!dir.isDirectory()) return false;
return dir.name.endsWith(filter);
})
.map((dir) => path.join(base, dir.name))
);
}
main(process.argv[2]).catch((reason) => {
console.error(reason);
process.exit(1);
});