@rspress/plugin-typedoc 1.37.1 → 1.37.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.mjs +132 -0
- package/dist/lib/index.js +178 -275
- package/dist/types/index.d.ts +18 -17
- package/package.json +8 -6
- package/src/constants.ts +0 -1
- package/src/index.ts +39 -33
- package/src/patch.ts +72 -0
- package/dist/es/index.d.ts +0 -17
- package/dist/es/index.js +0 -253
- package/dist/es/index.js.map +0 -1
- package/dist/lib/index.d.ts +0 -17
- package/dist/lib/index.js.map +0 -1
- package/src/sidebar.ts +0 -179
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_typedoc__ from "typedoc";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_typedoc_plugin_markdown__ from "typedoc-plugin-markdown";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__ from "@rspress/shared/fs-extra";
|
|
5
|
+
const API_DIR = 'api';
|
|
6
|
+
async function patchLinks(outputDir) {
|
|
7
|
+
// Patch links in markdown files
|
|
8
|
+
// Scan all the markdown files in the output directory
|
|
9
|
+
// replace
|
|
10
|
+
// 1. [foo](bar) -> [foo](./bar)
|
|
11
|
+
// 2. [foo](./bar) -> [foo](./bar) no change
|
|
12
|
+
const normlizeLinksInFile = async (filePath)=>{
|
|
13
|
+
const content = await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].readFile(filePath, 'utf-8');
|
|
14
|
+
// 1. [foo](bar) -> [foo](./bar)
|
|
15
|
+
const newContent = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, p1, p2)=>{
|
|
16
|
+
// 2. [foo](./bar) -> [foo](./bar) no change
|
|
17
|
+
if ([
|
|
18
|
+
'/',
|
|
19
|
+
'.'
|
|
20
|
+
].includes(p2[0])) return `[${p1}](${p2})`;
|
|
21
|
+
return `[${p1}](./${p2})`;
|
|
22
|
+
});
|
|
23
|
+
await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].writeFile(filePath, newContent);
|
|
24
|
+
};
|
|
25
|
+
const traverse = async (dir)=>{
|
|
26
|
+
const files = await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].readdir(dir);
|
|
27
|
+
const filePaths = files.map((file)=>__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, file));
|
|
28
|
+
const stats = await Promise.all(filePaths.map((fp)=>__WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].stat(fp)));
|
|
29
|
+
await Promise.all(stats.map((stat, index)=>{
|
|
30
|
+
const file = files[index];
|
|
31
|
+
const filePath = filePaths[index];
|
|
32
|
+
if (stat.isDirectory()) return traverse(filePath);
|
|
33
|
+
if (stat.isFile() && /\.mdx?/.test(file)) return normlizeLinksInFile(filePath);
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
await traverse(outputDir);
|
|
37
|
+
}
|
|
38
|
+
async function generateMetaJson(absoluteApiDir) {
|
|
39
|
+
const metaJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(absoluteApiDir, '_meta.json');
|
|
40
|
+
const files = await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].readdir(absoluteApiDir);
|
|
41
|
+
const filePaths = files.map((file)=>__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(absoluteApiDir, file));
|
|
42
|
+
const stats = await Promise.all(filePaths.map((fp)=>__WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].stat(fp)));
|
|
43
|
+
const dirs = stats.map((stat, index)=>stat.isDirectory() ? files[index] : null).filter(Boolean);
|
|
44
|
+
const meta = dirs.map((dir)=>({
|
|
45
|
+
type: 'dir',
|
|
46
|
+
label: dir.slice(0, 1).toUpperCase() + dir.slice(1),
|
|
47
|
+
name: dir
|
|
48
|
+
}));
|
|
49
|
+
await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].writeFile(metaJsonPath, JSON.stringify([
|
|
50
|
+
'index',
|
|
51
|
+
...meta
|
|
52
|
+
]));
|
|
53
|
+
}
|
|
54
|
+
async function patchGeneratedApiDocs(absoluteApiDir) {
|
|
55
|
+
await patchLinks(absoluteApiDir);
|
|
56
|
+
await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].rename(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(absoluteApiDir, 'README.md'), __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(absoluteApiDir, 'index.md'));
|
|
57
|
+
await generateMetaJson(absoluteApiDir);
|
|
58
|
+
}
|
|
59
|
+
function pluginTypeDoc(options) {
|
|
60
|
+
let docRoot;
|
|
61
|
+
const { entryPoints = [], outDir = API_DIR } = options;
|
|
62
|
+
const apiPageRoute = `/${outDir.replace(/(^\/)|(\/$)/, '')}/`; // e.g: /api/
|
|
63
|
+
return {
|
|
64
|
+
name: '@rspress/plugin-typedoc',
|
|
65
|
+
async addPages () {
|
|
66
|
+
return [
|
|
67
|
+
{
|
|
68
|
+
routePath: apiPageRoute,
|
|
69
|
+
filepath: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(docRoot, outDir, 'README.md')
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
},
|
|
73
|
+
async config (config) {
|
|
74
|
+
const app = new __WEBPACK_EXTERNAL_MODULE_typedoc__.Application();
|
|
75
|
+
docRoot = config.root;
|
|
76
|
+
app.options.addReader(new __WEBPACK_EXTERNAL_MODULE_typedoc__.TSConfigReader());
|
|
77
|
+
(0, __WEBPACK_EXTERNAL_MODULE_typedoc_plugin_markdown__.load)(app);
|
|
78
|
+
app.bootstrap({
|
|
79
|
+
name: config.title,
|
|
80
|
+
entryPoints,
|
|
81
|
+
theme: 'markdown',
|
|
82
|
+
disableSources: true,
|
|
83
|
+
readme: 'none',
|
|
84
|
+
githubPages: false,
|
|
85
|
+
requiredToBeDocumented: [
|
|
86
|
+
'Class',
|
|
87
|
+
'Function',
|
|
88
|
+
'Interface'
|
|
89
|
+
],
|
|
90
|
+
plugin: [
|
|
91
|
+
'typedoc-plugin-markdown'
|
|
92
|
+
],
|
|
93
|
+
// @ts-expect-error MarkdownTheme has no export
|
|
94
|
+
hideBreadcrumbs: true,
|
|
95
|
+
hideMembersSymbol: true,
|
|
96
|
+
allReflectionsHaveOwnDocument: true
|
|
97
|
+
});
|
|
98
|
+
const project = app.convert();
|
|
99
|
+
if (project) {
|
|
100
|
+
// 1. Generate doc/api, doc/api/_meta.json by typedoc
|
|
101
|
+
const absoluteApiDir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(docRoot, outDir);
|
|
102
|
+
await app.generateDocs(project, absoluteApiDir);
|
|
103
|
+
await patchGeneratedApiDocs(absoluteApiDir);
|
|
104
|
+
// 2. Generate "api" nav bar
|
|
105
|
+
config.themeConfig = config.themeConfig || {};
|
|
106
|
+
config.themeConfig.nav = config.themeConfig.nav || [];
|
|
107
|
+
const { nav } = config.themeConfig;
|
|
108
|
+
// avoid that user config "api" in doc/_meta.json
|
|
109
|
+
function isApiAlreadyInNav(navList) {
|
|
110
|
+
return navList.some((item)=>{
|
|
111
|
+
if ('link' in item && 'string' == typeof item.link && item.link.startsWith(apiPageRoute.slice(0, apiPageRoute.length - 1))) return true;
|
|
112
|
+
return false;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// Note: TypeDoc does not support i18n
|
|
116
|
+
if (Array.isArray(nav)) {
|
|
117
|
+
if (!isApiAlreadyInNav(nav)) nav.push({
|
|
118
|
+
text: 'API',
|
|
119
|
+
link: apiPageRoute
|
|
120
|
+
});
|
|
121
|
+
} else if ('default' in nav) {
|
|
122
|
+
if (!isApiAlreadyInNav(nav.default)) nav.default.push({
|
|
123
|
+
text: 'API',
|
|
124
|
+
link: apiPageRoute
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return config;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export { pluginTypeDoc };
|
package/dist/lib/index.js
CHANGED
|
@@ -1,287 +1,190 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __async = (__this, __arguments, generator) => {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
var fulfilled = (value) => {
|
|
32
|
-
try {
|
|
33
|
-
step(generator.next(value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
2
|
+
// The require scope
|
|
3
|
+
var __webpack_require__ = {};
|
|
4
|
+
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
|
5
|
+
(()=>{
|
|
6
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
7
|
+
__webpack_require__.n = function(module) {
|
|
8
|
+
var getter = module && module.__esModule ? function() {
|
|
9
|
+
return module['default'];
|
|
10
|
+
} : function() {
|
|
11
|
+
return module;
|
|
12
|
+
};
|
|
13
|
+
__webpack_require__.d(getter, {
|
|
14
|
+
a: getter
|
|
15
|
+
});
|
|
16
|
+
return getter;
|
|
17
|
+
};
|
|
18
|
+
})();
|
|
19
|
+
// webpack/runtime/define_property_getters
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
22
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: definition[key]
|
|
25
|
+
});
|
|
37
26
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
})();
|
|
28
|
+
// webpack/runtime/has_own_property
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.o = function(obj, prop) {
|
|
31
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
// webpack/runtime/make_namespace_object
|
|
35
|
+
(()=>{
|
|
36
|
+
// define __esModule on exports
|
|
37
|
+
__webpack_require__.r = function(exports1) {
|
|
38
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
39
|
+
value: 'Module'
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
42
|
+
value: true
|
|
43
|
+
});
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
__export(src_exports, {
|
|
53
|
-
pluginTypeDoc: () => pluginTypeDoc
|
|
45
|
+
})();
|
|
46
|
+
/************************************************************************/ var __webpack_exports__ = {};
|
|
47
|
+
// ESM COMPAT FLAG
|
|
48
|
+
__webpack_require__.r(__webpack_exports__);
|
|
49
|
+
// EXPORTS
|
|
50
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
pluginTypeDoc: ()=>/* binding */ pluginTypeDoc
|
|
54
52
|
});
|
|
55
|
-
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} else if (stat.isFile() && /\.mdx?/.test(file)) {
|
|
94
|
-
yield normlizeLinksInFile(filePath);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
yield traverse(outputDir);
|
|
99
|
-
});
|
|
53
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
54
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
55
|
+
const external_typedoc_namespaceObject = require("typedoc");
|
|
56
|
+
const external_typedoc_plugin_markdown_namespaceObject = require("typedoc-plugin-markdown");
|
|
57
|
+
const API_DIR = 'api';
|
|
58
|
+
const fs_extra_namespaceObject = require("@rspress/shared/fs-extra");
|
|
59
|
+
var fs_extra_default = /*#__PURE__*/ __webpack_require__.n(fs_extra_namespaceObject);
|
|
60
|
+
async function patchLinks(outputDir) {
|
|
61
|
+
// Patch links in markdown files
|
|
62
|
+
// Scan all the markdown files in the output directory
|
|
63
|
+
// replace
|
|
64
|
+
// 1. [foo](bar) -> [foo](./bar)
|
|
65
|
+
// 2. [foo](./bar) -> [foo](./bar) no change
|
|
66
|
+
const normlizeLinksInFile = async (filePath)=>{
|
|
67
|
+
const content = await fs_extra_default().readFile(filePath, 'utf-8');
|
|
68
|
+
// 1. [foo](bar) -> [foo](./bar)
|
|
69
|
+
const newContent = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, p1, p2)=>{
|
|
70
|
+
// 2. [foo](./bar) -> [foo](./bar) no change
|
|
71
|
+
if ([
|
|
72
|
+
'/',
|
|
73
|
+
'.'
|
|
74
|
+
].includes(p2[0])) return `[${p1}](${p2})`;
|
|
75
|
+
return `[${p1}](./${p2})`;
|
|
76
|
+
});
|
|
77
|
+
await fs_extra_default().writeFile(filePath, newContent);
|
|
78
|
+
};
|
|
79
|
+
const traverse = async (dir)=>{
|
|
80
|
+
const files = await fs_extra_default().readdir(dir);
|
|
81
|
+
const filePaths = files.map((file)=>external_node_path_default().join(dir, file));
|
|
82
|
+
const stats = await Promise.all(filePaths.map((fp)=>fs_extra_default().stat(fp)));
|
|
83
|
+
await Promise.all(stats.map((stat, index)=>{
|
|
84
|
+
const file = files[index];
|
|
85
|
+
const filePath = filePaths[index];
|
|
86
|
+
if (stat.isDirectory()) return traverse(filePath);
|
|
87
|
+
if (stat.isFile() && /\.mdx?/.test(file)) return normlizeLinksInFile(filePath);
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
await traverse(outputDir);
|
|
100
91
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (dataItem) {
|
|
117
|
-
let fileName = dataItem.name;
|
|
118
|
-
if (symbolMap.has(dataItem.name)) {
|
|
119
|
-
const count = symbolMap.get(dataItem.name) + 1;
|
|
120
|
-
symbolMap.set(dataItem.name, count);
|
|
121
|
-
fileName = `${dataItem.name}-${count}`;
|
|
122
|
-
} else {
|
|
123
|
-
symbolMap.set(dataItem.name.toLocaleLowerCase(), 0);
|
|
124
|
-
}
|
|
125
|
-
groupItem.items.push({
|
|
126
|
-
text: dataItem.name,
|
|
127
|
-
link: `${ROUTE_PREFIX}/${group.title.toLocaleLowerCase()}/${fileName}`
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
result.push(groupItem);
|
|
132
|
-
});
|
|
133
|
-
yield patchLinks(import_node_path.default.dirname(jsonFile));
|
|
134
|
-
return result;
|
|
135
|
-
});
|
|
92
|
+
async function generateMetaJson(absoluteApiDir) {
|
|
93
|
+
const metaJsonPath = external_node_path_default().join(absoluteApiDir, '_meta.json');
|
|
94
|
+
const files = await fs_extra_default().readdir(absoluteApiDir);
|
|
95
|
+
const filePaths = files.map((file)=>external_node_path_default().join(absoluteApiDir, file));
|
|
96
|
+
const stats = await Promise.all(filePaths.map((fp)=>fs_extra_default().stat(fp)));
|
|
97
|
+
const dirs = stats.map((stat, index)=>stat.isDirectory() ? files[index] : null).filter(Boolean);
|
|
98
|
+
const meta = dirs.map((dir)=>({
|
|
99
|
+
type: 'dir',
|
|
100
|
+
label: dir.slice(0, 1).toUpperCase() + dir.slice(1),
|
|
101
|
+
name: dir
|
|
102
|
+
}));
|
|
103
|
+
await fs_extra_default().writeFile(metaJsonPath, JSON.stringify([
|
|
104
|
+
'index',
|
|
105
|
+
...meta
|
|
106
|
+
]));
|
|
136
107
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (!data.children || data.children.length <= 0) {
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
function getModulePath(name) {
|
|
145
|
-
return import_node_path.default.join(`${ROUTE_PREFIX}/modules`, `${transformModuleName(name)}`).replace(/\\/g, "/");
|
|
146
|
-
}
|
|
147
|
-
function getClassPath(moduleName, className) {
|
|
148
|
-
return import_node_path.default.join(
|
|
149
|
-
`${ROUTE_PREFIX}/classes`,
|
|
150
|
-
`${transformModuleName(moduleName)}.${className}`
|
|
151
|
-
).replace(/\\/g, "/");
|
|
152
|
-
}
|
|
153
|
-
function getInterfacePath(moduleName, interfaceName) {
|
|
154
|
-
return import_node_path.default.join(
|
|
155
|
-
`${ROUTE_PREFIX}/interfaces`,
|
|
156
|
-
`${transformModuleName(moduleName)}.${interfaceName}`
|
|
157
|
-
).replace(/\\/g, "/");
|
|
158
|
-
}
|
|
159
|
-
function getFunctionPath(moduleName, functionName) {
|
|
160
|
-
return import_node_path.default.join(
|
|
161
|
-
`${ROUTE_PREFIX}/functions`,
|
|
162
|
-
`${transformModuleName(moduleName)}.${functionName}`
|
|
163
|
-
).replace(/\\/g, "/");
|
|
164
|
-
}
|
|
165
|
-
data.children.forEach((module2) => {
|
|
166
|
-
const moduleNames = module2.name.split("/");
|
|
167
|
-
const name = moduleNames[moduleNames.length - 1];
|
|
168
|
-
const moduleConfig = {
|
|
169
|
-
text: `Module:${name}`,
|
|
170
|
-
items: [{ text: "Overview", link: getModulePath(module2.name) }]
|
|
171
|
-
};
|
|
172
|
-
if (!module2.children || module2.children.length <= 0) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
module2.children.forEach((sub) => {
|
|
176
|
-
var _a;
|
|
177
|
-
const kindString = (_a = module2.groups.find((item) => item.children.includes(sub.id))) == null ? void 0 : _a.title.slice(0, -1);
|
|
178
|
-
if (!kindString) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
switch (kindString) {
|
|
182
|
-
case "Class":
|
|
183
|
-
moduleConfig.items.push({
|
|
184
|
-
text: `Class:${sub.name}`,
|
|
185
|
-
link: getClassPath(module2.name, sub.name)
|
|
186
|
-
});
|
|
187
|
-
break;
|
|
188
|
-
case "Interface":
|
|
189
|
-
moduleConfig.items.push({
|
|
190
|
-
text: `Interface:${sub.name}`,
|
|
191
|
-
link: getInterfacePath(module2.name, sub.name)
|
|
192
|
-
});
|
|
193
|
-
break;
|
|
194
|
-
case "Function":
|
|
195
|
-
moduleConfig.items.push({
|
|
196
|
-
text: `Function:${sub.name}`,
|
|
197
|
-
link: getFunctionPath(module2.name, sub.name)
|
|
198
|
-
});
|
|
199
|
-
break;
|
|
200
|
-
default:
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
result.push(moduleConfig);
|
|
205
|
-
});
|
|
206
|
-
yield patchLinks(import_node_path.default.dirname(jsonFile));
|
|
207
|
-
return result;
|
|
208
|
-
});
|
|
108
|
+
async function patchGeneratedApiDocs(absoluteApiDir) {
|
|
109
|
+
await patchLinks(absoluteApiDir);
|
|
110
|
+
await fs_extra_default().rename(external_node_path_default().join(absoluteApiDir, 'README.md'), external_node_path_default().join(absoluteApiDir, 'index.md'));
|
|
111
|
+
await generateMetaJson(absoluteApiDir);
|
|
209
112
|
}
|
|
210
|
-
|
|
211
|
-
// src/index.ts
|
|
212
113
|
function pluginTypeDoc(options) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
yield app.generateDocs(project, absoluteOutputdir);
|
|
251
|
-
const jsonDir = import_node_path2.default.join(absoluteOutputdir, "documentation.json");
|
|
252
|
-
yield app.generateJson(project, jsonDir);
|
|
253
|
-
config.themeConfig = config.themeConfig || {};
|
|
254
|
-
config.themeConfig.nav = config.themeConfig.nav || [];
|
|
255
|
-
const apiIndexLink = `/${outDir.replace(/(^\/)|(\/$)/, "")}/`;
|
|
256
|
-
const { nav } = config.themeConfig;
|
|
257
|
-
if (Array.isArray(nav)) {
|
|
258
|
-
nav.push({
|
|
259
|
-
text: "API",
|
|
260
|
-
link: apiIndexLink
|
|
114
|
+
let docRoot;
|
|
115
|
+
const { entryPoints = [], outDir = API_DIR } = options;
|
|
116
|
+
const apiPageRoute = `/${outDir.replace(/(^\/)|(\/$)/, '')}/`; // e.g: /api/
|
|
117
|
+
return {
|
|
118
|
+
name: '@rspress/plugin-typedoc',
|
|
119
|
+
async addPages () {
|
|
120
|
+
return [
|
|
121
|
+
{
|
|
122
|
+
routePath: apiPageRoute,
|
|
123
|
+
filepath: external_node_path_default().join(docRoot, outDir, 'README.md')
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
},
|
|
127
|
+
async config (config) {
|
|
128
|
+
const app = new external_typedoc_namespaceObject.Application();
|
|
129
|
+
docRoot = config.root;
|
|
130
|
+
app.options.addReader(new external_typedoc_namespaceObject.TSConfigReader());
|
|
131
|
+
(0, external_typedoc_plugin_markdown_namespaceObject.load)(app);
|
|
132
|
+
app.bootstrap({
|
|
133
|
+
name: config.title,
|
|
134
|
+
entryPoints,
|
|
135
|
+
theme: 'markdown',
|
|
136
|
+
disableSources: true,
|
|
137
|
+
readme: 'none',
|
|
138
|
+
githubPages: false,
|
|
139
|
+
requiredToBeDocumented: [
|
|
140
|
+
'Class',
|
|
141
|
+
'Function',
|
|
142
|
+
'Interface'
|
|
143
|
+
],
|
|
144
|
+
plugin: [
|
|
145
|
+
'typedoc-plugin-markdown'
|
|
146
|
+
],
|
|
147
|
+
// @ts-expect-error MarkdownTheme has no export
|
|
148
|
+
hideBreadcrumbs: true,
|
|
149
|
+
hideMembersSymbol: true,
|
|
150
|
+
allReflectionsHaveOwnDocument: true
|
|
261
151
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
152
|
+
const project = app.convert();
|
|
153
|
+
if (project) {
|
|
154
|
+
// 1. Generate doc/api, doc/api/_meta.json by typedoc
|
|
155
|
+
const absoluteApiDir = external_node_path_default().join(docRoot, outDir);
|
|
156
|
+
await app.generateDocs(project, absoluteApiDir);
|
|
157
|
+
await patchGeneratedApiDocs(absoluteApiDir);
|
|
158
|
+
// 2. Generate "api" nav bar
|
|
159
|
+
config.themeConfig = config.themeConfig || {};
|
|
160
|
+
config.themeConfig.nav = config.themeConfig.nav || [];
|
|
161
|
+
const { nav } = config.themeConfig;
|
|
162
|
+
// avoid that user config "api" in doc/_meta.json
|
|
163
|
+
function isApiAlreadyInNav(navList) {
|
|
164
|
+
return navList.some((item)=>{
|
|
165
|
+
if ('link' in item && 'string' == typeof item.link && item.link.startsWith(apiPageRoute.slice(0, apiPageRoute.length - 1))) return true;
|
|
166
|
+
return false;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// Note: TypeDoc does not support i18n
|
|
170
|
+
if (Array.isArray(nav)) {
|
|
171
|
+
if (!isApiAlreadyInNav(nav)) nav.push({
|
|
172
|
+
text: 'API',
|
|
173
|
+
link: apiPageRoute
|
|
174
|
+
});
|
|
175
|
+
} else if ('default' in nav) {
|
|
176
|
+
if (!isApiAlreadyInNav(nav.default)) nav.default.push({
|
|
177
|
+
text: 'API',
|
|
178
|
+
link: apiPageRoute
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return config;
|
|
274
183
|
}
|
|
275
|
-
|
|
276
|
-
config.route.exclude = config.route.exclude || [];
|
|
277
|
-
return config;
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
};
|
|
184
|
+
};
|
|
281
185
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
186
|
+
var __webpack_export_target__ = exports;
|
|
187
|
+
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
|
|
188
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
189
|
+
value: true
|
|
285
190
|
});
|
|
286
|
-
|
|
287
|
-
//# sourceMappingURL=index.js.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { RspressPlugin } from '@rspress/shared';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import type { RspressPlugin } from '@rspress/shared';
|
|
2
|
+
|
|
3
|
+
export declare function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin;
|
|
4
|
+
|
|
5
|
+
export declare interface PluginTypeDocOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The entry points of modules.
|
|
8
|
+
* @default []
|
|
9
|
+
*/
|
|
10
|
+
entryPoints: string[];
|
|
11
|
+
/**
|
|
12
|
+
* The output directory.
|
|
13
|
+
* @default 'api'
|
|
14
|
+
*/
|
|
15
|
+
outDir?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { }
|