@rspress/plugin-typedoc 2.0.0-beta.3 → 2.0.0-beta.31
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 +1 -1
- package/dist/es/index.js +20 -49
- package/dist/types/index.d.ts +1 -1
- package/package.json +10 -12
package/README.md
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { Application, TSConfigReader } from "typedoc";
|
|
3
|
+
import { load } from "typedoc-plugin-markdown";
|
|
4
|
+
import promises from "fs/promises";
|
|
5
5
|
const API_DIR = 'api';
|
|
6
6
|
async function patchLinks(outputDir) {
|
|
7
7
|
const normalizeLinksInFile = async (filePath)=>{
|
|
8
|
-
const content = await
|
|
8
|
+
const content = await promises.readFile(filePath, 'utf-8');
|
|
9
9
|
const newContent = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, p1, p2)=>{
|
|
10
10
|
if ([
|
|
11
11
|
'/',
|
|
12
12
|
'.'
|
|
13
|
-
].includes(p2[0])) return `[${p1}](${p2})`;
|
|
13
|
+
].includes(p2[0]) || p2.startsWith('http://') || p2.startsWith('https://')) return `[${p1}](${p2})`;
|
|
14
14
|
return `[${p1}](./${p2})`;
|
|
15
15
|
});
|
|
16
|
-
await
|
|
16
|
+
await promises.writeFile(filePath, newContent);
|
|
17
17
|
};
|
|
18
18
|
const traverse = async (dir)=>{
|
|
19
|
-
const files = await
|
|
20
|
-
const filePaths = files.map((file)=>
|
|
21
|
-
const stats = await Promise.all(filePaths.map((fp)=>
|
|
19
|
+
const files = await promises.readdir(dir);
|
|
20
|
+
const filePaths = files.map((file)=>path.join(dir, file));
|
|
21
|
+
const stats = await Promise.all(filePaths.map((fp)=>promises.stat(fp)));
|
|
22
22
|
await Promise.all(stats.map((stat, index)=>{
|
|
23
23
|
const file = files[index];
|
|
24
24
|
const filePath = filePaths[index];
|
|
@@ -29,45 +29,36 @@ async function patchLinks(outputDir) {
|
|
|
29
29
|
await traverse(outputDir);
|
|
30
30
|
}
|
|
31
31
|
async function generateMetaJson(absoluteApiDir) {
|
|
32
|
-
const metaJsonPath =
|
|
33
|
-
const files = await
|
|
34
|
-
const filePaths = files.map((file)=>
|
|
35
|
-
const stats = await Promise.all(filePaths.map((fp)=>
|
|
32
|
+
const metaJsonPath = path.join(absoluteApiDir, '_meta.json');
|
|
33
|
+
const files = await promises.readdir(absoluteApiDir);
|
|
34
|
+
const filePaths = files.map((file)=>path.join(absoluteApiDir, file));
|
|
35
|
+
const stats = await Promise.all(filePaths.map((fp)=>promises.stat(fp)));
|
|
36
36
|
const dirs = stats.map((stat, index)=>stat.isDirectory() ? files[index] : null).filter(Boolean);
|
|
37
37
|
const meta = dirs.map((dir)=>({
|
|
38
38
|
type: 'dir',
|
|
39
39
|
label: dir.slice(0, 1).toUpperCase() + dir.slice(1),
|
|
40
40
|
name: dir
|
|
41
41
|
}));
|
|
42
|
-
await
|
|
42
|
+
await promises.writeFile(metaJsonPath, JSON.stringify([
|
|
43
43
|
'index',
|
|
44
44
|
...meta
|
|
45
45
|
]));
|
|
46
46
|
}
|
|
47
47
|
async function patchGeneratedApiDocs(absoluteApiDir) {
|
|
48
48
|
await patchLinks(absoluteApiDir);
|
|
49
|
-
await
|
|
49
|
+
await promises.rename(path.join(absoluteApiDir, 'README.md'), path.join(absoluteApiDir, 'index.md'));
|
|
50
50
|
await generateMetaJson(absoluteApiDir);
|
|
51
51
|
}
|
|
52
52
|
function pluginTypeDoc(options) {
|
|
53
53
|
let docRoot;
|
|
54
54
|
const { entryPoints = [], outDir = API_DIR } = options;
|
|
55
|
-
const apiPageRoute = `/${outDir.replace(/(^\/)|(\/$)/, '')}/`;
|
|
56
55
|
return {
|
|
57
56
|
name: '@rspress/plugin-typedoc',
|
|
58
|
-
async addPages () {
|
|
59
|
-
return [
|
|
60
|
-
{
|
|
61
|
-
routePath: apiPageRoute,
|
|
62
|
-
filepath: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(docRoot, outDir, 'README.md')
|
|
63
|
-
}
|
|
64
|
-
];
|
|
65
|
-
},
|
|
66
57
|
async config (config) {
|
|
67
|
-
const app = new
|
|
58
|
+
const app = new Application();
|
|
68
59
|
docRoot = config.root;
|
|
69
|
-
app.options.addReader(new
|
|
70
|
-
|
|
60
|
+
app.options.addReader(new TSConfigReader());
|
|
61
|
+
load(app);
|
|
71
62
|
app.bootstrap({
|
|
72
63
|
name: config.title,
|
|
73
64
|
entryPoints,
|
|
@@ -89,29 +80,9 @@ function pluginTypeDoc(options) {
|
|
|
89
80
|
});
|
|
90
81
|
const project = app.convert();
|
|
91
82
|
if (project) {
|
|
92
|
-
const absoluteApiDir =
|
|
83
|
+
const absoluteApiDir = path.join(docRoot, outDir);
|
|
93
84
|
await app.generateDocs(project, absoluteApiDir);
|
|
94
85
|
await patchGeneratedApiDocs(absoluteApiDir);
|
|
95
|
-
config.themeConfig = config.themeConfig || {};
|
|
96
|
-
config.themeConfig.nav = config.themeConfig.nav || [];
|
|
97
|
-
const { nav } = config.themeConfig;
|
|
98
|
-
function isApiAlreadyInNav(navList) {
|
|
99
|
-
return navList.some((item)=>{
|
|
100
|
-
if ('link' in item && 'string' == typeof item.link && item.link.startsWith(apiPageRoute.slice(0, apiPageRoute.length - 1))) return true;
|
|
101
|
-
return false;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (Array.isArray(nav)) {
|
|
105
|
-
if (!isApiAlreadyInNav(nav)) nav.push({
|
|
106
|
-
text: 'API',
|
|
107
|
-
link: apiPageRoute
|
|
108
|
-
});
|
|
109
|
-
} else if ('default' in nav) {
|
|
110
|
-
if (!isApiAlreadyInNav(nav.default)) nav.default.push({
|
|
111
|
-
text: 'API',
|
|
112
|
-
link: apiPageRoute
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
86
|
}
|
|
116
87
|
return config;
|
|
117
88
|
}
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-typedoc",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.31",
|
|
4
4
|
"description": "A plugin for rspress to integrate typedoc",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -29,29 +29,27 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"typedoc": "0.24.8",
|
|
32
|
-
"typedoc-plugin-markdown": "3.17.1"
|
|
33
|
-
"@rspress/shared": "2.0.0-beta.3"
|
|
32
|
+
"typedoc-plugin-markdown": "3.17.1"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@microsoft/api-extractor": "^7.52.
|
|
37
|
-
"@rslib/core": "0.
|
|
38
|
-
"@types/node": "^
|
|
39
|
-
"@types/react": "^
|
|
40
|
-
"@types/react-dom": "^
|
|
41
|
-
"react": "^19.1.
|
|
42
|
-
"rsbuild-plugin-publint": "^0.3.
|
|
35
|
+
"@microsoft/api-extractor": "^7.52.11",
|
|
36
|
+
"@rslib/core": "0.12.4",
|
|
37
|
+
"@types/node": "^22.8.1",
|
|
38
|
+
"@types/react": "^19.1.12",
|
|
39
|
+
"@types/react-dom": "^19.1.9",
|
|
40
|
+
"react": "^19.1.1",
|
|
41
|
+
"rsbuild-plugin-publint": "^0.3.3",
|
|
43
42
|
"typescript": "^5.8.2",
|
|
44
43
|
"@rspress/config": "1.0.0"
|
|
45
44
|
},
|
|
46
45
|
"peerDependencies": {
|
|
47
|
-
"rspress": "^2.0.0-beta.
|
|
46
|
+
"@rspress/core": "^2.0.0-beta.31"
|
|
48
47
|
},
|
|
49
48
|
"engines": {
|
|
50
49
|
"node": ">=18.0.0"
|
|
51
50
|
},
|
|
52
51
|
"publishConfig": {
|
|
53
52
|
"access": "public",
|
|
54
|
-
"provenance": true,
|
|
55
53
|
"registry": "https://registry.npmjs.org/"
|
|
56
54
|
},
|
|
57
55
|
"scripts": {
|