-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathindex.mjs
More file actions
87 lines (75 loc) · 2.94 KB
/
Copy pathindex.mjs
File metadata and controls
87 lines (75 loc) · 2.94 KB
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
import { Converter, ReflectionKind, Renderer } from 'typedoc';
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { applyExportEqualsReflections } from './exportEquals.mjs';
import { applySourceMetadata } from './source.mjs';
import { DocKitRouter } from './router.mjs';
import { sidebar } from './site.mjs';
import { createTypeMap } from './typeMap.mjs';
import { categoryForReflection } from '../shared/categories.mjs';
/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.defineRouter('doc-kit', DocKitRouter);
app.options.addDeclaration({ name: 'base' });
app.converter.on(Converter.EVENT_RESOLVE_BEGIN, context => {
// doc-kit has property metadata, not TypeDoc accessor metadata.
context.project
.getReflectionsByKind(ReflectionKind.Accessor)
.forEach(accessor => {
accessor.kind = ReflectionKind.Property;
if (accessor.getSignature) {
accessor.type = accessor.getSignature.type;
accessor.comment = accessor.getSignature.comment;
} else if (accessor.setSignature) {
accessor.type = accessor.setSignature.parameters?.[0]?.type;
accessor.comment = accessor.setSignature.comment;
}
});
// Reference reflections duplicate the real declaration entries and confuse
// both routing and the custom type map.
context.project
.getReflectionsByKind(ReflectionKind.Reference)
.forEach(ref => context.project.removeReflection(ref));
applyExportEqualsReflections(context.project);
applySourceMetadata(context.project);
});
app.converter.on(Converter.EVENT_RESOLVE_END, context => {
const project = context.project;
const internalModule = project.children?.find(c => c.name === '<internal>');
if (internalModule) {
const importantTypes = [];
internalModule.children.forEach(child => {
// TODO: We are calling `categoryForReflection` here, and then again when routing
// We should cache the result to avoid re-looking up that data
if (categoryForReflection(child)) {
importantTypes.push(child);
} else {
project.removeReflection(child);
}
});
internalModule.children = importantTypes;
project.mergeReflections(internalModule, project);
}
});
app.renderer.on(Renderer.EVENT_END, () => {
// doc-kit resolves custom type annotations from this map while generating
// HTML, so use the final router URLs instead of recomputing paths here.
const typeMap = createTypeMap(app.renderer.router);
writeFileSync(
join(app.options.getValue('out'), 'type-map.json'),
JSON.stringify(typeMap, null, 2)
);
writeFileSync(
join(app.options.getValue('out'), 'site.json'),
JSON.stringify(
{
sidebar: sidebar(app.renderer.router, app.options.getValue('base')),
},
null,
2
)
);
});
}