11import path from 'node:path' ;
22import type { RspressPlugin } from '@rspress/core' ;
3- import { Application , TSConfigReader } from 'typedoc' ;
4- import { load } from 'typedoc-plugin-markdown' ;
3+ import { Application } from 'typedoc' ;
4+ import { load as loadPluginMarkdown } from 'typedoc-plugin-markdown' ;
55import { API_DIR } from './constants' ;
66import { patchGeneratedApiDocs } from './patch' ;
77
@@ -19,35 +19,36 @@ export interface PluginTypeDocOptions {
1919}
2020
2121export function pluginTypeDoc ( options : PluginTypeDocOptions ) : RspressPlugin {
22- let docRoot : string | undefined ;
2322 const { entryPoints = [ ] , outDir = API_DIR } = options ;
2423 return {
2524 name : '@rspress/plugin-typedoc' ,
2625 async config ( config ) {
27- const app = new Application ( ) ;
28- docRoot = config . root ;
29- app . options . addReader ( new TSConfigReader ( ) ) ;
30- load ( app ) ;
31- app . bootstrap ( {
26+ const app = await Application . bootstrapWithPlugins ( {
3227 name : config . title ,
3328 entryPoints,
34- theme : 'markdown' ,
3529 disableSources : true ,
30+ router : 'kind' ,
3631 readme : 'none' ,
3732 githubPages : false ,
3833 requiredToBeDocumented : [ 'Class' , 'Function' , 'Interface' ] ,
39- plugin : [ 'typedoc-plugin-markdown' ] ,
40- // @ts -expect-error - FIXME: current version of MarkdownTheme has no export, bump related package versions
34+ // @ts -expect-error - Typedoc does not export a type for this options
35+ plugin : [ loadPluginMarkdown ] ,
36+ entryFileName : 'index' ,
37+ hidePageHeader : true ,
4138 hideBreadcrumbs : true ,
42- hideMembersSymbol : true ,
43- allReflectionsHaveOwnDocument : true ,
39+ pageTitleTemplates : {
40+ module : '{kind}: {name}' , // e.g. "Module: MyModule"
41+ } ,
4442 } ) ;
45- const project = app . convert ( ) ;
4643
44+ const project = await app . convert ( ) ;
4745 if ( project ) {
4846 // 1. Generate doc/api, doc/api/_meta.json by typedoc
49- const absoluteApiDir = path . join ( docRoot ! , outDir ) ;
50- await app . generateDocs ( project , absoluteApiDir ) ;
47+ const absoluteApiDir = path . join ( config . root ! , outDir ) ;
48+ await app . outputs . writeOutput (
49+ { name : 'markdown' , path : absoluteApiDir } ,
50+ project ,
51+ ) ;
5152 await patchGeneratedApiDocs ( absoluteApiDir ) ;
5253 }
5354 return config ;
0 commit comments