Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions e2e/fixtures/plugin-typedoc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ test.describe('plugin-typedoc single entry', async () => {
[
'@rspress-fixture/rspress-plugin-typedoc-single',
'Functions',
'Function: createMiddleware',
'Function: mergeMiddlewares',
'Function: createMiddleware()',
'Function: mergeMiddlewares()',
'Types',
'Type alias: Middleware',
'Type Alias: Middleware()',
].join(','),
);
});
Expand Down Expand Up @@ -68,21 +68,21 @@ test.describe('plugin-typedoc multi entries', async () => {
[
'@rspress-fixture/rspress-plugin-typedoc-multi',
'Functions',
'Function: createMiddleware',
'Function: mergeMiddlewares',
'Function: getRspressUrl',
'Function: createMiddleware()',
'Function: mergeMiddlewares()',
'Function: getRspressUrl()',
'Modules',
'Module: middleware',
'Module: raw-link',
'Types',
'Type alias: Middleware',
'Type Alias: Middleware()',
].join(','),
);
});

test('Should render raw link correctly', async ({ page }) => {
await page.goto(
`http://localhost:${appPort}/api/functions/raw_link.getRspressUrl.html`,
`http://localhost:${appPort}/api/functions/raw-link.getRspressUrl.html`,
{
waitUntil: 'networkidle',
},
Expand Down
6 changes: 3 additions & 3 deletions e2e/fixtures/plugin-typedoc/multi/rspress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export default defineConfig({
plugins: [
pluginTypeDoc({
entryPoints: [
path.join('./src/index.ts'),
path.join('./src/middleware.ts'),
path.join('./src/raw-link.ts'),
'./src/index.ts',
'./src/middleware.ts',
'./src/raw-link.ts',
],
}),
],
Expand Down
5 changes: 1 addition & 4 deletions e2e/fixtures/plugin-typedoc/single/rspress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ export default defineConfig({
root: path.join(__dirname, 'doc'),
plugins: [
pluginTypeDoc({
entryPoints: [
path.join('./src/index.ts'),
// path.join('../../packages/rspack/src/hello.ts')
],
entryPoints: ['./src/index.ts'],
}),
],
});
4 changes: 2 additions & 2 deletions packages/plugin-typedoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"typedoc": "0.24.8",
"typedoc-plugin-markdown": "3.17.1"
"typedoc": "0.28.15",
"typedoc-plugin-markdown": "4.9.0"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.55.1",
Expand Down
33 changes: 17 additions & 16 deletions packages/plugin-typedoc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import type { RspressPlugin } from '@rspress/core';
import { Application, TSConfigReader } from 'typedoc';
import { load } from 'typedoc-plugin-markdown';
import { Application } from 'typedoc';
import { load as loadPluginMarkdown } from 'typedoc-plugin-markdown';
import { API_DIR } from './constants';
import { patchGeneratedApiDocs } from './patch';

Expand All @@ -19,35 +19,36 @@ export interface PluginTypeDocOptions {
}

export function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin {
let docRoot: string | undefined;
const { entryPoints = [], outDir = API_DIR } = options;
return {
name: '@rspress/plugin-typedoc',
async config(config) {
const app = new Application();
docRoot = config.root;
app.options.addReader(new TSConfigReader());
load(app);
app.bootstrap({
const app = await Application.bootstrapWithPlugins({
name: config.title,
entryPoints,
theme: 'markdown',
disableSources: true,
router: 'kind',
readme: 'none',
githubPages: false,
requiredToBeDocumented: ['Class', 'Function', 'Interface'],
plugin: ['typedoc-plugin-markdown'],
// @ts-expect-error - FIXME: current version of MarkdownTheme has no export, bump related package versions
// @ts-expect-error - Typedoc does not export a type for this options
plugin: [loadPluginMarkdown],
entryFileName: 'index',
hidePageHeader: true,
hideBreadcrumbs: true,
hideMembersSymbol: true,
allReflectionsHaveOwnDocument: true,
pageTitleTemplates: {
module: '{kind}: {name}', // e.g. "Module: MyModule"
},
});
const project = app.convert();

const project = await app.convert();
if (project) {
// 1. Generate doc/api, doc/api/_meta.json by typedoc
const absoluteApiDir = path.join(docRoot!, outDir);
await app.generateDocs(project, absoluteApiDir);
const absoluteApiDir = path.join(config.root!, outDir);
await app.outputs.writeOutput(
{ name: 'markdown', path: absoluteApiDir },
project,
);
await patchGeneratedApiDocs(absoluteApiDir);
}
return config;
Expand Down
4 changes: 0 additions & 4 deletions packages/plugin-typedoc/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,5 @@ async function generateMetaJson(absoluteApiDir: string) {

export async function patchGeneratedApiDocs(absoluteApiDir: string) {
await patchLinks(absoluteApiDir);
await fs.rename(
path.join(absoluteApiDir, 'README.md'),
path.join(absoluteApiDir, 'index.md'),
);
await generateMetaJson(absoluteApiDir);
}
3 changes: 0 additions & 3 deletions packages/plugin-typedoc/src/utils.ts

This file was deleted.

Loading
Loading