@rspress/plugin-typedoc 0.0.0-nightly-20241124160321 → 0.0.0-nightly-20241125160247
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 +197 -0
- package/dist/lib/index.js +226 -258
- package/dist/types/index.d.ts +18 -17
- package/package.json +8 -6
- 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
|
@@ -0,0 +1,197 @@
|
|
|
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
|
+
const ROUTE_PREFIX = `/${API_DIR}`;
|
|
7
|
+
function transformModuleName(name) {
|
|
8
|
+
return name.replace(/\//g, '_').replace(/-/g, '_');
|
|
9
|
+
}
|
|
10
|
+
async function patchLinks(outputDir) {
|
|
11
|
+
// Patch links in markdown files
|
|
12
|
+
// Scan all the markdown files in the output directory
|
|
13
|
+
// replace [foo](bar) -> [foo](./bar)
|
|
14
|
+
const normlizeLinksInFile = async (filePath)=>{
|
|
15
|
+
const content = await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].readFile(filePath, 'utf-8');
|
|
16
|
+
// replace: [foo](bar) -> [foo](./bar)
|
|
17
|
+
const newContent = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, p1, p2)=>`[${p1}](./${p2})`);
|
|
18
|
+
await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].writeFile(filePath, newContent);
|
|
19
|
+
};
|
|
20
|
+
const traverse = async (dir)=>{
|
|
21
|
+
const files = await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].readdir(dir);
|
|
22
|
+
for (const file of files){
|
|
23
|
+
const filePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, file);
|
|
24
|
+
const stat = await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].stat(filePath);
|
|
25
|
+
if (stat.isDirectory()) await traverse(filePath);
|
|
26
|
+
else if (stat.isFile() && /\.mdx?/.test(file)) await normlizeLinksInFile(filePath);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
await traverse(outputDir);
|
|
30
|
+
}
|
|
31
|
+
async function resolveSidebarForSingleEntry(jsonFile) {
|
|
32
|
+
const result = [];
|
|
33
|
+
const data = JSON.parse(await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].readFile(jsonFile, 'utf-8'));
|
|
34
|
+
if (!data.children || data.children.length <= 0) return [];
|
|
35
|
+
const symbolMap = new Map();
|
|
36
|
+
data.groups.forEach((group)=>{
|
|
37
|
+
const groupItem = {
|
|
38
|
+
text: group.title,
|
|
39
|
+
items: []
|
|
40
|
+
};
|
|
41
|
+
group.children.forEach((id)=>{
|
|
42
|
+
const dataItem = data.children.find((item)=>item.id === id);
|
|
43
|
+
if (dataItem) {
|
|
44
|
+
// Note: we should handle the case that classes and interfaces have the same name
|
|
45
|
+
// Such as class `Env` and variable `env`
|
|
46
|
+
// The final output file name should be `classes/Env.md` and `variables/env-1.md`
|
|
47
|
+
let fileName = dataItem.name;
|
|
48
|
+
if (symbolMap.has(dataItem.name)) {
|
|
49
|
+
const count = symbolMap.get(dataItem.name) + 1;
|
|
50
|
+
symbolMap.set(dataItem.name, count);
|
|
51
|
+
fileName = `${dataItem.name}-${count}`;
|
|
52
|
+
} else symbolMap.set(dataItem.name.toLocaleLowerCase(), 0);
|
|
53
|
+
groupItem.items.push({
|
|
54
|
+
text: dataItem.name,
|
|
55
|
+
link: `${ROUTE_PREFIX}/${group.title.toLocaleLowerCase()}/${fileName}`
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
result.push(groupItem);
|
|
60
|
+
});
|
|
61
|
+
await patchLinks(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(jsonFile));
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
async function resolveSidebarForMultiEntry(jsonFile) {
|
|
65
|
+
const result = [];
|
|
66
|
+
const data = JSON.parse(await __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__["default"].readFile(jsonFile, 'utf-8'));
|
|
67
|
+
if (!data.children || data.children.length <= 0) return result;
|
|
68
|
+
function getModulePath(name) {
|
|
69
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(`${ROUTE_PREFIX}/modules`, `${transformModuleName(name)}`).replace(/\\/g, '/');
|
|
70
|
+
}
|
|
71
|
+
function getClassPath(moduleName, className) {
|
|
72
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(`${ROUTE_PREFIX}/classes`, `${transformModuleName(moduleName)}.${className}`).replace(/\\/g, '/');
|
|
73
|
+
}
|
|
74
|
+
function getInterfacePath(moduleName, interfaceName) {
|
|
75
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(`${ROUTE_PREFIX}/interfaces`, `${transformModuleName(moduleName)}.${interfaceName}`).replace(/\\/g, '/');
|
|
76
|
+
}
|
|
77
|
+
function getFunctionPath(moduleName, functionName) {
|
|
78
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(`${ROUTE_PREFIX}/functions`, `${transformModuleName(moduleName)}.${functionName}`).replace(/\\/g, '/');
|
|
79
|
+
}
|
|
80
|
+
data.children.forEach((module)=>{
|
|
81
|
+
const moduleNames = module.name.split('/');
|
|
82
|
+
const name = moduleNames[moduleNames.length - 1];
|
|
83
|
+
const moduleConfig = {
|
|
84
|
+
text: `Module:${name}`,
|
|
85
|
+
items: [
|
|
86
|
+
{
|
|
87
|
+
text: 'Overview',
|
|
88
|
+
link: getModulePath(module.name)
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
};
|
|
92
|
+
if (!module.children || module.children.length <= 0) return;
|
|
93
|
+
module.children.forEach((sub)=>{
|
|
94
|
+
var _module_groups_find;
|
|
95
|
+
const kindString = null === (_module_groups_find = module.groups.find((item)=>item.children.includes(sub.id))) || void 0 === _module_groups_find ? void 0 : _module_groups_find.title.slice(0, -1);
|
|
96
|
+
if (!kindString) return;
|
|
97
|
+
switch(kindString){
|
|
98
|
+
case 'Class':
|
|
99
|
+
moduleConfig.items.push({
|
|
100
|
+
text: `Class:${sub.name}`,
|
|
101
|
+
link: getClassPath(module.name, sub.name)
|
|
102
|
+
});
|
|
103
|
+
break;
|
|
104
|
+
case 'Interface':
|
|
105
|
+
moduleConfig.items.push({
|
|
106
|
+
text: `Interface:${sub.name}`,
|
|
107
|
+
link: getInterfacePath(module.name, sub.name)
|
|
108
|
+
});
|
|
109
|
+
break;
|
|
110
|
+
case 'Function':
|
|
111
|
+
moduleConfig.items.push({
|
|
112
|
+
text: `Function:${sub.name}`,
|
|
113
|
+
link: getFunctionPath(module.name, sub.name)
|
|
114
|
+
});
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
result.push(moduleConfig);
|
|
121
|
+
});
|
|
122
|
+
await patchLinks(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(jsonFile));
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
function pluginTypeDoc(options) {
|
|
126
|
+
let docRoot;
|
|
127
|
+
const { entryPoints = [], outDir = API_DIR } = options;
|
|
128
|
+
return {
|
|
129
|
+
name: '@rspress/plugin-typedoc',
|
|
130
|
+
async addPages () {
|
|
131
|
+
return [
|
|
132
|
+
{
|
|
133
|
+
routePath: `${outDir.replace(/\/$/, '')}/`,
|
|
134
|
+
filepath: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(docRoot, outDir, 'README.md')
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
},
|
|
138
|
+
async config (config) {
|
|
139
|
+
const app = new __WEBPACK_EXTERNAL_MODULE_typedoc__.Application();
|
|
140
|
+
docRoot = config.root;
|
|
141
|
+
app.options.addReader(new __WEBPACK_EXTERNAL_MODULE_typedoc__.TSConfigReader());
|
|
142
|
+
(0, __WEBPACK_EXTERNAL_MODULE_typedoc_plugin_markdown__.load)(app);
|
|
143
|
+
app.bootstrap({
|
|
144
|
+
name: config.title,
|
|
145
|
+
entryPoints,
|
|
146
|
+
theme: 'markdown',
|
|
147
|
+
disableSources: true,
|
|
148
|
+
readme: 'none',
|
|
149
|
+
githubPages: false,
|
|
150
|
+
requiredToBeDocumented: [
|
|
151
|
+
'Class',
|
|
152
|
+
'Function',
|
|
153
|
+
'Interface'
|
|
154
|
+
],
|
|
155
|
+
plugin: [
|
|
156
|
+
'typedoc-plugin-markdown'
|
|
157
|
+
],
|
|
158
|
+
// @ts-expect-error MarkdownTheme has no export
|
|
159
|
+
hideBreadcrumbs: true,
|
|
160
|
+
hideMembersSymbol: true,
|
|
161
|
+
allReflectionsHaveOwnDocument: true
|
|
162
|
+
});
|
|
163
|
+
const project = app.convert();
|
|
164
|
+
if (project) {
|
|
165
|
+
// 1. Generate module doc by typedoc
|
|
166
|
+
const absoluteOutputdir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(docRoot, outDir);
|
|
167
|
+
await app.generateDocs(project, absoluteOutputdir);
|
|
168
|
+
const jsonDir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(absoluteOutputdir, 'documentation.json');
|
|
169
|
+
await app.generateJson(project, jsonDir);
|
|
170
|
+
// 2. Generate sidebar
|
|
171
|
+
config.themeConfig = config.themeConfig || {};
|
|
172
|
+
config.themeConfig.nav = config.themeConfig.nav || [];
|
|
173
|
+
const apiIndexLink = `/${outDir.replace(/(^\/)|(\/$)/, '')}/`;
|
|
174
|
+
const { nav } = config.themeConfig;
|
|
175
|
+
// Note: TypeDoc does not support i18n
|
|
176
|
+
if (Array.isArray(nav)) nav.push({
|
|
177
|
+
text: 'API',
|
|
178
|
+
link: apiIndexLink
|
|
179
|
+
});
|
|
180
|
+
else if ('default' in nav) nav.default.push({
|
|
181
|
+
text: 'API',
|
|
182
|
+
link: apiIndexLink
|
|
183
|
+
});
|
|
184
|
+
config.themeConfig.sidebar = config.themeConfig.sidebar || {};
|
|
185
|
+
config.themeConfig.sidebar[apiIndexLink] = entryPoints.length > 1 ? await resolveSidebarForMultiEntry(jsonDir) : await resolveSidebarForSingleEntry(jsonDir);
|
|
186
|
+
config.themeConfig.sidebar[apiIndexLink].unshift({
|
|
187
|
+
text: 'Overview',
|
|
188
|
+
link: `${apiIndexLink}README`
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
config.route = config.route || {};
|
|
192
|
+
config.route.exclude = config.route.exclude || [];
|
|
193
|
+
return config;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export { pluginTypeDoc };
|
package/dist/lib/index.js
CHANGED
|
@@ -1,287 +1,255 @@
|
|
|
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);
|
|
44
32
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
};
|
|
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
|
-
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
// src/sidebar.ts
|
|
65
|
-
var import_node_path = __toESM(require("path"));
|
|
66
|
-
var import_fs_extra = __toESM(require("@rspress/shared/fs-extra"));
|
|
67
|
-
|
|
68
|
-
// src/utils.ts
|
|
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 ROUTE_PREFIX = `/${API_DIR}`;
|
|
59
|
+
const fs_extra_namespaceObject = require("@rspress/shared/fs-extra");
|
|
60
|
+
var fs_extra_default = /*#__PURE__*/ __webpack_require__.n(fs_extra_namespaceObject);
|
|
69
61
|
function transformModuleName(name) {
|
|
70
|
-
|
|
62
|
+
return name.replace(/\//g, '_').replace(/-/g, '_');
|
|
71
63
|
}
|
|
72
|
-
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const normlizeLinksInFile = (filePath)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/\[([^\]]+)\]\(([^)]+)\)/g,
|
|
80
|
-
(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const filePath = import_node_path.default.join(dir, file);
|
|
90
|
-
const stat = yield import_fs_extra.default.stat(filePath);
|
|
91
|
-
if (stat.isDirectory()) {
|
|
92
|
-
yield traverse(filePath);
|
|
93
|
-
} else if (stat.isFile() && /\.mdx?/.test(file)) {
|
|
94
|
-
yield normlizeLinksInFile(filePath);
|
|
64
|
+
async function patchLinks(outputDir) {
|
|
65
|
+
// Patch links in markdown files
|
|
66
|
+
// Scan all the markdown files in the output directory
|
|
67
|
+
// replace [foo](bar) -> [foo](./bar)
|
|
68
|
+
const normlizeLinksInFile = async (filePath)=>{
|
|
69
|
+
const content = await fs_extra_default().readFile(filePath, 'utf-8');
|
|
70
|
+
// replace: [foo](bar) -> [foo](./bar)
|
|
71
|
+
const newContent = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, p1, p2)=>`[${p1}](./${p2})`);
|
|
72
|
+
await fs_extra_default().writeFile(filePath, newContent);
|
|
73
|
+
};
|
|
74
|
+
const traverse = async (dir)=>{
|
|
75
|
+
const files = await fs_extra_default().readdir(dir);
|
|
76
|
+
for (const file of files){
|
|
77
|
+
const filePath = external_node_path_default().join(dir, file);
|
|
78
|
+
const stat = await fs_extra_default().stat(filePath);
|
|
79
|
+
if (stat.isDirectory()) await traverse(filePath);
|
|
80
|
+
else if (stat.isFile() && /\.mdx?/.test(file)) await normlizeLinksInFile(filePath);
|
|
95
81
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
yield traverse(outputDir);
|
|
99
|
-
});
|
|
82
|
+
};
|
|
83
|
+
await traverse(outputDir);
|
|
100
84
|
}
|
|
101
|
-
function resolveSidebarForSingleEntry(jsonFile) {
|
|
102
|
-
return __async(this, null, function* () {
|
|
85
|
+
async function resolveSidebarForSingleEntry(jsonFile) {
|
|
103
86
|
const result = [];
|
|
104
|
-
const data = JSON.parse(
|
|
105
|
-
if (!data.children || data.children.length <= 0)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
result.push(groupItem);
|
|
87
|
+
const data = JSON.parse(await fs_extra_default().readFile(jsonFile, 'utf-8'));
|
|
88
|
+
if (!data.children || data.children.length <= 0) return [];
|
|
89
|
+
const symbolMap = new Map();
|
|
90
|
+
data.groups.forEach((group)=>{
|
|
91
|
+
const groupItem = {
|
|
92
|
+
text: group.title,
|
|
93
|
+
items: []
|
|
94
|
+
};
|
|
95
|
+
group.children.forEach((id)=>{
|
|
96
|
+
const dataItem = data.children.find((item)=>item.id === id);
|
|
97
|
+
if (dataItem) {
|
|
98
|
+
// Note: we should handle the case that classes and interfaces have the same name
|
|
99
|
+
// Such as class `Env` and variable `env`
|
|
100
|
+
// The final output file name should be `classes/Env.md` and `variables/env-1.md`
|
|
101
|
+
let fileName = dataItem.name;
|
|
102
|
+
if (symbolMap.has(dataItem.name)) {
|
|
103
|
+
const count = symbolMap.get(dataItem.name) + 1;
|
|
104
|
+
symbolMap.set(dataItem.name, count);
|
|
105
|
+
fileName = `${dataItem.name}-${count}`;
|
|
106
|
+
} else symbolMap.set(dataItem.name.toLocaleLowerCase(), 0);
|
|
107
|
+
groupItem.items.push({
|
|
108
|
+
text: dataItem.name,
|
|
109
|
+
link: `${ROUTE_PREFIX}/${group.title.toLocaleLowerCase()}/${fileName}`
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
result.push(groupItem);
|
|
132
114
|
});
|
|
133
|
-
|
|
115
|
+
await patchLinks(external_node_path_default().dirname(jsonFile));
|
|
134
116
|
return result;
|
|
135
|
-
});
|
|
136
117
|
}
|
|
137
|
-
function resolveSidebarForMultiEntry(jsonFile) {
|
|
138
|
-
return __async(this, null, function* () {
|
|
118
|
+
async function resolveSidebarForMultiEntry(jsonFile) {
|
|
139
119
|
const result = [];
|
|
140
|
-
const data = JSON.parse(
|
|
141
|
-
if (!data.children || data.children.length <= 0)
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
120
|
+
const data = JSON.parse(await fs_extra_default().readFile(jsonFile, 'utf-8'));
|
|
121
|
+
if (!data.children || data.children.length <= 0) return result;
|
|
144
122
|
function getModulePath(name) {
|
|
145
|
-
|
|
123
|
+
return external_node_path_default().join(`${ROUTE_PREFIX}/modules`, `${transformModuleName(name)}`).replace(/\\/g, '/');
|
|
146
124
|
}
|
|
147
125
|
function getClassPath(moduleName, className) {
|
|
148
|
-
|
|
149
|
-
`${ROUTE_PREFIX}/classes`,
|
|
150
|
-
`${transformModuleName(moduleName)}.${className}`
|
|
151
|
-
).replace(/\\/g, "/");
|
|
126
|
+
return external_node_path_default().join(`${ROUTE_PREFIX}/classes`, `${transformModuleName(moduleName)}.${className}`).replace(/\\/g, '/');
|
|
152
127
|
}
|
|
153
128
|
function getInterfacePath(moduleName, interfaceName) {
|
|
154
|
-
|
|
155
|
-
`${ROUTE_PREFIX}/interfaces`,
|
|
156
|
-
`${transformModuleName(moduleName)}.${interfaceName}`
|
|
157
|
-
).replace(/\\/g, "/");
|
|
129
|
+
return external_node_path_default().join(`${ROUTE_PREFIX}/interfaces`, `${transformModuleName(moduleName)}.${interfaceName}`).replace(/\\/g, '/');
|
|
158
130
|
}
|
|
159
131
|
function getFunctionPath(moduleName, functionName) {
|
|
160
|
-
|
|
161
|
-
`${ROUTE_PREFIX}/functions`,
|
|
162
|
-
`${transformModuleName(moduleName)}.${functionName}`
|
|
163
|
-
).replace(/\\/g, "/");
|
|
132
|
+
return external_node_path_default().join(`${ROUTE_PREFIX}/functions`, `${transformModuleName(moduleName)}.${functionName}`).replace(/\\/g, '/');
|
|
164
133
|
}
|
|
165
|
-
data.children.forEach((
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
134
|
+
data.children.forEach((module)=>{
|
|
135
|
+
const moduleNames = module.name.split('/');
|
|
136
|
+
const name = moduleNames[moduleNames.length - 1];
|
|
137
|
+
const moduleConfig = {
|
|
138
|
+
text: `Module:${name}`,
|
|
139
|
+
items: [
|
|
140
|
+
{
|
|
141
|
+
text: 'Overview',
|
|
142
|
+
link: getModulePath(module.name)
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
};
|
|
146
|
+
if (!module.children || module.children.length <= 0) return;
|
|
147
|
+
module.children.forEach((sub)=>{
|
|
148
|
+
var _module_groups_find;
|
|
149
|
+
const kindString = null === (_module_groups_find = module.groups.find((item)=>item.children.includes(sub.id))) || void 0 === _module_groups_find ? void 0 : _module_groups_find.title.slice(0, -1);
|
|
150
|
+
if (!kindString) return;
|
|
151
|
+
switch(kindString){
|
|
152
|
+
case 'Class':
|
|
153
|
+
moduleConfig.items.push({
|
|
154
|
+
text: `Class:${sub.name}`,
|
|
155
|
+
link: getClassPath(module.name, sub.name)
|
|
156
|
+
});
|
|
157
|
+
break;
|
|
158
|
+
case 'Interface':
|
|
159
|
+
moduleConfig.items.push({
|
|
160
|
+
text: `Interface:${sub.name}`,
|
|
161
|
+
link: getInterfacePath(module.name, sub.name)
|
|
162
|
+
});
|
|
163
|
+
break;
|
|
164
|
+
case 'Function':
|
|
165
|
+
moduleConfig.items.push({
|
|
166
|
+
text: `Function:${sub.name}`,
|
|
167
|
+
link: getFunctionPath(module.name, sub.name)
|
|
168
|
+
});
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
result.push(moduleConfig);
|
|
205
175
|
});
|
|
206
|
-
|
|
176
|
+
await patchLinks(external_node_path_default().dirname(jsonFile));
|
|
207
177
|
return result;
|
|
208
|
-
});
|
|
209
178
|
}
|
|
210
|
-
|
|
211
|
-
// src/index.ts
|
|
212
179
|
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
|
-
const absoluteOutputdir = import_node_path2.default.join(docRoot, outDir);
|
|
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
|
|
180
|
+
let docRoot;
|
|
181
|
+
const { entryPoints = [], outDir = API_DIR } = options;
|
|
182
|
+
return {
|
|
183
|
+
name: '@rspress/plugin-typedoc',
|
|
184
|
+
async addPages () {
|
|
185
|
+
return [
|
|
186
|
+
{
|
|
187
|
+
routePath: `${outDir.replace(/\/$/, '')}/`,
|
|
188
|
+
filepath: external_node_path_default().join(docRoot, outDir, 'README.md')
|
|
189
|
+
}
|
|
190
|
+
];
|
|
191
|
+
},
|
|
192
|
+
async config (config) {
|
|
193
|
+
const app = new external_typedoc_namespaceObject.Application();
|
|
194
|
+
docRoot = config.root;
|
|
195
|
+
app.options.addReader(new external_typedoc_namespaceObject.TSConfigReader());
|
|
196
|
+
(0, external_typedoc_plugin_markdown_namespaceObject.load)(app);
|
|
197
|
+
app.bootstrap({
|
|
198
|
+
name: config.title,
|
|
199
|
+
entryPoints,
|
|
200
|
+
theme: 'markdown',
|
|
201
|
+
disableSources: true,
|
|
202
|
+
readme: 'none',
|
|
203
|
+
githubPages: false,
|
|
204
|
+
requiredToBeDocumented: [
|
|
205
|
+
'Class',
|
|
206
|
+
'Function',
|
|
207
|
+
'Interface'
|
|
208
|
+
],
|
|
209
|
+
plugin: [
|
|
210
|
+
'typedoc-plugin-markdown'
|
|
211
|
+
],
|
|
212
|
+
// @ts-expect-error MarkdownTheme has no export
|
|
213
|
+
hideBreadcrumbs: true,
|
|
214
|
+
hideMembersSymbol: true,
|
|
215
|
+
allReflectionsHaveOwnDocument: true
|
|
261
216
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
217
|
+
const project = app.convert();
|
|
218
|
+
if (project) {
|
|
219
|
+
// 1. Generate module doc by typedoc
|
|
220
|
+
const absoluteOutputdir = external_node_path_default().join(docRoot, outDir);
|
|
221
|
+
await app.generateDocs(project, absoluteOutputdir);
|
|
222
|
+
const jsonDir = external_node_path_default().join(absoluteOutputdir, 'documentation.json');
|
|
223
|
+
await app.generateJson(project, jsonDir);
|
|
224
|
+
// 2. Generate sidebar
|
|
225
|
+
config.themeConfig = config.themeConfig || {};
|
|
226
|
+
config.themeConfig.nav = config.themeConfig.nav || [];
|
|
227
|
+
const apiIndexLink = `/${outDir.replace(/(^\/)|(\/$)/, '')}/`;
|
|
228
|
+
const { nav } = config.themeConfig;
|
|
229
|
+
// Note: TypeDoc does not support i18n
|
|
230
|
+
if (Array.isArray(nav)) nav.push({
|
|
231
|
+
text: 'API',
|
|
232
|
+
link: apiIndexLink
|
|
233
|
+
});
|
|
234
|
+
else if ('default' in nav) nav.default.push({
|
|
235
|
+
text: 'API',
|
|
236
|
+
link: apiIndexLink
|
|
237
|
+
});
|
|
238
|
+
config.themeConfig.sidebar = config.themeConfig.sidebar || {};
|
|
239
|
+
config.themeConfig.sidebar[apiIndexLink] = entryPoints.length > 1 ? await resolveSidebarForMultiEntry(jsonDir) : await resolveSidebarForSingleEntry(jsonDir);
|
|
240
|
+
config.themeConfig.sidebar[apiIndexLink].unshift({
|
|
241
|
+
text: 'Overview',
|
|
242
|
+
link: `${apiIndexLink}README`
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
config.route = config.route || {};
|
|
246
|
+
config.route.exclude = config.route.exclude || [];
|
|
247
|
+
return config;
|
|
274
248
|
}
|
|
275
|
-
|
|
276
|
-
config.route.exclude = config.route.exclude || [];
|
|
277
|
-
return config;
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
};
|
|
249
|
+
};
|
|
281
250
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
251
|
+
var __webpack_export_target__ = exports;
|
|
252
|
+
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
|
|
253
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
254
|
+
value: true
|
|
285
255
|
});
|
|
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 { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-typedoc",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20241125160247",
|
|
4
4
|
"description": "A plugin for rspress to integrate typedoc",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"node": ">=14.17.6"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@modern-js/tsconfig": "2.62.
|
|
20
|
+
"@modern-js/tsconfig": "2.62.1",
|
|
21
|
+
"@rslib/core": "0.1.0",
|
|
22
|
+
"@microsoft/api-extractor": "^7.48.0",
|
|
21
23
|
"@types/node": "^18.11.17",
|
|
22
24
|
"@types/react": "^18.3.12",
|
|
23
25
|
"@types/react-dom": "^18.3.1",
|
|
@@ -26,7 +28,7 @@
|
|
|
26
28
|
"vitest": "2.1.5"
|
|
27
29
|
},
|
|
28
30
|
"peerDependencies": {
|
|
29
|
-
"rspress": "0.0.0-nightly-
|
|
31
|
+
"rspress": "0.0.0-nightly-20241125160247"
|
|
30
32
|
},
|
|
31
33
|
"sideEffects": [
|
|
32
34
|
"*.css",
|
|
@@ -46,11 +48,11 @@
|
|
|
46
48
|
"dependencies": {
|
|
47
49
|
"typedoc": "0.24.8",
|
|
48
50
|
"typedoc-plugin-markdown": "3.17.1",
|
|
49
|
-
"@rspress/shared": "0.0.0-nightly-
|
|
51
|
+
"@rspress/shared": "0.0.0-nightly-20241125160247"
|
|
50
52
|
},
|
|
51
53
|
"scripts": {
|
|
52
|
-
"dev": "
|
|
53
|
-
"build": "
|
|
54
|
+
"dev": "rslib build -w",
|
|
55
|
+
"build": "rslib build",
|
|
54
56
|
"reset": "rimraf ./**/node_modules",
|
|
55
57
|
"test": "vitest run --passWithNoTests"
|
|
56
58
|
}
|
package/dist/es/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RspressPlugin } from '@rspress/shared';
|
|
2
|
-
|
|
3
|
-
interface PluginTypeDocOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The entry points of modules.
|
|
6
|
-
* @default []
|
|
7
|
-
*/
|
|
8
|
-
entryPoints: string[];
|
|
9
|
-
/**
|
|
10
|
-
* The output directory.
|
|
11
|
-
* @default 'api'
|
|
12
|
-
*/
|
|
13
|
-
outDir?: string;
|
|
14
|
-
}
|
|
15
|
-
declare function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin;
|
|
16
|
-
|
|
17
|
-
export { type PluginTypeDocOptions, pluginTypeDoc };
|
package/dist/es/index.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/index.ts
|
|
23
|
-
import path2 from "path";
|
|
24
|
-
import { Application, TSConfigReader } from "typedoc";
|
|
25
|
-
import { load } from "typedoc-plugin-markdown";
|
|
26
|
-
|
|
27
|
-
// src/constants.ts
|
|
28
|
-
var API_DIR = "api";
|
|
29
|
-
var ROUTE_PREFIX = `/${API_DIR}`;
|
|
30
|
-
|
|
31
|
-
// src/sidebar.ts
|
|
32
|
-
import path from "path";
|
|
33
|
-
import fs from "@rspress/shared/fs-extra";
|
|
34
|
-
|
|
35
|
-
// src/utils.ts
|
|
36
|
-
function transformModuleName(name) {
|
|
37
|
-
return name.replace(/\//g, "_").replace(/-/g, "_");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/sidebar.ts
|
|
41
|
-
function patchLinks(outputDir) {
|
|
42
|
-
return __async(this, null, function* () {
|
|
43
|
-
const normlizeLinksInFile = (filePath) => __async(this, null, function* () {
|
|
44
|
-
const content = yield fs.readFile(filePath, "utf-8");
|
|
45
|
-
const newContent = content.replace(
|
|
46
|
-
/\[([^\]]+)\]\(([^)]+)\)/g,
|
|
47
|
-
(_match, p1, p2) => {
|
|
48
|
-
return `[${p1}](./${p2})`;
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
yield fs.writeFile(filePath, newContent);
|
|
52
|
-
});
|
|
53
|
-
const traverse = (dir) => __async(this, null, function* () {
|
|
54
|
-
const files = yield fs.readdir(dir);
|
|
55
|
-
for (const file of files) {
|
|
56
|
-
const filePath = path.join(dir, file);
|
|
57
|
-
const stat = yield fs.stat(filePath);
|
|
58
|
-
if (stat.isDirectory()) {
|
|
59
|
-
yield traverse(filePath);
|
|
60
|
-
} else if (stat.isFile() && /\.mdx?/.test(file)) {
|
|
61
|
-
yield normlizeLinksInFile(filePath);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
yield traverse(outputDir);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
function resolveSidebarForSingleEntry(jsonFile) {
|
|
69
|
-
return __async(this, null, function* () {
|
|
70
|
-
const result = [];
|
|
71
|
-
const data = JSON.parse(yield fs.readFile(jsonFile, "utf-8"));
|
|
72
|
-
if (!data.children || data.children.length <= 0) {
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
const symbolMap = /* @__PURE__ */ new Map();
|
|
76
|
-
data.groups.forEach((group) => {
|
|
77
|
-
const groupItem = {
|
|
78
|
-
text: group.title,
|
|
79
|
-
items: []
|
|
80
|
-
};
|
|
81
|
-
group.children.forEach((id) => {
|
|
82
|
-
const dataItem = data.children.find((item) => item.id === id);
|
|
83
|
-
if (dataItem) {
|
|
84
|
-
let fileName = dataItem.name;
|
|
85
|
-
if (symbolMap.has(dataItem.name)) {
|
|
86
|
-
const count = symbolMap.get(dataItem.name) + 1;
|
|
87
|
-
symbolMap.set(dataItem.name, count);
|
|
88
|
-
fileName = `${dataItem.name}-${count}`;
|
|
89
|
-
} else {
|
|
90
|
-
symbolMap.set(dataItem.name.toLocaleLowerCase(), 0);
|
|
91
|
-
}
|
|
92
|
-
groupItem.items.push({
|
|
93
|
-
text: dataItem.name,
|
|
94
|
-
link: `${ROUTE_PREFIX}/${group.title.toLocaleLowerCase()}/${fileName}`
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
result.push(groupItem);
|
|
99
|
-
});
|
|
100
|
-
yield patchLinks(path.dirname(jsonFile));
|
|
101
|
-
return result;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function resolveSidebarForMultiEntry(jsonFile) {
|
|
105
|
-
return __async(this, null, function* () {
|
|
106
|
-
const result = [];
|
|
107
|
-
const data = JSON.parse(yield fs.readFile(jsonFile, "utf-8"));
|
|
108
|
-
if (!data.children || data.children.length <= 0) {
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
function getModulePath(name) {
|
|
112
|
-
return path.join(`${ROUTE_PREFIX}/modules`, `${transformModuleName(name)}`).replace(/\\/g, "/");
|
|
113
|
-
}
|
|
114
|
-
function getClassPath(moduleName, className) {
|
|
115
|
-
return path.join(
|
|
116
|
-
`${ROUTE_PREFIX}/classes`,
|
|
117
|
-
`${transformModuleName(moduleName)}.${className}`
|
|
118
|
-
).replace(/\\/g, "/");
|
|
119
|
-
}
|
|
120
|
-
function getInterfacePath(moduleName, interfaceName) {
|
|
121
|
-
return path.join(
|
|
122
|
-
`${ROUTE_PREFIX}/interfaces`,
|
|
123
|
-
`${transformModuleName(moduleName)}.${interfaceName}`
|
|
124
|
-
).replace(/\\/g, "/");
|
|
125
|
-
}
|
|
126
|
-
function getFunctionPath(moduleName, functionName) {
|
|
127
|
-
return path.join(
|
|
128
|
-
`${ROUTE_PREFIX}/functions`,
|
|
129
|
-
`${transformModuleName(moduleName)}.${functionName}`
|
|
130
|
-
).replace(/\\/g, "/");
|
|
131
|
-
}
|
|
132
|
-
data.children.forEach((module) => {
|
|
133
|
-
const moduleNames = module.name.split("/");
|
|
134
|
-
const name = moduleNames[moduleNames.length - 1];
|
|
135
|
-
const moduleConfig = {
|
|
136
|
-
text: `Module:${name}`,
|
|
137
|
-
items: [{ text: "Overview", link: getModulePath(module.name) }]
|
|
138
|
-
};
|
|
139
|
-
if (!module.children || module.children.length <= 0) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
module.children.forEach((sub) => {
|
|
143
|
-
var _a;
|
|
144
|
-
const kindString = (_a = module.groups.find((item) => item.children.includes(sub.id))) == null ? void 0 : _a.title.slice(0, -1);
|
|
145
|
-
if (!kindString) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
switch (kindString) {
|
|
149
|
-
case "Class":
|
|
150
|
-
moduleConfig.items.push({
|
|
151
|
-
text: `Class:${sub.name}`,
|
|
152
|
-
link: getClassPath(module.name, sub.name)
|
|
153
|
-
});
|
|
154
|
-
break;
|
|
155
|
-
case "Interface":
|
|
156
|
-
moduleConfig.items.push({
|
|
157
|
-
text: `Interface:${sub.name}`,
|
|
158
|
-
link: getInterfacePath(module.name, sub.name)
|
|
159
|
-
});
|
|
160
|
-
break;
|
|
161
|
-
case "Function":
|
|
162
|
-
moduleConfig.items.push({
|
|
163
|
-
text: `Function:${sub.name}`,
|
|
164
|
-
link: getFunctionPath(module.name, sub.name)
|
|
165
|
-
});
|
|
166
|
-
break;
|
|
167
|
-
default:
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
result.push(moduleConfig);
|
|
172
|
-
});
|
|
173
|
-
yield patchLinks(path.dirname(jsonFile));
|
|
174
|
-
return result;
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/index.ts
|
|
179
|
-
function pluginTypeDoc(options) {
|
|
180
|
-
let docRoot;
|
|
181
|
-
const { entryPoints = [], outDir = API_DIR } = options;
|
|
182
|
-
return {
|
|
183
|
-
name: "@rspress/plugin-typedoc",
|
|
184
|
-
addPages() {
|
|
185
|
-
return __async(this, null, function* () {
|
|
186
|
-
return [
|
|
187
|
-
{
|
|
188
|
-
routePath: `${outDir.replace(/\/$/, "")}/`,
|
|
189
|
-
filepath: path2.join(docRoot, outDir, "README.md")
|
|
190
|
-
}
|
|
191
|
-
];
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
config(config) {
|
|
195
|
-
return __async(this, null, function* () {
|
|
196
|
-
const app = new Application();
|
|
197
|
-
docRoot = config.root;
|
|
198
|
-
app.options.addReader(new TSConfigReader());
|
|
199
|
-
load(app);
|
|
200
|
-
app.bootstrap({
|
|
201
|
-
name: config.title,
|
|
202
|
-
entryPoints,
|
|
203
|
-
theme: "markdown",
|
|
204
|
-
disableSources: true,
|
|
205
|
-
readme: "none",
|
|
206
|
-
githubPages: false,
|
|
207
|
-
requiredToBeDocumented: ["Class", "Function", "Interface"],
|
|
208
|
-
plugin: ["typedoc-plugin-markdown"],
|
|
209
|
-
// @ts-expect-error MarkdownTheme has no export
|
|
210
|
-
hideBreadcrumbs: true,
|
|
211
|
-
hideMembersSymbol: true,
|
|
212
|
-
allReflectionsHaveOwnDocument: true
|
|
213
|
-
});
|
|
214
|
-
const project = app.convert();
|
|
215
|
-
if (project) {
|
|
216
|
-
const absoluteOutputdir = path2.join(docRoot, outDir);
|
|
217
|
-
yield app.generateDocs(project, absoluteOutputdir);
|
|
218
|
-
const jsonDir = path2.join(absoluteOutputdir, "documentation.json");
|
|
219
|
-
yield app.generateJson(project, jsonDir);
|
|
220
|
-
config.themeConfig = config.themeConfig || {};
|
|
221
|
-
config.themeConfig.nav = config.themeConfig.nav || [];
|
|
222
|
-
const apiIndexLink = `/${outDir.replace(/(^\/)|(\/$)/, "")}/`;
|
|
223
|
-
const { nav } = config.themeConfig;
|
|
224
|
-
if (Array.isArray(nav)) {
|
|
225
|
-
nav.push({
|
|
226
|
-
text: "API",
|
|
227
|
-
link: apiIndexLink
|
|
228
|
-
});
|
|
229
|
-
} else if ("default" in nav) {
|
|
230
|
-
nav.default.push({
|
|
231
|
-
text: "API",
|
|
232
|
-
link: apiIndexLink
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
config.themeConfig.sidebar = config.themeConfig.sidebar || {};
|
|
236
|
-
config.themeConfig.sidebar[apiIndexLink] = entryPoints.length > 1 ? yield resolveSidebarForMultiEntry(jsonDir) : yield resolveSidebarForSingleEntry(jsonDir);
|
|
237
|
-
config.themeConfig.sidebar[apiIndexLink].unshift({
|
|
238
|
-
text: "Overview",
|
|
239
|
-
link: `${apiIndexLink}README`
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
config.route = config.route || {};
|
|
243
|
-
config.route.exclude = config.route.exclude || [];
|
|
244
|
-
return config;
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
export {
|
|
250
|
-
pluginTypeDoc
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,WAAU;AACjB,SAAS,aAAa,sBAAsB;AAE5C,SAAS,YAAY;;;ACHd,IAAM,UAAU;AAChB,IAAM,eAAe,IAAI,OAAO;;;ACDvC,OAAO,UAAU;AACjB,OAAO,QAAQ;;;ACDR,SAAS,oBAAoB,MAAc;AAChD,SAAO,KAAK,QAAQ,OAAO,GAAG,EAAE,QAAQ,MAAM,GAAG;AACnD;;;ADiBA,SAAe,WAAW,WAAmB;AAAA;AAI3C,UAAM,sBAAsB,CAAO,aAAqB;AACtD,YAAM,UAAU,MAAM,GAAG,SAAS,UAAU,OAAO;AAEnD,YAAM,aAA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AC3B,gBAAI,QAAQ,KAAK;AAAA,cACf,MAAM;AAAA,cACN,MAAM;AAAA,YACR,CAAC;AAAA,UACH;AAEA,iBAAO,YAAY,UAAU,OAAO,YAAY,WAAW,CAAC;AAC5D,iBAAO,YAAY,QAAQ,YAAY,IACrC,YAAY,SAAS,IACjB,MAAM,4BAA4B,OAAO,IACzC,MAAM,6BAA6B,OAAO;AAChD,iBAAO,YAAY,QAAQ,YAAY,EAAE,QAAQ;AAAA,YAC/C,MAAM;AAAA,YACN,MAAM,GAAG,YAAY;AAAA,UACvB,CAAC;AAAA,QACH;AACA,eAAO,QAAQ,OAAO,SAAS,CAAC;AAChC,eAAO,MAAM,UAAU,OAAO,MAAM,WAAW,CAAC;AAChD,eAAO;AAAA,MACT;AAAA;AAAA,EACF;AACF","names":["path"],"ignoreList":[],"sources":["../../src/index.ts","../../src/constants.ts","../../src/sidebar.ts","../../src/utils.ts"],"sourcesContent":["import path from 'node:path';\nimport { Application, TSConfigReader } from 'typedoc';\nimport type { RspressPlugin } from '@rspress/shared';\nimport { load } from 'typedoc-plugin-markdown';\nimport { API_DIR } from './constants';\nimport {\n resolveSidebarForMultiEntry,\n resolveSidebarForSingleEntry,\n} from './sidebar';\n\nexport interface PluginTypeDocOptions {\n /**\n * The entry points of modules.\n * @default []\n */\n entryPoints: string[];\n /**\n * The output directory.\n * @default 'api'\n */\n outDir?: string;\n}\n\nexport function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin {\n let docRoot: string | undefined;\n const { entryPoints = [], outDir = API_DIR } = options;\n return {\n name: '@rspress/plugin-typedoc',\n async addPages() {\n return [\n {\n routePath: `${outDir.replace(/\\/$/, '')}/`,\n filepath: path.join(docRoot!, outDir, 'README.md'),\n },\n ];\n },\n async config(config) {\n const app = new Application();\n docRoot = config.root;\n app.options.addReader(new TSConfigReader());\n load(app);\n app.bootstrap({\n name: config.title,\n entryPoints,\n theme: 'markdown',\n disableSources: true,\n readme: 'none',\n githubPages: false,\n requiredToBeDocumented: ['Class', 'Function', 'Interface'],\n plugin: ['typedoc-plugin-markdown'],\n // @ts-expect-error MarkdownTheme has no export\n hideBreadcrumbs: true,\n hideMembersSymbol: true,\n allReflectionsHaveOwnDocument: true,\n });\n const project = app.convert();\n\n if (project) {\n // 1. Generate module doc by typedoc\n const absoluteOutputdir = path.join(docRoot!, outDir);\n await app.generateDocs(project, absoluteOutputdir);\n const jsonDir = path.join(absoluteOutputdir, 'documentation.json');\n await app.generateJson(project, jsonDir);\n // 2. Generate sidebar\n config.themeConfig = config.themeConfig || {};\n config.themeConfig.nav = config.themeConfig.nav || [];\n const apiIndexLink = `/${outDir.replace(/(^\\/)|(\\/$)/, '')}/`;\n const { nav } = config.themeConfig;\n // Note: TypeDoc does not support i18n\n if (Array.isArray(nav)) {\n nav.push({\n text: 'API',\n link: apiIndexLink,\n });\n } else if ('default' in nav) {\n nav.default.push({\n text: 'API',\n link: apiIndexLink,\n });\n }\n\n config.themeConfig.sidebar = config.themeConfig.sidebar || {};\n config.themeConfig.sidebar[apiIndexLink] =\n entryPoints.length > 1\n ? await resolveSidebarForMultiEntry(jsonDir)\n : await resolveSidebarForSingleEntry(jsonDir);\n config.themeConfig.sidebar[apiIndexLink].unshift({\n text: 'Overview',\n link: `${apiIndexLink}README`,\n });\n }\n config.route = config.route || {};\n config.route.exclude = config.route.exclude || [];\n return config;\n },\n };\n}\n","export const API_DIR = 'api';\nexport const ROUTE_PREFIX = `/${API_DIR}`;\n","import path from 'node:path';\nimport fs from '@rspress/shared/fs-extra';\nimport type { SidebarGroup } from '@rspress/shared';\nimport { transformModuleName } from './utils';\nimport { ROUTE_PREFIX } from './constants';\n\ninterface ModuleItem {\n id: number;\n name: string;\n children: {\n id: number;\n name: string;\n }[];\n groups: {\n title: string;\n children: number[];\n }[];\n}\n\nasync function patchLinks(outputDir: string) {\n // Patch links in markdown files\n // Scan all the markdown files in the output directory\n // replace [foo](bar) -> [foo](./bar)\n const normlizeLinksInFile = async (filePath: string) => {\n const content = await fs.readFile(filePath, 'utf-8');\n // replace: [foo](bar) -> [foo](./bar)\n const newContent = content.replace(\n /\\[([^\\]]+)\\]\\(([^)]+)\\)/g,\n (_match, p1, p2) => {\n return `[${p1}](./${p2})`;\n },\n );\n await fs.writeFile(filePath, newContent);\n };\n\n const traverse = async (dir: string) => {\n const files = await fs.readdir(dir);\n for (const file of files) {\n const filePath = path.join(dir, file);\n const stat = await fs.stat(filePath);\n if (stat.isDirectory()) {\n await traverse(filePath);\n } else if (stat.isFile() && /\\.mdx?/.test(file)) {\n await normlizeLinksInFile(filePath);\n }\n }\n };\n await traverse(outputDir);\n}\n\nexport async function resolveSidebarForSingleEntry(\n jsonFile: string,\n): Promise<SidebarGroup[]> {\n const result: SidebarGroup[] = [];\n const data = JSON.parse(await fs.readFile(jsonFile, 'utf-8'));\n if (!data.children || data.children.length <= 0) {\n return [];\n }\n const symbolMap = new Map<string, number>();\n data.groups.forEach((group: { title: string; children: number[] }) => {\n const groupItem: SidebarGroup = {\n text: group.title,\n items: [],\n };\n group.children.forEach((id: number) => {\n const dataItem = data.children.find((item: ModuleItem) => item.id === id);\n if (dataItem) {\n // Note: we should handle the case that classes and interfaces have the same name\n // Such as class `Env` and variable `env`\n // The final output file name should be `classes/Env.md` and `variables/env-1.md`\n let fileName = dataItem.name;\n if (symbolMap.has(dataItem.name)) {\n const count = symbolMap.get(dataItem.name)! + 1;\n symbolMap.set(dataItem.name, count);\n fileName = `${dataItem.name}-${count}`;\n } else {\n symbolMap.set(dataItem.name.toLocaleLowerCase(), 0);\n }\n groupItem.items.push({\n text: dataItem.name,\n link: `${ROUTE_PREFIX}/${group.title.toLocaleLowerCase()}/${fileName}`,\n });\n }\n });\n result.push(groupItem);\n });\n\n await patchLinks(path.dirname(jsonFile));\n\n return result;\n}\n\nexport async function resolveSidebarForMultiEntry(\n jsonFile: string,\n): Promise<SidebarGroup[]> {\n const result: SidebarGroup[] = [];\n const data = JSON.parse(await fs.readFile(jsonFile, 'utf-8'));\n if (!data.children || data.children.length <= 0) {\n return result;\n }\n\n function getModulePath(name: string) {\n return path\n .join(`${ROUTE_PREFIX}/modules`, `${transformModuleName(name)}`)\n .replace(/\\\\/g, '/');\n }\n\n function getClassPath(moduleName: string, className: string) {\n return path\n .join(\n `${ROUTE_PREFIX}/classes`,\n `${transformModuleName(moduleName)}.${className}`,\n )\n .replace(/\\\\/g, '/');\n }\n\n function getInterfacePath(moduleName: string, interfaceName: string) {\n return path\n .join(\n `${ROUTE_PREFIX}/interfaces`,\n `${transformModuleName(moduleName)}.${interfaceName}`,\n )\n .replace(/\\\\/g, '/');\n }\n\n function getFunctionPath(moduleName: string, functionName: string) {\n return path\n .join(\n `${ROUTE_PREFIX}/functions`,\n `${transformModuleName(moduleName)}.${functionName}`,\n )\n .replace(/\\\\/g, '/');\n }\n\n data.children.forEach((module: ModuleItem) => {\n const moduleNames = module.name.split('/');\n const name = moduleNames[moduleNames.length - 1];\n const moduleConfig = {\n text: `Module:${name}`,\n items: [{ text: 'Overview', link: getModulePath(module.name) }],\n };\n if (!module.children || module.children.length <= 0) {\n return;\n }\n module.children.forEach(sub => {\n const kindString = module.groups\n .find(item => item.children.includes(sub.id))\n ?.title.slice(0, -1);\n if (!kindString) {\n return;\n }\n switch (kindString) {\n case 'Class':\n moduleConfig.items.push({\n text: `Class:${sub.name}`,\n link: getClassPath(module.name, sub.name),\n });\n break;\n case 'Interface':\n moduleConfig.items.push({\n text: `Interface:${sub.name}`,\n link: getInterfacePath(module.name, sub.name),\n });\n break;\n case 'Function':\n moduleConfig.items.push({\n text: `Function:${sub.name}`,\n link: getFunctionPath(module.name, sub.name),\n });\n break;\n default:\n break;\n }\n });\n result.push(moduleConfig);\n });\n await patchLinks(path.dirname(jsonFile));\n return result;\n}\n","export function transformModuleName(name: string) {\n return name.replace(/\\//g, '_').replace(/-/g, '_');\n}\n"]}
|
package/dist/lib/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RspressPlugin } from '@rspress/shared';
|
|
2
|
-
|
|
3
|
-
interface PluginTypeDocOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The entry points of modules.
|
|
6
|
-
* @default []
|
|
7
|
-
*/
|
|
8
|
-
entryPoints: string[];
|
|
9
|
-
/**
|
|
10
|
-
* The output directory.
|
|
11
|
-
* @default 'api'
|
|
12
|
-
*/
|
|
13
|
-
outDir?: string;
|
|
14
|
-
}
|
|
15
|
-
declare function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin;
|
|
16
|
-
|
|
17
|
-
export { type PluginTypeDocOptions, pluginTypeDoc };
|
package/dist/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,oBAAiB;AACjB,qBAA4C;AAE5C,qCAAqB;;;ACHd,IAAM,UAAU;AAChB,IAAM,eAAe,IAAI,OAAO;;;ACDvC,uBAAiB;AACjB,sBAAe;;;ACDR,SAAS,oBAAoB,MAAc;AAChD,SAAO,KAAK,QAAQ,OAAO,GAAG,EAAE,QAAQ,MAAM,GAAG;AACnD;;;ADiBA,SAAe,WAAW,WAAmB;AAAA;AAI3C,UAAM,sBAAsB,CAAO,aAAqB;AACtD,YAAM,UAAU,MAAM,gBAAAC,QAAG,SAAS,UAAU,OAAO;AAEnD,YAAM,aAAa,QAAQ;AAAA,QACzB;AAAA,QACA,CAAC,QAAQ,IAAI,OAAO;AAClB,iBAAO,IAAI,EAAE,OAAO,EAAE;AAAA,QACxB;AAAA,MACF;AACA,YAAM,gBAAAA,QAAG,UAAU,UAAU,UAAU;AAAA,IACzC;AAEA,UAAM,WAAW,CAAO,QAAgB;AACtC,YAAM,QAAQ,MAAM,gBAAAA,QAAG,QAAQ,GAAG;AAClC,iBAAW,QAAQ,OAAO;AACxB,cAAM,WAAW,iBAAAC,QAAK,KAAK,KAAK,I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,SAAS,IACjB,MAAM,4BAA4B,OAAO,IACzC,MAAM,6BAA6B,OAAO;AAChD,iBAAO,YAAY,QAAQ,YAAY,EAAE,QAAQ;AAAA,YAC/C,MAAM;AAAA,YACN,MAAM,GAAG,YAAY;AAAA,UACvB,CAAC;AAAA,QACH;AACA,eAAO,QAAQ,OAAO,SAAS,CAAC;AAChC,eAAO,MAAM,UAAU,OAAO,MAAM,WAAW,CAAC;AAChD,eAAO;AAAA,MACT;AAAA;AAAA,EACF;AACF","names":["import_node_path","fs","path","module"],"ignoreList":[],"sources":["../../src/index.ts","../../src/constants.ts","../../src/sidebar.ts","../../src/utils.ts"],"sourcesContent":["import path from 'node:path';\nimport { Application, TSConfigReader } from 'typedoc';\nimport type { RspressPlugin } from '@rspress/shared';\nimport { load } from 'typedoc-plugin-markdown';\nimport { API_DIR } from './constants';\nimport {\n resolveSidebarForMultiEntry,\n resolveSidebarForSingleEntry,\n} from './sidebar';\n\nexport interface PluginTypeDocOptions {\n /**\n * The entry points of modules.\n * @default []\n */\n entryPoints: string[];\n /**\n * The output directory.\n * @default 'api'\n */\n outDir?: string;\n}\n\nexport function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin {\n let docRoot: string | undefined;\n const { entryPoints = [], outDir = API_DIR } = options;\n return {\n name: '@rspress/plugin-typedoc',\n async addPages() {\n return [\n {\n routePath: `${outDir.replace(/\\/$/, '')}/`,\n filepath: path.join(docRoot!, outDir, 'README.md'),\n },\n ];\n },\n async config(config) {\n const app = new Application();\n docRoot = config.root;\n app.options.addReader(new TSConfigReader());\n load(app);\n app.bootstrap({\n name: config.title,\n entryPoints,\n theme: 'markdown',\n disableSources: true,\n readme: 'none',\n githubPages: false,\n requiredToBeDocumented: ['Class', 'Function', 'Interface'],\n plugin: ['typedoc-plugin-markdown'],\n // @ts-expect-error MarkdownTheme has no export\n hideBreadcrumbs: true,\n hideMembersSymbol: true,\n allReflectionsHaveOwnDocument: true,\n });\n const project = app.convert();\n\n if (project) {\n // 1. Generate module doc by typedoc\n const absoluteOutputdir = path.join(docRoot!, outDir);\n await app.generateDocs(project, absoluteOutputdir);\n const jsonDir = path.join(absoluteOutputdir, 'documentation.json');\n await app.generateJson(project, jsonDir);\n // 2. Generate sidebar\n config.themeConfig = config.themeConfig || {};\n config.themeConfig.nav = config.themeConfig.nav || [];\n const apiIndexLink = `/${outDir.replace(/(^\\/)|(\\/$)/, '')}/`;\n const { nav } = config.themeConfig;\n // Note: TypeDoc does not support i18n\n if (Array.isArray(nav)) {\n nav.push({\n text: 'API',\n link: apiIndexLink,\n });\n } else if ('default' in nav) {\n nav.default.push({\n text: 'API',\n link: apiIndexLink,\n });\n }\n\n config.themeConfig.sidebar = config.themeConfig.sidebar || {};\n config.themeConfig.sidebar[apiIndexLink] =\n entryPoints.length > 1\n ? await resolveSidebarForMultiEntry(jsonDir)\n : await resolveSidebarForSingleEntry(jsonDir);\n config.themeConfig.sidebar[apiIndexLink].unshift({\n text: 'Overview',\n link: `${apiIndexLink}README`,\n });\n }\n config.route = config.route || {};\n config.route.exclude = config.route.exclude || [];\n return config;\n },\n };\n}\n","export const API_DIR = 'api';\nexport const ROUTE_PREFIX = `/${API_DIR}`;\n","import path from 'node:path';\nimport fs from '@rspress/shared/fs-extra';\nimport type { SidebarGroup } from '@rspress/shared';\nimport { transformModuleName } from './utils';\nimport { ROUTE_PREFIX } from './constants';\n\ninterface ModuleItem {\n id: number;\n name: string;\n children: {\n id: number;\n name: string;\n }[];\n groups: {\n title: string;\n children: number[];\n }[];\n}\n\nasync function patchLinks(outputDir: string) {\n // Patch links in markdown files\n // Scan all the markdown files in the output directory\n // replace [foo](bar) -> [foo](./bar)\n const normlizeLinksInFile = async (filePath: string) => {\n const content = await fs.readFile(filePath, 'utf-8');\n // replace: [foo](bar) -> [foo](./bar)\n const newContent = content.replace(\n /\\[([^\\]]+)\\]\\(([^)]+)\\)/g,\n (_match, p1, p2) => {\n return `[${p1}](./${p2})`;\n },\n );\n await fs.writeFile(filePath, newContent);\n };\n\n const traverse = async (dir: string) => {\n const files = await fs.readdir(dir);\n for (const file of files) {\n const filePath = path.join(dir, file);\n const stat = await fs.stat(filePath);\n if (stat.isDirectory()) {\n await traverse(filePath);\n } else if (stat.isFile() && /\\.mdx?/.test(file)) {\n await normlizeLinksInFile(filePath);\n }\n }\n };\n await traverse(outputDir);\n}\n\nexport async function resolveSidebarForSingleEntry(\n jsonFile: string,\n): Promise<SidebarGroup[]> {\n const result: SidebarGroup[] = [];\n const data = JSON.parse(await fs.readFile(jsonFile, 'utf-8'));\n if (!data.children || data.children.length <= 0) {\n return [];\n }\n const symbolMap = new Map<string, number>();\n data.groups.forEach((group: { title: string; children: number[] }) => {\n const groupItem: SidebarGroup = {\n text: group.title,\n items: [],\n };\n group.children.forEach((id: number) => {\n const dataItem = data.children.find((item: ModuleItem) => item.id === id);\n if (dataItem) {\n // Note: we should handle the case that classes and interfaces have the same name\n // Such as class `Env` and variable `env`\n // The final output file name should be `classes/Env.md` and `variables/env-1.md`\n let fileName = dataItem.name;\n if (symbolMap.has(dataItem.name)) {\n const count = symbolMap.get(dataItem.name)! + 1;\n symbolMap.set(dataItem.name, count);\n fileName = `${dataItem.name}-${count}`;\n } else {\n symbolMap.set(dataItem.name.toLocaleLowerCase(), 0);\n }\n groupItem.items.push({\n text: dataItem.name,\n link: `${ROUTE_PREFIX}/${group.title.toLocaleLowerCase()}/${fileName}`,\n });\n }\n });\n result.push(groupItem);\n });\n\n await patchLinks(path.dirname(jsonFile));\n\n return result;\n}\n\nexport async function resolveSidebarForMultiEntry(\n jsonFile: string,\n): Promise<SidebarGroup[]> {\n const result: SidebarGroup[] = [];\n const data = JSON.parse(await fs.readFile(jsonFile, 'utf-8'));\n if (!data.children || data.children.length <= 0) {\n return result;\n }\n\n function getModulePath(name: string) {\n return path\n .join(`${ROUTE_PREFIX}/modules`, `${transformModuleName(name)}`)\n .replace(/\\\\/g, '/');\n }\n\n function getClassPath(moduleName: string, className: string) {\n return path\n .join(\n `${ROUTE_PREFIX}/classes`,\n `${transformModuleName(moduleName)}.${className}`,\n )\n .replace(/\\\\/g, '/');\n }\n\n function getInterfacePath(moduleName: string, interfaceName: string) {\n return path\n .join(\n `${ROUTE_PREFIX}/interfaces`,\n `${transformModuleName(moduleName)}.${interfaceName}`,\n )\n .replace(/\\\\/g, '/');\n }\n\n function getFunctionPath(moduleName: string, functionName: string) {\n return path\n .join(\n `${ROUTE_PREFIX}/functions`,\n `${transformModuleName(moduleName)}.${functionName}`,\n )\n .replace(/\\\\/g, '/');\n }\n\n data.children.forEach((module: ModuleItem) => {\n const moduleNames = module.name.split('/');\n const name = moduleNames[moduleNames.length - 1];\n const moduleConfig = {\n text: `Module:${name}`,\n items: [{ text: 'Overview', link: getModulePath(module.name) }],\n };\n if (!module.children || module.children.length <= 0) {\n return;\n }\n module.children.forEach(sub => {\n const kindString = module.groups\n .find(item => item.children.includes(sub.id))\n ?.title.slice(0, -1);\n if (!kindString) {\n return;\n }\n switch (kindString) {\n case 'Class':\n moduleConfig.items.push({\n text: `Class:${sub.name}`,\n link: getClassPath(module.name, sub.name),\n });\n break;\n case 'Interface':\n moduleConfig.items.push({\n text: `Interface:${sub.name}`,\n link: getInterfacePath(module.name, sub.name),\n });\n break;\n case 'Function':\n moduleConfig.items.push({\n text: `Function:${sub.name}`,\n link: getFunctionPath(module.name, sub.name),\n });\n break;\n default:\n break;\n }\n });\n result.push(moduleConfig);\n });\n await patchLinks(path.dirname(jsonFile));\n return result;\n}\n","export function transformModuleName(name: string) {\n return name.replace(/\\//g, '_').replace(/-/g, '_');\n}\n"]}
|