docusaurus-plugin-typedoc 1.2.1 → 1.2.3

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/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * @module core
3
3
  */
4
4
  export { PluginOptions } from './models.js';
5
- export { default } from './plugins/docusaurus.js';
5
+ export { default } from './plugin/docusaurus.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { default } from './plugins/docusaurus.js';
1
+ export { default } from './plugin/docusaurus.js';
@@ -1,12 +1,4 @@
1
1
  import { DeclarationOption } from 'typedoc';
2
- /**
3
- * Used internally to pass options from docusaurus.config to TypeDoc.
4
- *
5
- * @internal
6
- *
7
- * @hidden
8
- */
9
- export declare const docusaurusConfigOptions: Partial<DeclarationOption>;
10
2
  /**
11
3
  * **autoConfiguration**
12
4
  *
@@ -1,17 +1,5 @@
1
1
  import { ParameterType } from 'typedoc';
2
2
  import { DEFAULT_SIDEBAR_OPTIONS } from './options.js';
3
- /**
4
- * Used internally to pass options from docusaurus.config to TypeDoc.
5
- *
6
- * @internal
7
- *
8
- * @hidden
9
- */
10
- export const docusaurusConfigOptions = {
11
- help: 'docusaurus.config options - should not be used if running as a docusaurus plugin.',
12
- type: ParameterType.String,
13
- defaultValue: '{}',
14
- };
15
3
  /**
16
4
  * **autoConfiguration**
17
5
  *
@@ -26,10 +26,7 @@ export function getPluginOptions(context, opts) {
26
26
  ...opts.sidebar,
27
27
  },
28
28
  plugin: [
29
- ...new Set([
30
- ...['typedoc-plugin-markdown', 'docusaurus-plugin-typedoc/typedoc'],
31
- ...(opts.plugin || []),
32
- ]),
29
+ ...new Set([...['typedoc-plugin-markdown'], ...(opts.plugin || [])]),
33
30
  ],
34
31
  };
35
32
  return options;
@@ -1,8 +1,6 @@
1
- import { spawnSync } from 'child_process';
2
1
  import * as fs from 'fs';
3
- import * as path from 'path';
4
2
  import { getPluginOptions } from '../options/options.js';
5
- import { presets } from '../options/presets.js';
3
+ import { writeSidebar } from './sidebar.js';
6
4
  export default async function pluginDocusaurus(context, opts) {
7
5
  await generateTypedoc(context, opts);
8
6
  return {
@@ -26,18 +24,19 @@ export default async function pluginDocusaurus(context, opts) {
26
24
  * Initiates a new typedoc Application bootstrapped with plugin options
27
25
  */
28
26
  async function generateTypedoc(context, opts) {
27
+ // get plugin options
28
+ const options = getPluginOptions(context, opts);
29
29
  // create outDir if it doesn't exist
30
- const outputDir = path.join(context?.siteDir, presets.out);
31
- if (!fs.existsSync(outputDir)) {
32
- fs.mkdirSync(outputDir, { recursive: true });
30
+ if (!fs.existsSync(options.out)) {
31
+ fs.mkdirSync(options.out, { recursive: true });
33
32
  }
34
- const { plugin, ...options } = getPluginOptions(context, opts);
35
- // spawn typedoc process and pass docusaurus.config options as a string
36
- spawnSync('typedoc', [
37
- ...plugin.flatMap((plugin) => ['--plugin', plugin]),
38
- '--docusaurusConfigOptions',
39
- `${JSON.stringify(options)}`,
40
- ], {
41
- stdio: 'inherit',
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);
42
41
  });
43
42
  }
@@ -0,0 +1,3 @@
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,4 +1,25 @@
1
- export function getSidebar(navigation, basePath, options, numberPrefixParser) {
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 sidebarPath = path.resolve(outputDir, 'typedoc-sidebar.cjs');
7
+ let baseDir = path
8
+ .relative(siteDir, outputDir)
9
+ .split(path.sep)
10
+ .slice(1)
11
+ .join('/');
12
+ if (docsPresetPath) {
13
+ baseDir = adjustBaseDirectory(baseDir, docsPresetPath);
14
+ }
15
+ const sidebarJson = getSidebar(navigation, baseDir, sidebar, numberPrefixParser);
16
+ fs.writeFileSync(sidebarPath, `// @ts-check
17
+ /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
18
+ const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
19
+ module.exports = typedocSidebar.items;`);
20
+ }
21
+ }
22
+ function getSidebar(navigation, basePath, options, numberPrefixParser) {
2
23
  return navigation
3
24
  .map((navigationItem) => getNavigationItem(navigationItem, basePath, options, numberPrefixParser))
4
25
  .filter((navItem) => Boolean(navItem));
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Export as cjs to be compatible with esm
3
+ */
4
+ module.exports = {
5
+ bootstrap: async (options, postRenderCallbackFn) => {
6
+ const typedoc = await import('typedoc');
7
+
8
+ const app = await typedoc.Application.bootstrapWithPlugins(options, [
9
+ new typedoc.TypeDocReader(),
10
+ new typedoc.PackageJsonReader(),
11
+ new typedoc.TSConfigReader(),
12
+ ]);
13
+
14
+ app.renderer.postRenderAsyncJobs.push(postRenderCallbackFn);
15
+
16
+ const project = await app.convert();
17
+
18
+ // if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
19
+ if (!project) {
20
+ return;
21
+ }
22
+
23
+ if (options.watch) {
24
+ app.convertAndWatch(async (project) => {
25
+ await app.generateOutputs(project);
26
+ });
27
+ } else {
28
+ await app.generateOutputs(project);
29
+ }
30
+ },
31
+ };
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into a Docusaurus project.",
5
5
  "exports": {
6
- ".": "./dist/index.js",
7
- "./typedoc": "./dist/plugins/typedoc.js"
6
+ ".": "./dist/index.js"
8
7
  },
9
8
  "type": "module",
10
9
  "files": [
@@ -24,7 +23,7 @@
24
23
  },
25
24
  "scripts": {
26
25
  "lint": "eslint ./src",
27
- "prebuild": "rm -rf dist && prebuild-options",
26
+ "prebuild": "rm -rf dist && copyfiles --up 1 ./src/**/*.cjs ./dist/",
28
27
  "prepublishOnly": "npm run lint && npm run build",
29
28
  "build": "tsc",
30
29
  "pretest": "rm -rf ./test/out && docusaurus generate-typedoc",
@@ -39,7 +38,7 @@
39
38
  "plugin"
40
39
  ],
41
40
  "devDependencies": {
42
- "@docusaurus/core": "^3.6.1",
43
- "@docusaurus/types": "^3.6.1"
41
+ "@docusaurus/core": "^3.7.0",
42
+ "@docusaurus/types": "^3.7.0"
44
43
  }
45
44
  }
@@ -1,2 +0,0 @@
1
- import { MarkdownApplication } from 'typedoc-plugin-markdown';
2
- export declare function load(app: MarkdownApplication): void;
@@ -1,56 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as options from '../options/declarations.js';
4
- import { adjustBaseDirectory } from '../utils/adjust-basedir.js';
5
- import { getSidebar } from '../utils/get-sidebar.js';
6
- export function load(app) {
7
- Object.entries(options).forEach(([name, option]) => {
8
- app.options.addDeclaration({
9
- name,
10
- ...option,
11
- });
12
- });
13
- app.options.addReader(new (class {
14
- name = 'docusaurus-options';
15
- order = 100;
16
- supportsPackages = false;
17
- read(container) {
18
- const presets = JSON.parse(container.getValue('docusaurusConfigOptions'));
19
- const ignoreKeys = [
20
- 'id',
21
- 'siteDir',
22
- 'docsPresetPath',
23
- 'numberPrefixParser',
24
- ];
25
- Object.entries(presets)
26
- .filter(([key]) => !ignoreKeys.includes(key))
27
- .forEach(([key, value]) => {
28
- container.setValue(key, value);
29
- });
30
- }
31
- })());
32
- app.renderer.postRenderAsyncJobs.push(async (output) => {
33
- const outputDir = app.options.getValue('out');
34
- const docusaurusConfigOptions = JSON.parse(app.options.getValue('docusaurusConfigOptions'));
35
- const sidebar = app.options.getValue('sidebar');
36
- const siteDir = docusaurusConfigOptions.siteDir;
37
- const docsPresetPath = docusaurusConfigOptions.docsPresetPath;
38
- const numberPrefixParser = docusaurusConfigOptions.numberPrefixParser;
39
- if (sidebar?.autoConfiguration && output.navigation) {
40
- const sidebarPath = path.resolve(outputDir, 'typedoc-sidebar.cjs');
41
- let baseDir = path
42
- .relative(siteDir, outputDir)
43
- .split(path.sep)
44
- .slice(1)
45
- .join('/');
46
- if (docsPresetPath) {
47
- baseDir = adjustBaseDirectory(baseDir, docsPresetPath);
48
- }
49
- const sidebarJson = getSidebar(output.navigation, baseDir, sidebar, numberPrefixParser);
50
- fs.writeFileSync(sidebarPath, `// @ts-check
51
- /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
52
- const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
53
- module.exports = typedocSidebar.items;`);
54
- }
55
- });
56
- }
@@ -1,3 +0,0 @@
1
- import { NavigationItem } from 'typedoc-plugin-markdown';
2
- import { Sidebar } from '../types/options.js';
3
- export declare function getSidebar(navigation: NavigationItem[], basePath: string, options: Sidebar, numberPrefixParser?: any): any;
File without changes