@rspress/plugin-typedoc 1.37.2 → 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.
@@ -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
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
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
- var rejected = (value) => {
39
- try {
40
- step(generator.throw(value));
41
- } catch (e) {
42
- reject(e);
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
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
- step((generator = generator.apply(__this, __arguments)).next());
47
- });
48
- };
49
-
50
- // src/index.ts
51
- var src_exports = {};
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
- module.exports = __toCommonJS(src_exports);
56
- var import_node_path2 = __toESM(require("path"));
57
- var import_typedoc = require("typedoc");
58
- var import_typedoc_plugin_markdown = require("typedoc-plugin-markdown");
59
-
60
- // src/constants.ts
61
- var API_DIR = "api";
62
- var ROUTE_PREFIX = `/${API_DIR}`;
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
69
- function transformModuleName(name) {
70
- return name.replace(/\//g, "_").replace(/-/g, "_");
71
- }
72
-
73
- // src/sidebar.ts
74
- function patchLinks(outputDir) {
75
- return __async(this, null, function* () {
76
- const normlizeLinksInFile = (filePath) => __async(this, null, function* () {
77
- const content = yield import_fs_extra.default.readFile(filePath, "utf-8");
78
- const newContent = content.replace(
79
- /\[([^\]]+)\]\(([^)]+)\)/g,
80
- (_match, p1, p2) => {
81
- return `[${p1}](./${p2})`;
82
- }
83
- );
84
- yield import_fs_extra.default.writeFile(filePath, newContent);
85
- });
86
- const traverse = (dir) => __async(this, null, function* () {
87
- const files = yield import_fs_extra.default.readdir(dir);
88
- for (const file of files) {
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);
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 resolveSidebarForSingleEntry(jsonFile) {
102
- return __async(this, null, function* () {
103
- const result = [];
104
- const data = JSON.parse(yield import_fs_extra.default.readFile(jsonFile, "utf-8"));
105
- if (!data.children || data.children.length <= 0) {
106
- return [];
107
- }
108
- const symbolMap = /* @__PURE__ */ new Map();
109
- data.groups.forEach((group) => {
110
- const groupItem = {
111
- text: group.title,
112
- items: []
113
- };
114
- group.children.forEach((id) => {
115
- const dataItem = data.children.find((item) => item.id === id);
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 resolveSidebarForMultiEntry(jsonFile) {
138
- return __async(this, null, function* () {
139
- const result = [];
140
- const data = JSON.parse(yield import_fs_extra.default.readFile(jsonFile, "utf-8"));
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
- let docRoot;
214
- const { entryPoints = [], outDir = API_DIR } = options;
215
- return {
216
- name: "@rspress/plugin-typedoc",
217
- addPages() {
218
- return __async(this, null, function* () {
219
- return [
220
- {
221
- routePath: `${outDir.replace(/\/$/, "")}/`,
222
- filepath: import_node_path2.default.join(docRoot, outDir, "README.md")
223
- }
224
- ];
225
- });
226
- },
227
- config(config) {
228
- return __async(this, null, function* () {
229
- const app = new import_typedoc.Application();
230
- docRoot = config.root;
231
- app.options.addReader(new import_typedoc.TSConfigReader());
232
- (0, import_typedoc_plugin_markdown.load)(app);
233
- app.bootstrap({
234
- name: config.title,
235
- entryPoints,
236
- theme: "markdown",
237
- disableSources: true,
238
- readme: "none",
239
- githubPages: false,
240
- requiredToBeDocumented: ["Class", "Function", "Interface"],
241
- plugin: ["typedoc-plugin-markdown"],
242
- // @ts-expect-error MarkdownTheme has no export
243
- hideBreadcrumbs: true,
244
- hideMembersSymbol: true,
245
- allReflectionsHaveOwnDocument: true
246
- });
247
- const project = app.convert();
248
- if (project) {
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
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
- } else if ("default" in nav) {
263
- nav.default.push({
264
- text: "API",
265
- link: apiIndexLink
266
- });
267
- }
268
- config.themeConfig.sidebar = config.themeConfig.sidebar || {};
269
- config.themeConfig.sidebar[apiIndexLink] = entryPoints.length > 1 ? yield resolveSidebarForMultiEntry(jsonDir) : yield resolveSidebarForSingleEntry(jsonDir);
270
- config.themeConfig.sidebar[apiIndexLink].unshift({
271
- text: "Overview",
272
- link: `${apiIndexLink}README`
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
- config.route = config.route || {};
276
- config.route.exclude = config.route.exclude || [];
277
- return config;
278
- });
279
- }
280
- };
184
+ };
281
185
  }
282
- // Annotate the CommonJS export names for ESM import in node:
283
- 0 && (module.exports = {
284
- pluginTypeDoc
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
@@ -1,17 +1,18 @@
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 };
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 { }