docusaurus-plugin-typedoc 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/docusaurus-plugin-typedoc.svg?logo=npm)](https://www.npmjs.com/package/docusaurus-plugin-typedoc) [![Build Status](https://github.com/typedoc2md/typedoc-plugin-markdown/actions/workflows/ci.docusaurus-plugin-typedoc.yml/badge.svg?branch=main&style=flat-square)](https://github.com/typedoc2md/typedoc-plugin-markdown/actions/workflows/ci.docusaurus-plugin-typedoc.yml)
4
4
 
5
- > A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into a Docusaurus project.
5
+ > A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into the Docusaurus CLI.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Please visit the [https://typedoc-plugin-markdown.org/plugins/docusaurus](https://typedoc-plugin-markdown.org/plugins/docusaurus) for comprehensive documentation, including options and usage guides.
9
+ Please visit [https://typedoc-plugin-markdown.org/plugins/docusaurus](https://typedoc-plugin-markdown.org/plugins/docusaurus) for comprehensive documentation, including options and usage guides.
10
10
 
11
11
  ## License
12
12
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- /**
2
- * @module core
3
- */
4
- export { PluginOptions } from './models.js';
5
- export { default } from './plugin/docusaurus.js';
1
+ export { default } from './plugin.js';
2
+ export { PluginOptions } from './types/index.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { default } from './plugin/docusaurus.js';
1
+ export { default } from './plugin.js';
@@ -0,0 +1,3 @@
1
+ import { TypeDocOptions } from 'typedoc';
2
+ import { PluginOptions } from './types/plugin.js';
3
+ export declare function getPluginOptions(context: any, opts: Partial<PluginOptions & TypeDocOptions>): Record<string, any>;
@@ -0,0 +1,22 @@
1
+ import * as path from 'path';
2
+ export function getPluginOptions(context, opts) {
3
+ const docsPreset = context.siteConfig?.presets?.find((preset) => Boolean(preset[1]?.docs));
4
+ const docsPresetPath = docsPreset
5
+ ? docsPreset[1]?.docs?.path || './docs'
6
+ : './docs';
7
+ const options = {
8
+ out: './docs/api',
9
+ docsPath: path.join(context.siteDir, docsPresetPath),
10
+ numberPrefixParser: docsPreset
11
+ ? (docsPreset[1]?.docs?.numberPrefixParser ?? true)
12
+ : true,
13
+ ...opts,
14
+ plugin: [
15
+ ...new Set([
16
+ ...['typedoc-plugin-markdown', 'typedoc-docusaurus-theme'],
17
+ ...(opts.plugin || []),
18
+ ]),
19
+ ],
20
+ };
21
+ return options;
22
+ }
@@ -0,0 +1,7 @@
1
+ import { TypeDocOptions } from 'typedoc';
2
+ import { Cli, LoadContext } from './types/index.js';
3
+ import { PluginOptions } from './types/plugin.js';
4
+ export default function pluginDocusaurus(context: LoadContext, opts: Partial<PluginOptions & TypeDocOptions>): Promise<{
5
+ name: string;
6
+ extendCli(cli: Cli): void;
7
+ }>;
@@ -1,6 +1,5 @@
1
1
  import * as fs from 'fs';
2
- import { getPluginOptions } from '../options/options.js';
3
- import { writeSidebar } from './sidebar.js';
2
+ import { getPluginOptions } from './options.js';
4
3
  export default async function pluginDocusaurus(context, opts) {
5
4
  await generateTypedoc(context, opts);
6
5
  return {
@@ -10,7 +9,7 @@ export default async function pluginDocusaurus(context, opts) {
10
9
  .command('generate-typedoc')
11
10
  .description(`[docusaurus-plugin-typedoc] Generate TypeDoc docs independently of the Docusaurus build process.`)
12
11
  .action(async () => {
13
- context.siteConfig?.plugins.forEach((pluginConfig) => {
12
+ context.siteConfig?.plugins?.forEach((pluginConfig) => {
14
13
  // Check PluginConfig is typed to [string, PluginOptions]
15
14
  if (pluginConfig && typeof pluginConfig[1] === 'object') {
16
15
  generateTypedoc(context, pluginConfig[1]);
@@ -26,17 +25,13 @@ export default async function pluginDocusaurus(context, opts) {
26
25
  async function generateTypedoc(context, opts) {
27
26
  // get plugin options
28
27
  const options = getPluginOptions(context, opts);
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ const { id, ...typedocOptions } = options;
29
30
  // create outDir if it doesn't exist
30
- if (!fs.existsSync(options.out)) {
31
- fs.mkdirSync(options.out, { recursive: true });
31
+ if (!fs.existsSync(typedocOptions.out)) {
32
+ fs.mkdirSync(typedocOptions.out, { recursive: true });
32
33
  }
33
- // configure options for typedoc
34
- const {
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
- id, siteDir, numberPrefixParser, docsPresetPath, sidebar, ...optionsPassedToTypeDoc } = options;
37
- const typeDocApp = await import('./typedoc.cjs');
38
- // bootstrap typedoc with options
39
- await typeDocApp.bootstrap(optionsPassedToTypeDoc, async (renderer) => {
40
- writeSidebar(renderer.navigation, renderer.outputDirectory, sidebar, siteDir, docsPresetPath, numberPrefixParser);
41
- });
34
+ // Bootstrap typedoc with options (this mimics the TypeDoc CLI)
35
+ const typedoc = await import('./typedoc.cjs');
36
+ await typedoc.bootstrap(typedocOptions);
42
37
  }
@@ -1,8 +1,15 @@
1
+ // @ts-check
2
+
1
3
  /**
2
- * Export as cjs to be compatible with esm
4
+ * Export as CJS to ensure a fully synchronous module cache.
5
+ *
6
+ * This prevents "plugin loaded multiple times" errors when Docusaurus triggers a recompile.
3
7
  */
4
8
  module.exports = {
5
- bootstrap: async (options, postRenderCallbackFn) => {
9
+ bootstrap: async (
10
+ /** @type {import('typedoc').TypeDocOptions} */
11
+ options,
12
+ ) => {
6
13
  const typedoc = await import('typedoc');
7
14
 
8
15
  const app = await typedoc.Application.bootstrapWithPlugins(options, [
@@ -11,8 +18,6 @@ module.exports = {
11
18
  new typedoc.TSConfigReader(),
12
19
  ]);
13
20
 
14
- app.renderer.postRenderAsyncJobs.push(postRenderCallbackFn);
15
-
16
21
  const project = await app.convert();
17
22
 
18
23
  // if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
@@ -0,0 +1,13 @@
1
+ export interface LoadContext {
2
+ siteDir: string;
3
+ siteConfig: {
4
+ plugins?: any[];
5
+ presets?: any[];
6
+ };
7
+ }
8
+ export type Cli = {
9
+ command(name: string): Cli;
10
+ description(desc: string): Cli;
11
+ option(flag: string, desc?: string): Cli;
12
+ action(fn: (...args: any[]) => void): void;
13
+ };
@@ -1,6 +1,7 @@
1
1
  /**
2
- * All plugin types are exported from this module.
2
+ * All plugin types are exported from here.
3
3
  *
4
4
  * @module
5
5
  */
6
- export * from './options.js';
6
+ export * from './docusaurus.js';
7
+ export * from './plugin.js';
@@ -1,6 +1,7 @@
1
1
  /**
2
- * All plugin types are exported from this module.
2
+ * All plugin types are exported from here.
3
3
  *
4
4
  * @module
5
5
  */
6
- export * from './options.js';
6
+ export * from './docusaurus.js';
7
+ export * from './plugin.js';
@@ -1,6 +1,4 @@
1
+ import { PluginOptions as TypedocDocusaurusThemeOptions } from 'typedoc-docusaurus-theme';
1
2
  import { PluginOptions as TypedocPluginMarkdownOptions } from 'typedoc-plugin-markdown';
2
- import { PluginOptions as DocusaurusOptions } from './types/index.js';
3
- export interface PluginOptions extends TypedocPluginMarkdownOptions, DocusaurusOptions {
4
- id: string;
5
- out: string;
3
+ export interface PluginOptions extends TypedocPluginMarkdownOptions, TypedocDocusaurusThemeOptions {
6
4
  }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.3.0",
4
- "description": "A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into a Docusaurus project.",
3
+ "version": "1.4.0",
4
+ "description": "A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into the Docusaurus CLI.",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"
7
7
  },
@@ -18,27 +18,26 @@
18
18
  "directory": "packages/docusaurus-plugin-typedoc"
19
19
  },
20
20
  "homepage": "http://typedoc-plugin-markdown.org/plugins/docusaurus",
21
- "peerDependencies": {
22
- "typedoc-plugin-markdown": ">=4.6.0"
23
- },
24
21
  "scripts": {
25
22
  "lint": "eslint ./src",
26
- "prebuild": "rm -rf dist && prebuild-options && copyfiles --up 1 ./src/**/*.cjs ./dist/",
23
+ "prebuild": "rm -rf dist && copyfiles --up 1 ./src/**/*.cjs ./dist/",
27
24
  "prepublishOnly": "npm run lint && npm run build",
28
25
  "build": "tsc",
29
- "pretest": "rm -rf ./test/out && docusaurus generate-typedoc",
30
- "test": "jest",
31
- "test:update": "npm run build && npm test -- -u"
26
+ "pretest": "cd ../../devtools/examples/docusaurus-ts && npm i && npm run generate",
27
+ "test": "node ./test/test.mjs",
28
+ "build-and-test": "npm run build && npm test"
32
29
  },
33
30
  "author": "Thomas Grey",
34
31
  "license": "MIT",
32
+ "peerDependencies": {
33
+ "typedoc-plugin-markdown": ">=4.6.0"
34
+ },
35
+ "dependencies": {
36
+ "typedoc-docusaurus-theme": "^1.4.0"
37
+ },
35
38
  "keywords": [
36
39
  "docusaurus",
37
40
  "typedoc",
38
41
  "plugin"
39
- ],
40
- "devDependencies": {
41
- "@docusaurus/core": "^3.7.0",
42
- "@docusaurus/types": "^3.7.0"
43
- }
42
+ ]
44
43
  }
@@ -1,22 +0,0 @@
1
- import { DeclarationOption } from 'typedoc';
2
- /**
3
- * **autoConfiguration**
4
- *
5
- * Set to `false` to disable sidebar generation. Defaults to `true`.
6
- *
7
- * **typescript**
8
- *
9
- * Set to `true` to generate a TypeScript file. Defaults to `false` (CommonJs).
10
- *
11
- * **pretty**
12
- *
13
- * Pretty format the sidebar JSON. Defaults to `false`.
14
- *
15
- * **deprecatedItemClassName**
16
- *
17
- * The class name to apply to deprecated items in the sidebar. Defaults to `"typedoc-sidebar-item-deprecated"`.
18
- *
19
- * Please see the [sidebar guide](/plugins/docusaurus/guides/sidebar) for additional information on sidebar setup.
20
- *
21
- */
22
- export declare const sidebar: Partial<DeclarationOption>;
@@ -1,36 +0,0 @@
1
- import { ParameterType } from 'typedoc';
2
- import { DEFAULT_SIDEBAR_OPTIONS } from './options.js';
3
- /**
4
- * **autoConfiguration**
5
- *
6
- * Set to `false` to disable sidebar generation. Defaults to `true`.
7
- *
8
- * **typescript**
9
- *
10
- * Set to `true` to generate a TypeScript file. Defaults to `false` (CommonJs).
11
- *
12
- * **pretty**
13
- *
14
- * Pretty format the sidebar JSON. Defaults to `false`.
15
- *
16
- * **deprecatedItemClassName**
17
- *
18
- * The class name to apply to deprecated items in the sidebar. Defaults to `"typedoc-sidebar-item-deprecated"`.
19
- *
20
- * Please see the [sidebar guide](/plugins/docusaurus/guides/sidebar) for additional information on sidebar setup.
21
- *
22
- */
23
- export const sidebar = {
24
- help: 'Configures the autogenerated Docusaurus sidebar.',
25
- type: ParameterType.Mixed,
26
- defaultValue: DEFAULT_SIDEBAR_OPTIONS,
27
- validate(value) {
28
- if (typeof value !== 'object') {
29
- console.warn('[typedoc-plugin-markdown] Sidebar must be an object.');
30
- }
31
- const invalidKeys = Object.keys(value).filter((key) => !Object.keys(DEFAULT_SIDEBAR_OPTIONS).includes(key));
32
- if (invalidKeys.length > 0) {
33
- console.warn(`[typedoc-plugin-markdown] Invalid keys in sidebar options: ${invalidKeys.join(', ')}`);
34
- }
35
- },
36
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * All plugin types are exported from this module.
3
- *
4
- * @module
5
- */
6
- export * as declarations from './declarations.js';
7
- export * as presets from './presets.js';
@@ -1,7 +0,0 @@
1
- /**
2
- * All plugin types are exported from this module.
3
- *
4
- * @module
5
- */
6
- export * as declarations from './declarations.js';
7
- export * as presets from './presets.js';
@@ -1,7 +0,0 @@
1
- export declare const DEFAULT_SIDEBAR_OPTIONS: {
2
- autoConfiguration: boolean;
3
- pretty: boolean;
4
- typescript: boolean;
5
- deprecatedItemClassName: string;
6
- };
7
- export declare function getPluginOptions(context: any, opts: Record<string, any>): Record<string, any>;
@@ -1,34 +0,0 @@
1
- import { presets } from './presets.js';
2
- export const DEFAULT_SIDEBAR_OPTIONS = {
3
- autoConfiguration: true,
4
- pretty: false,
5
- typescript: false,
6
- deprecatedItemClassName: 'typedoc-sidebar-item-deprecated',
7
- };
8
- const DEFAULT_PLUGIN_OPTIONS = {
9
- ...presets,
10
- id: 'default',
11
- sidebar: {
12
- ...DEFAULT_SIDEBAR_OPTIONS,
13
- },
14
- };
15
- export function getPluginOptions(context, opts) {
16
- const docsPreset = context.siteConfig?.presets?.find((preset) => Boolean(preset[1]?.docs));
17
- const options = {
18
- ...DEFAULT_PLUGIN_OPTIONS,
19
- siteDir: context.siteDir,
20
- docsPresetPath: docsPreset ? docsPreset[1]?.docs?.path : null,
21
- numberPrefixParser: docsPreset
22
- ? docsPreset[1]?.docs?.numberPrefixParser
23
- : null,
24
- ...opts,
25
- sidebar: {
26
- ...DEFAULT_PLUGIN_OPTIONS.sidebar,
27
- ...opts.sidebar,
28
- },
29
- plugin: [
30
- ...new Set([...['typedoc-plugin-markdown'], ...(opts.plugin || [])]),
31
- ],
32
- };
33
- return options;
34
- }
@@ -1,7 +0,0 @@
1
- export declare const presets: {
2
- plugin: string[];
3
- out: string;
4
- hideBreadcrumbs: boolean;
5
- hidePageHeader: boolean;
6
- entryFileName: string;
7
- };
@@ -1,7 +0,0 @@
1
- export const presets = {
2
- plugin: ['typedoc-plugin-markdown', 'docusaurus-plugin-typedoc'],
3
- out: './docs/api',
4
- hideBreadcrumbs: true,
5
- hidePageHeader: true,
6
- entryFileName: 'index.md',
7
- };
@@ -1,5 +0,0 @@
1
- import { PluginOptions } from '../models.js';
2
- export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): Promise<{
3
- name: string;
4
- extendCli(cli: any): void;
5
- }>;
@@ -1,3 +0,0 @@
1
- import { NavigationItem } from 'typedoc-plugin-markdown';
2
- import { Sidebar } from '../types/options.js';
3
- export declare function writeSidebar(navigation: NavigationItem[], outputDir: string, sidebar: Sidebar, siteDir: string, docsPresetPath: string, numberPrefixParser: any): void;
@@ -1,83 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { adjustBaseDirectory } from '../utils/adjust-basedir.js';
4
- export function writeSidebar(navigation, outputDir, sidebar, siteDir, docsPresetPath, numberPrefixParser) {
5
- if (sidebar?.autoConfiguration) {
6
- const sidebarFileName = sidebar.typescript
7
- ? 'typedoc-sidebar.ts'
8
- : 'typedoc-sidebar.cjs';
9
- const sidebarPath = path.resolve(outputDir, sidebarFileName);
10
- let baseDir = path
11
- .relative(siteDir, outputDir)
12
- .split(path.sep)
13
- .slice(1)
14
- .join('/');
15
- if (docsPresetPath) {
16
- baseDir = adjustBaseDirectory(baseDir, docsPresetPath);
17
- }
18
- const sidebarJson = getSidebar(navigation, baseDir, sidebar, numberPrefixParser);
19
- const sidebarContent = sidebar.typescript
20
- ? getTypescriptSidebar(sidebarJson, sidebar)
21
- : getJsSidebar(sidebarJson, sidebar);
22
- fs.writeFileSync(sidebarPath, sidebarContent);
23
- }
24
- }
25
- function getTypescriptSidebar(sidebarJson, sidebar) {
26
- return `import { SidebarsConfig } from '@docusaurus/plugin-content-docs';
27
- const typedocSidebar: SidebarsConfig = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
28
- export default typedocSidebar;`;
29
- }
30
- function getJsSidebar(sidebarJson, sidebar) {
31
- return `// @ts-check
32
- /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
33
- const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
34
- module.exports = typedocSidebar.items;`;
35
- }
36
- function getSidebar(navigation, basePath, options, numberPrefixParser) {
37
- return navigation
38
- .map((navigationItem) => getNavigationItem(navigationItem, basePath, options, numberPrefixParser))
39
- .filter((navItem) => Boolean(navItem));
40
- }
41
- function getNavigationItem(navigationItem, basePath, options, numberPrefixParser) {
42
- const navigationItemPath = navigationItem.path || navigationItem.url;
43
- const parsedUrl = numberPrefixParser === false
44
- ? navigationItemPath
45
- : navigationItemPath?.replace(/\d+-/g, '');
46
- const getId = () => {
47
- const idParts = [];
48
- if (basePath.length > 0) {
49
- idParts.push(basePath);
50
- }
51
- if (parsedUrl) {
52
- idParts.push(parsedUrl.replace(/\\/g, '/'));
53
- }
54
- if (navigationItemPath) {
55
- return idParts.join('/').replace(/(.*)\.\w+$/, '$1');
56
- }
57
- return null;
58
- };
59
- const id = getId();
60
- if (navigationItem.children?.length) {
61
- return {
62
- type: 'category',
63
- label: navigationItem.title,
64
- items: getSidebar(navigationItem.children, basePath, options, numberPrefixParser),
65
- ...(id && {
66
- link: {
67
- type: 'doc',
68
- id,
69
- },
70
- }),
71
- };
72
- }
73
- return id
74
- ? {
75
- type: 'doc',
76
- id,
77
- label: navigationItem.title,
78
- ...(navigationItem.isDeprecated && {
79
- className: options.deprecatedItemClassName,
80
- }),
81
- }
82
- : null;
83
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Describes the options declared by the plugin.
3
- */
4
- export interface PluginOptions {
5
- /**
6
- * Configures the autogenerated Docusaurus sidebar.
7
- */
8
- sidebar?: Sidebar;
9
- }
10
- export interface Sidebar {
11
- autoConfiguration: boolean;
12
- pretty: boolean;
13
- typescript: boolean;
14
- deprecatedItemClassName: string;
15
- }
@@ -1,4 +0,0 @@
1
- /*
2
- * THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY
3
- */
4
- export {};
@@ -1,4 +0,0 @@
1
- /**
2
- * This method is designed to resolve the base directory paths for documentation presets.
3
- */
4
- export declare function adjustBaseDirectory(originalPath: string, subPath: string): string;
@@ -1,28 +0,0 @@
1
- import * as path from 'path';
2
- /**
3
- * This method is designed to resolve the base directory paths for documentation presets.
4
- */
5
- export function adjustBaseDirectory(originalPath, subPath) {
6
- // Normalize the paths to handle different path formats and OS differences
7
- originalPath = path.normalize(originalPath);
8
- subPath = path.normalize(subPath);
9
- // Split the original path into an array of segments
10
- const segments = originalPath.split(path.sep);
11
- // Split the sub path into an array of segments and filter out ".." to handle relative paths
12
- const subSegments = subPath
13
- .split(path.sep)
14
- .filter((segment) => segment !== '..');
15
- // Find the index of the first sub path segment in the original path segments
16
- const startIndex = segments.indexOf(subSegments[0]);
17
- // Remove the sub path segments from the original path segments if found
18
- if (startIndex !== -1) {
19
- segments.splice(startIndex, subSegments.length);
20
- }
21
- // Join the segments back into a path and remove the leading slash if present
22
- let newPath = segments.join(path.sep);
23
- // Ensure there is no leading slash
24
- if (newPath.startsWith(path.sep)) {
25
- newPath = newPath.slice(1);
26
- }
27
- return newPath.replace(/\\/g, '/');
28
- }
File without changes