-
-
Notifications
You must be signed in to change notification settings - Fork 198
feat(plugin-typedoc): Upgrade to TypeDoc v0.28 with new API #2790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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'; | ||
|
|
||
|
|
@@ -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({ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the constructor of the Application class has been made private, initialization is now done using the bootstrapWithPlugins method instead. |
||
| name: config.title, | ||
| entryPoints, | ||
| theme: 'markdown', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The theme option is no longer needed; instead, it is now specified via the writeOutput method. |
||
| disableSources: true, | ||
| router: 'kind', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the default output directory structure has changed, I added an option so that it can generate the same structure as before. |
||
| 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, | ||
|
Comment on lines
-42
to
-43
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These options have been removed and are no longer available. |
||
| 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, | ||
| ); | ||
|
Comment on lines
-50
to
+51
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the generateDocs method was changed to output HTML files, I updated the code to use the writeOutput method instead. |
||
| await patchGeneratedApiDocs(absoluteApiDir); | ||
| } | ||
| return config; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'), | ||
| ); | ||
|
Comment on lines
-73
to
-76
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated it to use the entryFileName option instead. |
||
| await generateMetaJson(absoluteApiDir); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this because it was not being used. |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TSConfigReader is now included by default when using the bootstrapWithPlugins method.