docusaurus-plugin-typedoc 1.3.1 → 1.4.1

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,7 +2,7 @@
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
 
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,9 +9,11 @@ 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) => {
14
- // Check PluginConfig is typed to [string, PluginOptions]
15
- if (pluginConfig && typeof pluginConfig[1] === 'object') {
12
+ context.siteConfig?.plugins?.forEach((pluginConfig) => {
13
+ // Check PluginConfig is typed to ['docusaurus-plugin-typedoc', PluginOptions]
14
+ if (pluginConfig &&
15
+ pluginConfig[0].includes('docusaurus-plugin-typedoc') &&
16
+ typeof pluginConfig[1] === 'object') {
16
17
  generateTypedoc(context, pluginConfig[1]);
17
18
  }
18
19
  });
@@ -26,17 +27,13 @@ export default async function pluginDocusaurus(context, opts) {
26
27
  async function generateTypedoc(context, opts) {
27
28
  // get plugin options
28
29
  const options = getPluginOptions(context, opts);
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ const { id, ...typedocOptions } = options;
29
32
  // create outDir if it doesn't exist
30
- if (!fs.existsSync(options.out)) {
31
- fs.mkdirSync(options.out, { recursive: true });
33
+ if (!fs.existsSync(typedocOptions.out)) {
34
+ fs.mkdirSync(typedocOptions.out, { recursive: true });
32
35
  }
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
- });
36
+ // Bootstrap typedoc with options (this mimics the TypeDoc CLI)
37
+ const typedoc = await import('./typedoc.cjs');
38
+ await typedoc.bootstrap(typedocOptions);
42
39
  }
@@ -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.1",
4
- "description": "A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into a Docusaurus project.",
3
+ "version": "1.4.1",
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,19 +18,27 @@
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
- "test": "jest",
30
- "test:update": "npm run build && npm test -- -u"
26
+ "pretest": "rm -rf ./test/out && docusaurus generate-typedoc",
27
+ "test": "mocha --config ./mocha.config.json",
28
+ "build-and-test": "npm run build && npm test"
31
29
  },
32
30
  "author": "Thomas Grey",
33
31
  "license": "MIT",
32
+ "peerDependencies": {
33
+ "typedoc-plugin-markdown": ">=4.8.0"
34
+ },
35
+ "dependencies": {
36
+ "typedoc-docusaurus-theme": "^1.4.0"
37
+ },
38
+ "devDependencies": {
39
+ "@docusaurus/core": "^3.8.1",
40
+ "@docusaurus/types": "^3.8.1"
41
+ },
34
42
  "keywords": [
35
43
  "docusaurus",
36
44
  "typedoc",
@@ -1,41 +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
- * ```js filename="docusaurus.config.js"
22
- * {
23
- * plugins: [
24
- * [
25
- * 'docusaurus-plugin-typedoc',
26
- * {
27
- * "sidebar": {
28
- * "autoConfiguration": true,
29
- * "pretty": false,
30
- * "typescript": false,
31
- * "deprecatedItemClassName": "typedoc-sidebar-item-deprecated"
32
- * }
33
- * }
34
- * ]
35
- * ]
36
- * }
37
- *
38
- * @omitExample
39
- *
40
- */
41
- export declare const sidebar: Partial<DeclarationOption>;
@@ -1,55 +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
- * ```js filename="docusaurus.config.js"
23
- * {
24
- * plugins: [
25
- * [
26
- * 'docusaurus-plugin-typedoc',
27
- * {
28
- * "sidebar": {
29
- * "autoConfiguration": true,
30
- * "pretty": false,
31
- * "typescript": false,
32
- * "deprecatedItemClassName": "typedoc-sidebar-item-deprecated"
33
- * }
34
- * }
35
- * ]
36
- * ]
37
- * }
38
- *
39
- * @omitExample
40
- *
41
- */
42
- export const sidebar = {
43
- help: 'Configures the autogenerated Docusaurus sidebar.',
44
- type: ParameterType.Mixed,
45
- defaultValue: DEFAULT_SIDEBAR_OPTIONS,
46
- validate(value) {
47
- if (typeof value !== 'object') {
48
- console.warn('[typedoc-plugin-markdown] Sidebar must be an object.');
49
- }
50
- const invalidKeys = Object.keys(value).filter((key) => !Object.keys(DEFAULT_SIDEBAR_OPTIONS).includes(key));
51
- if (invalidKeys.length > 0) {
52
- console.warn(`[typedoc-plugin-markdown] Invalid keys in sidebar options: ${invalidKeys.join(', ')}`);
53
- }
54
- },
55
- };
@@ -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,76 +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
- const baseDir = adjustBaseDirectory(path.relative(siteDir, outputDir).split(path.sep).join('/'), docsPresetPath || 'docs');
11
- const sidebarJson = getSidebar(navigation, baseDir, sidebar, numberPrefixParser);
12
- const sidebarContent = sidebar.typescript
13
- ? getTypescriptSidebar(sidebarJson, sidebar)
14
- : getJsSidebar(sidebarJson, sidebar);
15
- fs.writeFileSync(sidebarPath, sidebarContent);
16
- }
17
- }
18
- function getTypescriptSidebar(sidebarJson, sidebar) {
19
- return `import { SidebarsConfig } from '@docusaurus/plugin-content-docs';
20
- const typedocSidebar: SidebarsConfig = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
21
- export default typedocSidebar;`;
22
- }
23
- function getJsSidebar(sidebarJson, sidebar) {
24
- return `// @ts-check
25
- /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
26
- const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
27
- module.exports = typedocSidebar.items;`;
28
- }
29
- function getSidebar(navigation, basePath, options, numberPrefixParser) {
30
- return navigation
31
- .map((navigationItem) => getNavigationItem(navigationItem, basePath, options, numberPrefixParser))
32
- .filter((navItem) => Boolean(navItem));
33
- }
34
- function getNavigationItem(navigationItem, basePath, options, numberPrefixParser) {
35
- const navigationItemPath = navigationItem.path || navigationItem.url;
36
- const parsedUrl = numberPrefixParser === false
37
- ? navigationItemPath
38
- : navigationItemPath?.replace(/\d+-/g, '');
39
- const getId = () => {
40
- const idParts = [];
41
- if (basePath.length > 0) {
42
- idParts.push(basePath);
43
- }
44
- if (parsedUrl) {
45
- idParts.push(parsedUrl.replace(/\\/g, '/'));
46
- }
47
- if (navigationItemPath) {
48
- return idParts.join('/').replace(/(.*)\.\w+$/, '$1');
49
- }
50
- return null;
51
- };
52
- const id = getId();
53
- if (navigationItem.children?.length) {
54
- return {
55
- type: 'category',
56
- label: navigationItem.title,
57
- items: getSidebar(navigationItem.children, basePath, options, numberPrefixParser),
58
- ...(id && {
59
- link: {
60
- type: 'doc',
61
- id,
62
- },
63
- }),
64
- };
65
- }
66
- return id
67
- ? {
68
- type: 'doc',
69
- id,
70
- label: navigationItem.title,
71
- ...(navigationItem.isDeprecated && {
72
- className: options.deprecatedItemClassName,
73
- }),
74
- }
75
- : null;
76
- }
@@ -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