@rspress/plugin-typedoc 2.0.0-rc.1 → 2.0.0-rc.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/es/index.js +27 -45
- package/dist/types/index.d.ts +6 -0
- package/package.json +8 -8
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { cwd } from "process";
|
|
3
|
+
import { Application } from "typedoc";
|
|
3
4
|
import { load } from "typedoc-plugin-markdown";
|
|
4
5
|
import promises from "fs/promises";
|
|
5
6
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -28,36 +29,10 @@ function _async_to_generator(fn) {
|
|
|
28
29
|
});
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
|
-
function patchLinks(outputDir) {
|
|
32
|
-
return _async_to_generator(function*() {
|
|
33
|
-
const normalizeLinksInFile = (filePath)=>_async_to_generator(function*() {
|
|
34
|
-
const content = yield promises.readFile(filePath, 'utf-8');
|
|
35
|
-
const newContent = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, p1, p2)=>{
|
|
36
|
-
if ([
|
|
37
|
-
'/',
|
|
38
|
-
'.'
|
|
39
|
-
].includes(p2[0]) || p2.startsWith('http://') || p2.startsWith('https://')) return `[${p1}](${p2})`;
|
|
40
|
-
return `[${p1}](./${p2})`;
|
|
41
|
-
});
|
|
42
|
-
yield promises.writeFile(filePath, newContent);
|
|
43
|
-
})();
|
|
44
|
-
const traverse = (dir)=>_async_to_generator(function*() {
|
|
45
|
-
const files = yield promises.readdir(dir);
|
|
46
|
-
const filePaths = files.map((file)=>path.join(dir, file));
|
|
47
|
-
const stats = yield Promise.all(filePaths.map((fp)=>promises.stat(fp)));
|
|
48
|
-
yield Promise.all(stats.map((stat, index)=>{
|
|
49
|
-
const file = files[index];
|
|
50
|
-
const filePath = filePaths[index];
|
|
51
|
-
if (stat.isDirectory()) return traverse(filePath);
|
|
52
|
-
if (stat.isFile() && /\.mdx?/.test(file)) return normalizeLinksInFile(filePath);
|
|
53
|
-
}));
|
|
54
|
-
})();
|
|
55
|
-
yield traverse(outputDir);
|
|
56
|
-
})();
|
|
57
|
-
}
|
|
58
32
|
function generateMetaJson(absoluteApiDir) {
|
|
59
33
|
return _async_to_generator(function*() {
|
|
60
34
|
const metaJsonPath = path.join(absoluteApiDir, '_meta.json');
|
|
35
|
+
if (yield promises.access(metaJsonPath).then(()=>true).catch(()=>false)) return;
|
|
61
36
|
const files = yield promises.readdir(absoluteApiDir);
|
|
62
37
|
const filePaths = files.map((file)=>path.join(absoluteApiDir, file));
|
|
63
38
|
const stats = yield Promise.all(filePaths.map((fp)=>promises.stat(fp)));
|
|
@@ -70,13 +45,11 @@ function generateMetaJson(absoluteApiDir) {
|
|
|
70
45
|
yield promises.writeFile(metaJsonPath, JSON.stringify([
|
|
71
46
|
'index',
|
|
72
47
|
...meta
|
|
73
|
-
]));
|
|
48
|
+
], null, 2));
|
|
74
49
|
})();
|
|
75
50
|
}
|
|
76
51
|
function patchGeneratedApiDocs(absoluteApiDir) {
|
|
77
52
|
return _async_to_generator(function*() {
|
|
78
|
-
yield patchLinks(absoluteApiDir);
|
|
79
|
-
yield promises.rename(path.join(absoluteApiDir, 'README.md'), path.join(absoluteApiDir, 'index.md'));
|
|
80
53
|
yield generateMetaJson(absoluteApiDir);
|
|
81
54
|
})();
|
|
82
55
|
}
|
|
@@ -107,21 +80,22 @@ function src_async_to_generator(fn) {
|
|
|
107
80
|
};
|
|
108
81
|
}
|
|
109
82
|
function pluginTypeDoc(options) {
|
|
110
|
-
|
|
111
|
-
const
|
|
83
|
+
const { entryPoints: userEntryPoints = [], outDir = "api", setup = ()=>{} } = options;
|
|
84
|
+
const entryPoints = userEntryPoints.map((entryPath)=>{
|
|
85
|
+
if (!path.isAbsolute(entryPath)) return entryPath;
|
|
86
|
+
const cwdPosix = cwd().replace(/\\/g, '/');
|
|
87
|
+
const entryPosix = entryPath.replace(/\\/g, '/');
|
|
88
|
+
return path.posix.relative(cwdPosix, entryPosix);
|
|
89
|
+
});
|
|
112
90
|
return {
|
|
113
91
|
name: '@rspress/plugin-typedoc',
|
|
114
92
|
config (config) {
|
|
115
93
|
return src_async_to_generator(function*() {
|
|
116
|
-
|
|
117
|
-
docRoot = config.root;
|
|
118
|
-
app.options.addReader(new TSConfigReader());
|
|
119
|
-
load(app);
|
|
120
|
-
app.bootstrap({
|
|
94
|
+
let app = yield Application.bootstrapWithPlugins({
|
|
121
95
|
name: config.title,
|
|
122
96
|
entryPoints,
|
|
123
|
-
theme: 'markdown',
|
|
124
97
|
disableSources: true,
|
|
98
|
+
router: 'kind',
|
|
125
99
|
readme: 'none',
|
|
126
100
|
githubPages: false,
|
|
127
101
|
requiredToBeDocumented: [
|
|
@@ -130,16 +104,24 @@ function pluginTypeDoc(options) {
|
|
|
130
104
|
'Interface'
|
|
131
105
|
],
|
|
132
106
|
plugin: [
|
|
133
|
-
|
|
107
|
+
load
|
|
134
108
|
],
|
|
109
|
+
entryFileName: 'index',
|
|
110
|
+
hidePageHeader: true,
|
|
135
111
|
hideBreadcrumbs: true,
|
|
136
|
-
|
|
137
|
-
|
|
112
|
+
pageTitleTemplates: {
|
|
113
|
+
module: '{kind}: {name}'
|
|
114
|
+
},
|
|
115
|
+
cleanOutputDir: false
|
|
138
116
|
});
|
|
139
|
-
|
|
117
|
+
app = (yield setup(app)) || app;
|
|
118
|
+
const project = yield app.convert();
|
|
140
119
|
if (project) {
|
|
141
|
-
const absoluteApiDir = path.join(
|
|
142
|
-
yield app.
|
|
120
|
+
const absoluteApiDir = path.join(config.root, outDir);
|
|
121
|
+
yield app.outputs.writeOutput({
|
|
122
|
+
name: 'markdown',
|
|
123
|
+
path: absoluteApiDir
|
|
124
|
+
}, project);
|
|
143
125
|
yield patchGeneratedApiDocs(absoluteApiDir);
|
|
144
126
|
}
|
|
145
127
|
return config;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Application } from 'typedoc';
|
|
1
2
|
import type { RspressPlugin } from '@rspress/core';
|
|
2
3
|
|
|
3
4
|
export declare function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin;
|
|
@@ -13,6 +14,11 @@ export declare interface PluginTypeDocOptions {
|
|
|
13
14
|
* @default 'api'
|
|
14
15
|
*/
|
|
15
16
|
outDir?: string;
|
|
17
|
+
/**
|
|
18
|
+
* A function to setup the TypeDoc Application.
|
|
19
|
+
* @param app
|
|
20
|
+
*/
|
|
21
|
+
setup?: (app: Application) => Promise<Application> | Promise<void> | void;
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-typedoc",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.3",
|
|
4
4
|
"description": "A plugin for rspress to integrate typedoc",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"typedoc": "0.
|
|
32
|
-
"typedoc-plugin-markdown": "
|
|
31
|
+
"typedoc": "0.28.15",
|
|
32
|
+
"typedoc-plugin-markdown": "4.9.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@microsoft/api-extractor": "^7.55.
|
|
36
|
-
"@rslib/core": "0.
|
|
35
|
+
"@microsoft/api-extractor": "^7.55.2",
|
|
36
|
+
"@rslib/core": "0.18.5",
|
|
37
37
|
"@types/node": "^22.8.1",
|
|
38
|
-
"@types/react": "^19.2.
|
|
38
|
+
"@types/react": "^19.2.7",
|
|
39
39
|
"@types/react-dom": "^19.2.3",
|
|
40
|
-
"react": "^19.2.
|
|
40
|
+
"react": "^19.2.3",
|
|
41
41
|
"rsbuild-plugin-publint": "^0.3.3",
|
|
42
42
|
"typescript": "^5.8.2",
|
|
43
43
|
"@rspress/config": "1.0.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@rspress/core": "^2.0.0-rc.
|
|
46
|
+
"@rspress/core": "^2.0.0-rc.3"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=18.0.0"
|