docusaurus-plugin-typedoc 1.2.2 → 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 +1 -1
- package/dist/index.js +1 -1
- package/dist/options/declarations.d.ts +0 -8
- package/dist/options/declarations.js +0 -12
- package/dist/options/options.js +1 -4
- package/dist/{plugins → plugin}/docusaurus.js +13 -15
- package/dist/plugin/sidebar.d.ts +3 -0
- package/dist/{utils/get-sidebar.js → plugin/sidebar.js} +22 -1
- package/dist/plugin/typedoc.cjs +31 -0
- package/package.json +5 -6
- package/dist/plugins/typedoc.d.ts +0 -2
- package/dist/plugins/typedoc.js +0 -56
- package/dist/utils/get-sidebar.d.ts +0 -3
- /package/dist/{plugins → plugin}/docusaurus.d.ts +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './
|
|
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
|
*
|
package/dist/options/options.js
CHANGED
|
@@ -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 {
|
|
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,19 +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
|
-
|
|
31
|
-
|
|
32
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
30
|
+
if (!fs.existsSync(options.out)) {
|
|
31
|
+
fs.mkdirSync(options.out, { recursive: true });
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
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);
|
|
43
41
|
});
|
|
44
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
|
-
|
|
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.
|
|
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 &&
|
|
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.
|
|
43
|
-
"@docusaurus/types": "^3.
|
|
41
|
+
"@docusaurus/core": "^3.7.0",
|
|
42
|
+
"@docusaurus/types": "^3.7.0"
|
|
44
43
|
}
|
|
45
44
|
}
|
package/dist/plugins/typedoc.js
DELETED
|
@@ -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
|
-
}
|
|
File without changes
|