Skip to content

Commit 2771c0e

Browse files
committed
fixup!
1 parent c35b948 commit 2771c0e

File tree

9 files changed

+196
-139
lines changed

9 files changed

+196
-139
lines changed

generate-md.mjs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
import { Application } from "typedoc";
2-
import { fileURLToPath } from "node:url";
3-
import { resolve, dirname } from "node:path";
1+
import { Application } from 'typedoc';
42

5-
// Get the current file's directory
6-
const __filename = fileURLToPath(import.meta.url);
7-
const __dirname = dirname(__filename);
8-
9-
// Define all paths relative to the current file
10-
const entryPointsPath = resolve(__dirname, "./webpack/types.d.ts");
11-
const tsconfigPath = resolve(__dirname, "./tsconfig.json");
12-
const dockitTheme = resolve(__dirname, "./plugins/theme/index.mjs");
13-
const consolidationPlugin = resolve(__dirname, "./plugins/consolidation.mjs");
14-
15-
Application.bootstrapWithPlugins({
16-
entryPoints: [entryPointsPath],
17-
out: "generated-api",
3+
const app = await Application.bootstrapWithPlugins({
4+
entryPoints: ['./webpack/types.d.ts'],
5+
out: 'generated-api',
186

197
// Plugins
20-
plugin: ["typedoc-plugin-markdown", consolidationPlugin, dockitTheme],
8+
plugin: [
9+
'typedoc-plugin-markdown',
10+
'./plugins/processor.mjs',
11+
'./plugins/theme/index.mjs',
12+
],
13+
theme: 'doc-kit',
14+
15+
// Formatting
2116
hideGroupHeadings: true,
2217
hideBreadcrumbs: true,
23-
theme: "doc-kit",
24-
25-
tsconfig: tsconfigPath,
26-
entryFileName: "index",
2718
hidePageHeader: true,
2819
disableSources: true,
20+
2921
router: 'module',
30-
}).then(async (app) => app.generateOutputs(await app.convert()));
22+
entryFileName: 'index',
23+
24+
tsconfig: 'tsconfig.json',
25+
});
26+
27+
const project = await app.convert();
28+
29+
if (project) {
30+
await app.generateOutputs(project);
31+
}

package-lock.json

Lines changed: 3 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"scripts": {
3-
"build": "node generate-md.mjs && doc-kit generate -t web -i generated-api/webpack/namespaces/*.md -o out"
3+
"build": "node generate-md.mjs && doc-kit generate -t web -i generated-api/webpack/namespaces/*.md --type-map ./generated-type-map.json -o out"
44
},
55
"devDependencies": {
66
"@node-core/doc-kit": "^1.0.1",

plugins/consolidation.mjs

Lines changed: 0 additions & 15 deletions
This file was deleted.

plugins/processor.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Converter, ReflectionKind, Renderer } from 'typedoc';
2+
import { writeFileSync } from 'node:fs';
3+
/**
4+
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
5+
*/
6+
export function load(app) {
7+
// Merge `export=` namespaces into their parent
8+
app.converter.on(Converter.EVENT_RESOLVE_BEGIN, (context) => {
9+
context.project
10+
.getReflectionsByKind(ReflectionKind.Namespace)
11+
.filter((ref) => ref.name === 'export=')
12+
.forEach((namespace) =>
13+
context.project.mergeReflections(namespace, namespace.parent),
14+
);
15+
});
16+
17+
app.renderer.on(Renderer.EVENT_END, (context) => {
18+
const typeMap = Object.fromEntries(
19+
context.project
20+
.getReflectionsByKind(ReflectionKind.All)
21+
.filter((ref) => app.renderer.router.hasUrl(ref))
22+
.map((reference) => [
23+
reference.name,
24+
app.renderer.router
25+
.getFullUrl(reference)
26+
.replace('.md', '.html')
27+
.replace('webpack/namespaces/', ''),
28+
]),
29+
);
30+
31+
writeFileSync('generated-type-map.json', JSON.stringify(typeMap, null, 2));
32+
});
33+
}

plugins/theme/helpers/index.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @typedef {object} TypedListEntry
3+
* @property {string} [label]
4+
* @property {string} [name]
5+
* @property {import("typedoc").SomeType | string} [type]
6+
* @property {import("typedoc").Comment | import("typedoc").CommentTag} [comment]
7+
*/
8+
9+
/**
10+
* @param {import('typedoc-plugin-markdown').MarkdownThemeContext} ctx
11+
* @returns {import('typedoc-plugin-markdown').MarkdownThemeContext['helpers']}
12+
*/
13+
export default (ctx) => ({
14+
...ctx.helpers,
15+
16+
typedListItem({ label, name, type, comment }) {
17+
const namePart = label ? ` ${label}:` : name ? ` \`${name}\`` : '';
18+
19+
const typePart = type
20+
? ` ${typeof type === 'string' ? type : ctx.partials.someType(type)}`
21+
: '';
22+
23+
const descPart = comment
24+
? ` ${ctx.helpers.getCommentParts(comment.summary ?? comment.content)}`
25+
: '';
26+
27+
return `*${namePart}${typePart}${descPart}`;
28+
},
29+
30+
typedList(entries) {
31+
return entries.map(ctx.helpers.typedListItem).join('\n');
32+
},
33+
});

plugins/theme/index.mjs

Lines changed: 11 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,26 @@
1-
import { MarkdownTheme, MarkdownThemeContext } from "typedoc-plugin-markdown";
2-
import { ReflectionKind } from "typedoc";
3-
import * as typePartials from "./types.mjs";
4-
5-
const KIND_PREFIX = {
6-
[ReflectionKind.Class]: "Class",
7-
[ReflectionKind.Interface]: "Interface",
8-
[ReflectionKind.Enum]: "Enum",
9-
[ReflectionKind.TypeAlias]: "Type",
10-
[ReflectionKind.Namespace]: "Namespace",
11-
[ReflectionKind.Constructor]: "Constructor",
12-
[ReflectionKind.Property]: "Property",
13-
[ReflectionKind.Accessor]: "Accessor",
14-
};
15-
16-
const STATIC_PREFIX = {
17-
[ReflectionKind.Method]: "Static method",
18-
};
19-
20-
const resolveMemberPrefix = (model) =>
21-
model.flags?.isStatic ? STATIC_PREFIX[model.kind] : KIND_PREFIX[model.kind];
1+
import { MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown';
2+
import helpers from './helpers/index.mjs';
3+
import partials from './partials/index.mjs';
224

235
export class DocKitTheme extends MarkdownTheme {
246
getRenderContext(page) {
25-
this.application.options.setValue("propertiesFormat", "table");
7+
this.application.options.setValue('hidePageHeader', true);
8+
this.application.options.setValue('hideBreadcrumbs', true);
9+
this.application.options.setValue('propertiesFormat', 'table');
2610
return new DocKitThemeContext(this, page, this.application.options);
2711
}
2812
}
2913

3014
export class DocKitThemeContext extends MarkdownThemeContext {
31-
helpers = {
32-
...this.helpers,
33-
34-
/** @param {import('typedoc').ParameterReflection} */
35-
typedListItem: ({ label, name, type, comment }) => {
36-
const namePart = label ? ` ${label}:` : name ? ` \`${name}\`` : "";
37-
const typePart = type
38-
? ` ${typeof type === "string" ? type : this.partials.someType(type)}`
39-
: "";
40-
const descPart = comment
41-
? ` ${this.helpers.getCommentParts(comment.summary ?? comment.content)}`
42-
: "";
43-
44-
return `*${namePart}${typePart}${descPart}`;
45-
},
46-
47-
typedList: (entries) => entries.map(this.helpers.typedListItem).join("\n"),
48-
};
49-
partials = {
50-
...this.partials,
51-
...typePartials,
52-
53-
// Typed Lists
54-
parametersList: this.helpers.typedList,
55-
propertiesTable: this.helpers.typedList,
56-
signature: (model, options) => {
57-
const comment = options.multipleSignatures
58-
? model.comment
59-
: model.comment || model.parent?.comment;
15+
helpers = helpers(this);
6016

61-
return [
62-
model.typeParameters?.length &&
63-
this.partials.typeParametersList(model.typeParameters, {
64-
headingLevel: options.headingLevel,
65-
}),
66-
model.parameters?.length &&
67-
this.partials.parametersList(model.parameters, {
68-
headingLevel: options.headingLevel,
69-
}),
70-
this.helpers.typedListItem({
71-
label: "Returns",
72-
type: model.type ?? "void",
73-
comment: model.comment?.getTag("@returns"),
74-
}),
75-
"",
76-
comment &&
77-
this.partials.comment(comment, {
78-
headingLevel: options.headingLevel,
79-
}),
80-
]
81-
.filter((x) => (typeof x === "string" ? x : Boolean(x)))
82-
.join("\n");
83-
},
17+
partials = partials(this);
8418

85-
// Titles
86-
memberTitle: (model) => {
87-
const prefix = resolveMemberPrefix(model);
88-
const params = model.signatures?.[0]?.parameters ?? null;
89-
const name = params
90-
? // TODO: If params optional, wrap in `[]`
91-
`\`${model.name}(${params.map((p) => p.name).join(", ")})\``
92-
: `\`${model.name}\``;
93-
return prefix ? `${prefix}: ${name}` : name;
94-
},
19+
templates = {
20+
...this.templates,
9521
};
9622
}
9723

98-
/** @param {import('typedoc').Application} app */
9924
export function load(app) {
100-
app.renderer.defineTheme("doc-kit", DocKitTheme);
25+
app.renderer.defineTheme('doc-kit', DocKitTheme);
10126
}

0 commit comments

Comments
 (0)