@rspress/plugin-typedoc 1.0.0-beta.5 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/index.js CHANGED
@@ -1,3 +1,24 @@
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
+
1
22
  // src/index.ts
2
23
  import path2 from "path";
3
24
  import { Application, TSConfigReader } from "typedoc";
@@ -17,78 +38,35 @@ function transformModuleName(name) {
17
38
  }
18
39
 
19
40
  // src/sidebar.ts
20
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
21
- try {
22
- var info = gen[key](arg);
23
- var value = info.value;
24
- } catch (error) {
25
- reject(error);
26
- return;
27
- }
28
- if (info.done) {
29
- resolve(value);
30
- } else {
31
- Promise.resolve(value).then(_next, _throw);
32
- }
33
- }
34
- function _async_to_generator(fn) {
35
- return function() {
36
- var self = this, args = arguments;
37
- return new Promise(function(resolve, reject) {
38
- var gen = fn.apply(self, args);
39
- function _next(value) {
40
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
41
- }
42
- function _throw(err) {
43
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
44
- }
45
- _next(void 0);
46
- });
47
- };
48
- }
49
41
  function patchLinks(outputDir) {
50
- return _patchLinks.apply(this, arguments);
51
- }
52
- function _patchLinks() {
53
- _patchLinks = _async_to_generator(function* (outputDir) {
54
- const normlizeLinksInFile = function() {
55
- var _ref = _async_to_generator(function* (filePath) {
56
- const content = yield fs.readFile(filePath, "utf-8");
57
- const newContent = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, p1, p2) => {
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) => {
58
48
  return `[${p1}](./${p2})`;
59
- });
60
- yield fs.writeFile(filePath, newContent);
61
- });
62
- return function normlizeLinksInFile2(filePath) {
63
- return _ref.apply(this, arguments);
64
- };
65
- }();
66
- const traverse = function() {
67
- var _ref = _async_to_generator(function* (dir) {
68
- const files = yield fs.readdir(dir);
69
- for (const file of files) {
70
- const filePath = path.join(dir, file);
71
- const stat = yield fs.stat(filePath);
72
- if (stat.isDirectory()) {
73
- yield traverse(filePath);
74
- } else if (stat.isFile() && /\.mdx?/.test(file)) {
75
- yield normlizeLinksInFile(filePath);
76
- }
77
49
  }
78
- });
79
- return function traverse2(dir) {
80
- return _ref.apply(this, arguments);
81
- };
82
- }();
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
+ });
83
65
  yield traverse(outputDir);
84
66
  });
85
- return _patchLinks.apply(this, arguments);
86
67
  }
87
68
  function resolveSidebarForSingleEntry(jsonFile) {
88
- return _resolveSidebarForSingleEntry.apply(this, arguments);
89
- }
90
- function _resolveSidebarForSingleEntry() {
91
- _resolveSidebarForSingleEntry = _async_to_generator(function* (jsonFile) {
69
+ return __async(this, null, function* () {
92
70
  const result = [];
93
71
  const data = JSON.parse(yield fs.readFile(jsonFile, "utf-8"));
94
72
  if (!data.children || data.children.length <= 0) {
@@ -122,13 +100,9 @@ function _resolveSidebarForSingleEntry() {
122
100
  yield patchLinks(path.dirname(jsonFile));
123
101
  return result;
124
102
  });
125
- return _resolveSidebarForSingleEntry.apply(this, arguments);
126
103
  }
127
104
  function resolveSidebarForMultiEntry(jsonFile) {
128
- return _resolveSidebarForMultiEntry.apply(this, arguments);
129
- }
130
- function _resolveSidebarForMultiEntry() {
131
- _resolveSidebarForMultiEntry = _async_to_generator(function* (jsonFile) {
105
+ return __async(this, null, function* () {
132
106
  const result = [];
133
107
  const data = JSON.parse(yield fs.readFile(jsonFile, "utf-8"));
134
108
  if (!data.children || data.children.length <= 0) {
@@ -138,32 +112,36 @@ function _resolveSidebarForMultiEntry() {
138
112
  return path.join(`${ROUTE_PREFIX}/modules`, `${transformModuleName(name)}`).replace(/\\/g, "/");
139
113
  }
140
114
  function getClassPath(moduleName, className) {
141
- return path.join(`${ROUTE_PREFIX}/classes`, `${transformModuleName(moduleName)}.${className}`).replace(/\\/g, "/");
115
+ return path.join(
116
+ `${ROUTE_PREFIX}/classes`,
117
+ `${transformModuleName(moduleName)}.${className}`
118
+ ).replace(/\\/g, "/");
142
119
  }
143
120
  function getInterfacePath(moduleName, interfaceName) {
144
- return path.join(`${ROUTE_PREFIX}/interfaces`, `${transformModuleName(moduleName)}.${interfaceName}`).replace(/\\/g, "/");
121
+ return path.join(
122
+ `${ROUTE_PREFIX}/interfaces`,
123
+ `${transformModuleName(moduleName)}.${interfaceName}`
124
+ ).replace(/\\/g, "/");
145
125
  }
146
126
  function getFunctionPath(moduleName, functionName) {
147
- return path.join(`${ROUTE_PREFIX}/functions`, `${transformModuleName(moduleName)}.${functionName}`).replace(/\\/g, "/");
127
+ return path.join(
128
+ `${ROUTE_PREFIX}/functions`,
129
+ `${transformModuleName(moduleName)}.${functionName}`
130
+ ).replace(/\\/g, "/");
148
131
  }
149
132
  data.children.forEach((module) => {
150
133
  const moduleNames = module.name.split("/");
151
134
  const name = moduleNames[moduleNames.length - 1];
152
135
  const moduleConfig = {
153
136
  text: `Module:${name}`,
154
- items: [
155
- {
156
- text: "Overview",
157
- link: getModulePath(module.name)
158
- }
159
- ]
137
+ items: [{ text: "Overview", link: getModulePath(module.name) }]
160
138
  };
161
139
  if (!module.children || module.children.length <= 0) {
162
140
  return;
163
141
  }
164
142
  module.children.forEach((sub) => {
165
- var _module_groups_find;
166
- const kindString = (_module_groups_find = module.groups.find((item) => item.children.includes(sub.id))) === null || _module_groups_find === void 0 ? void 0 : _module_groups_find.title.slice(0, -1);
143
+ var _a;
144
+ const kindString = (_a = module.groups.find((item) => item.children.includes(sub.id))) == null ? void 0 : _a.title.slice(0, -1);
167
145
  if (!kindString) {
168
146
  return;
169
147
  }
@@ -195,56 +173,26 @@ function _resolveSidebarForMultiEntry() {
195
173
  yield patchLinks(path.dirname(jsonFile));
196
174
  return result;
197
175
  });
198
- return _resolveSidebarForMultiEntry.apply(this, arguments);
199
176
  }
200
177
 
201
178
  // src/index.ts
202
- function asyncGeneratorStep2(gen, resolve, reject, _next, _throw, key, arg) {
203
- try {
204
- var info = gen[key](arg);
205
- var value = info.value;
206
- } catch (error) {
207
- reject(error);
208
- return;
209
- }
210
- if (info.done) {
211
- resolve(value);
212
- } else {
213
- Promise.resolve(value).then(_next, _throw);
214
- }
215
- }
216
- function _async_to_generator2(fn) {
217
- return function() {
218
- var self = this, args = arguments;
219
- return new Promise(function(resolve, reject) {
220
- var gen = fn.apply(self, args);
221
- function _next(value) {
222
- asyncGeneratorStep2(gen, resolve, reject, _next, _throw, "next", value);
223
- }
224
- function _throw(err) {
225
- asyncGeneratorStep2(gen, resolve, reject, _next, _throw, "throw", err);
226
- }
227
- _next(void 0);
228
- });
229
- };
230
- }
231
179
  function pluginTypeDoc(options) {
232
180
  let docRoot;
233
181
  const { entryPoints = [], outDir = API_DIR } = options;
234
182
  return {
235
183
  name: "@rspress/plugin-typedoc",
236
184
  addPages() {
237
- return _async_to_generator2(function* () {
185
+ return __async(this, null, function* () {
238
186
  return [
239
187
  {
240
188
  routePath: `${outDir.replace(/\/$/, "")}/`,
241
189
  filepath: path2.join(docRoot, outDir, "README.md")
242
190
  }
243
191
  ];
244
- })();
192
+ });
245
193
  },
246
194
  config(config) {
247
- return _async_to_generator2(function* () {
195
+ return __async(this, null, function* () {
248
196
  const app = new Application();
249
197
  docRoot = config.root;
250
198
  app.options.addReader(new TSConfigReader());
@@ -256,14 +204,8 @@ function pluginTypeDoc(options) {
256
204
  disableSources: true,
257
205
  readme: "none",
258
206
  githubPages: false,
259
- requiredToBeDocumented: [
260
- "Class",
261
- "Function",
262
- "Interface"
263
- ],
264
- plugin: [
265
- "typedoc-plugin-markdown"
266
- ],
207
+ requiredToBeDocumented: ["Class", "Function", "Interface"],
208
+ plugin: ["typedoc-plugin-markdown"],
267
209
  // @ts-expect-error MarkdownTheme has no export
268
210
  hideBreadcrumbs: true,
269
211
  hideMembersSymbol: true,
@@ -292,7 +234,7 @@ function pluginTypeDoc(options) {
292
234
  config.route = config.route || {};
293
235
  config.route.exclude = config.route.exclude || [];
294
236
  return config;
295
- })();
237
+ });
296
238
  }
297
239
  };
298
240
  }
@@ -1 +1 @@
1
- {"version":3,"mappings":";AAAA,OAAOA,WAAU;AACjB,SAASC,aAAaC,sBAAsB;AAE5C,SAASC,YAAY;;;ACHd,IAAMC,UAAU;AAChB,IAAMC,eAAe,IAAID;;;ACDhC,OAAOJ,UAAU;AACjB,OAAOM,QAAQ;;;ACDR,SAASC,oBAAoBC,MAAY;AAC9C,SAAOA,KAAKC,QAAQ,OAAO,KAAKA,QAAQ,MAAM;AAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SDiBeC,WAAWC,WAAiB;SAA5BD;;SAAAA;AAAAA,gBAAf,+BAA0BC,WAAiB;AAIzC,UAAMC;iBAAsB,+BAAOC;AACjC,cAAMC,UAAU,MAAMR,GAAGS,SAASF,UAAU;AAE5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DIR","ROUTE_PREFIX","fs","transformModuleName","name","replace","patchLinks","outputDir","normlizeLinksInFile","filePath","content","readFile","newContent","_match","p1","p2","writeFile","traverse","dir","files","readdir","file","join","stat","isDirectory","isFile","test","resolveSidebarForSingleEntry","jsonFile","result","data","JSON","parse","children","length","symbolMap","Map","groups","forEach","group","groupItem","text","title","items","id","dataItem","find","item","fileName","has","count","get","set","toLocaleLowerCase","push","link","dirname","resolveSidebarForMultiEntry","getModulePath","getClassPath","moduleName","className","getInterfacePath","interfaceName","getFunctionPath","functionName","module","moduleNames","split","moduleConfig","sub","kindString","includes","slice","pluginTypeDoc","options","docRoot","entryPoints","outDir","addPages","_async_to_generator","routePath","filepath","config","app","root","addReader","bootstrap","theme","disableSources","readme","githubPages","requiredToBeDocumented","plugin","hideBreadcrumbs","hideMembersSymbol","allReflectionsHaveOwnDocument","project","convert","absoluteOutputdir","generateDocs","jsonDir","generateJson","themeConfig","nav","apiIndexLink","sidebar","unshift","route","exclude"],"sources":["../../src/home/runner/work/rspress/rspress/packages/plugin-typedoc/src/index.ts","../../src/home/runner/work/rspress/rspress/packages/plugin-typedoc/src/constants.ts","../../src/home/runner/work/rspress/rspress/packages/plugin-typedoc/src/sidebar.ts","../../src/home/runner/work/rspress/rspress/packages/plugin-typedoc/src/utils.ts"],"sourcesContent":["import path from '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 config.themeConfig.nav.push({\n text: 'API',\n link: apiIndexLink,\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 'path';\nimport fs from '@modern-js/utils/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 [xxx](yyy) -> [xxx](./yyy)\n const normlizeLinksInFile = async (filePath: string) => {\n const content = await fs.readFile(filePath, 'utf-8');\n // replace: [xxx](yyy) -> [xxx](./yyy)\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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oBAAoBA,MAAK,KAAK,SAAU,MAAM;AACpD,gBAAM,IAAI,aAAa,SAAS,iBAAiB;AACjD,gBAAM,UAAUA,MAAK,KAAK,mBAAmB,oBAAoB;AACjE,gBAAM,IAAI,aAAa,SAAS,OAAO;AAEvC,iBAAO,cAAc,OAAO,eAAe,CAAC;AAC5C,iBAAO,YAAY,MAAM,OAAO,YAAY,OAAO,CAAC;AACpD,gBAAM,eAAe,IAAI,OAAO,QAAQ,eAAe,EAAE,CAAC;AAC1D,iBAAO,YAAY,IAAI,KAAK;AAAA,YAC1B,MAAM;AAAA,YACN,MAAM;AAAA,UACR,CAAC;AACD,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"],"sources":["../../src/index.ts","../../src/constants.ts","../../src/sidebar.ts","../../src/utils.ts"],"sourcesContent":["import path from '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 config.themeConfig.nav.push({\n text: 'API',\n link: apiIndexLink,\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 'path';\nimport fs from '@modern-js/utils/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 [xxx](yyy) -> [xxx](./yyy)\n const normlizeLinksInFile = async (filePath: string) => {\n const content = await fs.readFile(filePath, 'utf-8');\n // replace: [xxx](yyy) -> [xxx](./yyy)\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.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiB;AACjB,qBAA4C;AAE5C,qCAAqB;;;ACHd,IAAM,UAAU;AAChB,IAAM,eAAe,IAAI;;;ACDhC,kBAAiB;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,wBAAG,SAAS,UAAU,OAAO;AAEnD,YAAM,aAAa,QAAQ;AAAA,QACzB;AAAA,QACA,CAAC,QAAQ,IAAI,OAAO;AAClB,iBAAO,IAAI,SAAS;AAAA,QACtB;AAAA,MACF;AACA,YAAM,wBAAG,UAAU,UAAU,UAAU;AAAA,IACzC;AAEA,UAAM,WAAW,CAAO,QAAgB;AACtC,YAAM,QAAQ,MAAM,wBAAG,QAAQ,GAAG;AAClC,iBAAW,QAAQ,OAAO;AACxB,cAAM,WAAW,oBAAK,KAAK,KAAK,IAAI;AACpC,cAAM,OAAO,MAAM,wBAAG,KAAK,QAAQ;AACnC,YAAI,KAAK,YAAY,GAAG;AACtB,gBAAM,SAAS,QAAQ;AAAA,QACzB,WAAW,KAAK,OAAO,KAAK,SAAS,KAAK,IAAI,GAAG;AAC/C,gBAAM,oBAAoB,QAAQ;AAAA,QACpC;AAAA,MACF;A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B;AAAA,UACjB,mBAAmB;AAAA,UACnB,+BAA+B;AAAA,QACjC,CAAC;AACD,cAAM,UAAU,IAAI,QAAQ;AAE5B,YAAI,SAAS;AAEX,gBAAM,oBAAoB,qBAAK,KAAK,SAAU,MAAM;AACpD,gBAAM,IAAI,aAAa,SAAS,iBAAiB;AACjD,gBAAM,UAAU,qBAAK,KAAK,mBAAmB,oBAAoB;AACjE,gBAAM,IAAI,aAAa,SAAS,OAAO;AAEvC,iBAAO,cAAc,OAAO,eAAe,CAAC;AAC5C,iBAAO,YAAY,MAAM,OAAO,YAAY,OAAO,CAAC;AACpD,gBAAM,eAAe,IAAI,OAAO,QAAQ,eAAe,EAAE;AACzD,iBAAO,YAAY,IAAI,KAAK;AAAA,YAC1B,MAAM;AAAA,YACN,MAAM;AAAA,UACR,CAAC;AACD,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;AAAA,UACX,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":["module"],"sources":["../../src/index.ts","../../src/constants.ts","../../src/sidebar.ts","../../src/utils.ts"],"sourcesContent":["import path from '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 config.themeConfig.nav.push({\n text: 'API',\n link: apiIndexLink,\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 'path';\nimport fs from '@modern-js/utils/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 [xxx](yyy) -> [xxx](./yyy)\n const normlizeLinksInFile = async (filePath: string) => {\n const content = await fs.readFile(filePath, 'utf-8');\n // replace: [xxx](yyy) -> [xxx](./yyy)\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"]}
1
+ {"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiB;AACjB,qBAA4C;AAE5C,qCAAqB;;;ACHd,IAAM,UAAU;AAChB,IAAM,eAAe,IAAI,OAAO;;;ACDvC,kBAAiB;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,wBAAG,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,wBAAG,UAAU,UAAU,UAAU;AAAA,IACzC;AAEA,UAAM,WAAW,CAAO,QAAgB;AACtC,YAAM,QAAQ,MAAM,wBAAG,QAAQ,GAAG;AAClC,iBAAW,QAAQ,OAAO;AACxB,cAAM,WAAW,oBAAK,KAAK,KAAK,IAAI;AACpC,cAAM,OAAO,MAAM,wBAAG,KAAK,QAAQ;AACnC,YAAI,KAAK,YAAY,GAAG;AACtB,gBAAM,SAAS,QAAQ;AAAA,QACzB,WAAW,KAAK,OAAO,KAAK,SAAS,KAAK,IAAI,GAAG;AAC/C,gBAAM,oBAAoB,QAAQ;AAAA,QACpC;AAAA,MACF;AAAA,IACF;AACA,UAAM,S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AAAA,UACb,wBAAwB,CAAC,SAAS,YAAY,WAAW;AAAA,UACzD,QAAQ,CAAC,yBAAyB;AAAA;AAAA,UAElC,iBAAiB;AAAA,UACjB,mBAAmB;AAAA,UACnB,+BAA+B;AAAA,QACjC,CAAC;AACD,cAAM,UAAU,IAAI,QAAQ;AAE5B,YAAI,SAAS;AAEX,gBAAM,oBAAoB,qBAAK,KAAK,SAAU,MAAM;AACpD,gBAAM,IAAI,aAAa,SAAS,iBAAiB;AACjD,gBAAM,UAAU,qBAAK,KAAK,mBAAmB,oBAAoB;AACjE,gBAAM,IAAI,aAAa,SAAS,OAAO;AAEvC,iBAAO,cAAc,OAAO,eAAe,CAAC;AAC5C,iBAAO,YAAY,MAAM,OAAO,YAAY,OAAO,CAAC;AACpD,gBAAM,eAAe,IAAI,OAAO,QAAQ,eAAe,EAAE,CAAC;AAC1D,iBAAO,YAAY,IAAI,KAAK;AAAA,YAC1B,MAAM;AAAA,YACN,MAAM;AAAA,UACR,CAAC;AACD,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":["module"],"sources":["../../src/index.ts","../../src/constants.ts","../../src/sidebar.ts","../../src/utils.ts"],"sourcesContent":["import path from '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 config.themeConfig.nav.push({\n text: 'API',\n link: apiIndexLink,\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 'path';\nimport fs from '@modern-js/utils/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 [xxx](yyy) -> [xxx](./yyy)\n const normlizeLinksInFile = async (filePath: string) => {\n const content = await fs.readFile(filePath, 'utf-8');\n // replace: [xxx](yyy) -> [xxx](./yyy)\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-typedoc",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.1",
4
4
  "description": "A plugin for rspress to integrate typedoc",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -21,17 +21,17 @@
21
21
  "dist/"
22
22
  ],
23
23
  "devDependencies": {
24
- "@modern-js/tsconfig": "2.35.1",
24
+ "@modern-js/tsconfig": "2.36.0",
25
25
  "@types/node": "^18.11.17",
26
26
  "@types/react": "^18",
27
27
  "@types/react-dom": "^18",
28
28
  "typescript": "^5",
29
29
  "vitest": "0.33.0",
30
30
  "react": "^18",
31
- "@rspress/shared": "1.0.0-beta.5"
31
+ "@rspress/shared": "1.0.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "rspress": "1.0.0-beta.5"
34
+ "rspress": "1.0.1"
35
35
  },
36
36
  "sideEffects": [
37
37
  "*.css",
@@ -49,7 +49,7 @@
49
49
  "registry": "https://registry.npmjs.org/"
50
50
  },
51
51
  "dependencies": {
52
- "@modern-js/utils": "2.35.1",
52
+ "@modern-js/utils": "2.36.0",
53
53
  "typedoc": "0.24.8",
54
54
  "typedoc-plugin-markdown": "3.15.3"
55
55
  },