@rspress/plugin-typedoc 2.0.0-beta.9 → 2.0.0-rc.0
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 +136 -106
- package/dist/types/index.d.ts +1 -1
- package/package.json +9 -11
package/dist/es/index.js
CHANGED
|
@@ -1,119 +1,149 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
6
|
+
try {
|
|
7
|
+
var info = gen[key](arg);
|
|
8
|
+
var value = info.value;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
reject(error);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (info.done) resolve(value);
|
|
14
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
15
|
+
}
|
|
16
|
+
function _async_to_generator(fn) {
|
|
17
|
+
return function() {
|
|
18
|
+
var self = this, args = arguments;
|
|
19
|
+
return new Promise(function(resolve, reject) {
|
|
20
|
+
var gen = fn.apply(self, args);
|
|
21
|
+
function _next(value) {
|
|
22
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
23
|
+
}
|
|
24
|
+
function _throw(err) {
|
|
25
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
26
|
+
}
|
|
27
|
+
_next(void 0);
|
|
15
28
|
});
|
|
16
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(filePath, newContent);
|
|
17
|
-
};
|
|
18
|
-
const traverse = async (dir)=>{
|
|
19
|
-
const files = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(dir);
|
|
20
|
-
const filePaths = files.map((file)=>__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dir, file));
|
|
21
|
-
const stats = await Promise.all(filePaths.map((fp)=>__WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].stat(fp)));
|
|
22
|
-
await Promise.all(stats.map((stat, index)=>{
|
|
23
|
-
const file = files[index];
|
|
24
|
-
const filePath = filePaths[index];
|
|
25
|
-
if (stat.isDirectory()) return traverse(filePath);
|
|
26
|
-
if (stat.isFile() && /\.mdx?/.test(file)) return normalizeLinksInFile(filePath);
|
|
27
|
-
}));
|
|
28
29
|
};
|
|
29
|
-
await traverse(outputDir);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
function generateMetaJson(absoluteApiDir) {
|
|
59
|
+
return _async_to_generator(function*() {
|
|
60
|
+
const metaJsonPath = path.join(absoluteApiDir, '_meta.json');
|
|
61
|
+
const files = yield promises.readdir(absoluteApiDir);
|
|
62
|
+
const filePaths = files.map((file)=>path.join(absoluteApiDir, file));
|
|
63
|
+
const stats = yield Promise.all(filePaths.map((fp)=>promises.stat(fp)));
|
|
64
|
+
const dirs = stats.map((stat, index)=>stat.isDirectory() ? files[index] : null).filter(Boolean);
|
|
65
|
+
const meta = dirs.map((dir)=>({
|
|
66
|
+
type: 'dir',
|
|
67
|
+
label: dir.slice(0, 1).toUpperCase() + dir.slice(1),
|
|
68
|
+
name: dir
|
|
69
|
+
}));
|
|
70
|
+
yield promises.writeFile(metaJsonPath, JSON.stringify([
|
|
71
|
+
'index',
|
|
72
|
+
...meta
|
|
73
|
+
]));
|
|
74
|
+
})();
|
|
75
|
+
}
|
|
76
|
+
function patchGeneratedApiDocs(absoluteApiDir) {
|
|
77
|
+
return _async_to_generator(function*() {
|
|
78
|
+
yield patchLinks(absoluteApiDir);
|
|
79
|
+
yield promises.rename(path.join(absoluteApiDir, 'README.md'), path.join(absoluteApiDir, 'index.md'));
|
|
80
|
+
yield generateMetaJson(absoluteApiDir);
|
|
81
|
+
})();
|
|
82
|
+
}
|
|
83
|
+
function src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
84
|
+
try {
|
|
85
|
+
var info = gen[key](arg);
|
|
86
|
+
var value = info.value;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
reject(error);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (info.done) resolve(value);
|
|
92
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
46
93
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
94
|
+
function src_async_to_generator(fn) {
|
|
95
|
+
return function() {
|
|
96
|
+
var self = this, args = arguments;
|
|
97
|
+
return new Promise(function(resolve, reject) {
|
|
98
|
+
var gen = fn.apply(self, args);
|
|
99
|
+
function _next(value) {
|
|
100
|
+
src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
101
|
+
}
|
|
102
|
+
function _throw(err) {
|
|
103
|
+
src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
104
|
+
}
|
|
105
|
+
_next(void 0);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
51
108
|
}
|
|
52
109
|
function pluginTypeDoc(options) {
|
|
53
110
|
let docRoot;
|
|
54
|
-
const { entryPoints = [], outDir =
|
|
55
|
-
const apiPageRoute = `/${outDir.replace(/(^\/)|(\/$)/, '')}/`;
|
|
111
|
+
const { entryPoints = [], outDir = "api" } = options;
|
|
56
112
|
return {
|
|
57
113
|
name: '@rspress/plugin-typedoc',
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
114
|
+
config (config) {
|
|
115
|
+
return src_async_to_generator(function*() {
|
|
116
|
+
const app = new Application();
|
|
117
|
+
docRoot = config.root;
|
|
118
|
+
app.options.addReader(new TSConfigReader());
|
|
119
|
+
load(app);
|
|
120
|
+
app.bootstrap({
|
|
121
|
+
name: config.title,
|
|
122
|
+
entryPoints,
|
|
123
|
+
theme: 'markdown',
|
|
124
|
+
disableSources: true,
|
|
125
|
+
readme: 'none',
|
|
126
|
+
githubPages: false,
|
|
127
|
+
requiredToBeDocumented: [
|
|
128
|
+
'Class',
|
|
129
|
+
'Function',
|
|
130
|
+
'Interface'
|
|
131
|
+
],
|
|
132
|
+
plugin: [
|
|
133
|
+
'typedoc-plugin-markdown'
|
|
134
|
+
],
|
|
135
|
+
hideBreadcrumbs: true,
|
|
136
|
+
hideMembersSymbol: true,
|
|
137
|
+
allReflectionsHaveOwnDocument: true
|
|
138
|
+
});
|
|
139
|
+
const project = app.convert();
|
|
140
|
+
if (project) {
|
|
141
|
+
const absoluteApiDir = path.join(docRoot, outDir);
|
|
142
|
+
yield app.generateDocs(project, absoluteApiDir);
|
|
143
|
+
yield patchGeneratedApiDocs(absoluteApiDir);
|
|
63
144
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
async config (config) {
|
|
67
|
-
const app = new __WEBPACK_EXTERNAL_MODULE_typedoc__.Application();
|
|
68
|
-
docRoot = config.root;
|
|
69
|
-
app.options.addReader(new __WEBPACK_EXTERNAL_MODULE_typedoc__.TSConfigReader());
|
|
70
|
-
(0, __WEBPACK_EXTERNAL_MODULE_typedoc_plugin_markdown_836f15e3__.load)(app);
|
|
71
|
-
app.bootstrap({
|
|
72
|
-
name: config.title,
|
|
73
|
-
entryPoints,
|
|
74
|
-
theme: 'markdown',
|
|
75
|
-
disableSources: true,
|
|
76
|
-
readme: 'none',
|
|
77
|
-
githubPages: false,
|
|
78
|
-
requiredToBeDocumented: [
|
|
79
|
-
'Class',
|
|
80
|
-
'Function',
|
|
81
|
-
'Interface'
|
|
82
|
-
],
|
|
83
|
-
plugin: [
|
|
84
|
-
'typedoc-plugin-markdown'
|
|
85
|
-
],
|
|
86
|
-
hideBreadcrumbs: true,
|
|
87
|
-
hideMembersSymbol: true,
|
|
88
|
-
allReflectionsHaveOwnDocument: true
|
|
89
|
-
});
|
|
90
|
-
const project = app.convert();
|
|
91
|
-
if (project) {
|
|
92
|
-
const absoluteApiDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(docRoot, outDir);
|
|
93
|
-
await app.generateDocs(project, absoluteApiDir);
|
|
94
|
-
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
|
-
}
|
|
116
|
-
return config;
|
|
145
|
+
return config;
|
|
146
|
+
})();
|
|
117
147
|
}
|
|
118
148
|
};
|
|
119
149
|
}
|
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-
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
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.9"
|
|
32
|
+
"typedoc-plugin-markdown": "3.17.1"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@microsoft/api-extractor": "^7.
|
|
37
|
-
"@rslib/core": "0.
|
|
35
|
+
"@microsoft/api-extractor": "^7.54.0",
|
|
36
|
+
"@rslib/core": "0.16.1",
|
|
38
37
|
"@types/node": "^22.8.1",
|
|
39
|
-
"@types/react": "^
|
|
40
|
-
"@types/react-dom": "^
|
|
41
|
-
"react": "^19.
|
|
42
|
-
"rsbuild-plugin-publint": "^0.3.
|
|
38
|
+
"@types/react": "^19.2.2",
|
|
39
|
+
"@types/react-dom": "^19.2.2",
|
|
40
|
+
"react": "^19.2.0",
|
|
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-
|
|
46
|
+
"@rspress/core": "^2.0.0-rc.0"
|
|
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": {
|