@rspress/plugin-api-docgen 2.0.0-beta.11 → 2.0.0-beta.13
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/index.js +22 -22
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
7
|
-
|
1
|
+
import external_node_fs_default from "node:fs";
|
2
|
+
import external_node_path_default from "node:path";
|
3
|
+
import { logger } from "@rspress/shared/logger";
|
4
|
+
import { RSPRESS_TEMP_DIR } from "@rspress/shared";
|
5
|
+
import external_chokidar_default from "chokidar";
|
6
|
+
import { withCompilerOptions, withCustomConfig, withDefaultConfig } from "react-docgen-typescript";
|
7
|
+
external_node_path_default.join(__dirname, '..');
|
8
8
|
const apiDocMap = {};
|
9
9
|
const locales = {
|
10
10
|
zh: {
|
@@ -62,7 +62,7 @@ const docgen = async ({ entries, languages, apiParseTool, appDir, parseToolOptio
|
|
62
62
|
const genApiDoc = async (entry, tool)=>{
|
63
63
|
if (0 === Object.keys(entry).length) return;
|
64
64
|
await Promise.all(Object.entries(entry).map(async ([key, value])=>{
|
65
|
-
const moduleSourceFilePath =
|
65
|
+
const moduleSourceFilePath = external_node_path_default.resolve(appDir, value);
|
66
66
|
watchFileMap[moduleSourceFilePath] = {
|
67
67
|
apiParseTool,
|
68
68
|
moduleName: key
|
@@ -91,22 +91,22 @@ const docgen = async ({ entries, languages, apiParseTool, appDir, parseToolOptio
|
|
91
91
|
},
|
92
92
|
...restOptions
|
93
93
|
};
|
94
|
-
let fileParser =
|
95
|
-
if (tsconfigPath?.[key]) fileParser =
|
96
|
-
else if (compilerOptions?.[key]) fileParser =
|
94
|
+
let fileParser = withDefaultConfig(parserOpts);
|
95
|
+
if (tsconfigPath?.[key]) fileParser = withCustomConfig(tsconfigPath[key], parserOpts);
|
96
|
+
else if (compilerOptions?.[key]) fileParser = withCompilerOptions(compilerOptions[key], parserOpts);
|
97
97
|
const componentDoc = fileParser.parse(moduleSourceFilePath);
|
98
|
-
if (0 === componentDoc.length)
|
98
|
+
if (0 === componentDoc.length) logger.warn('[module-doc-plugin]', `Unable to parse API document in ${moduleSourceFilePath}`);
|
99
99
|
if (languages.length > 0) languages.forEach((language)=>{
|
100
100
|
apiDocMap[`${key}-${language}`] = generateTable(componentDoc, language);
|
101
101
|
});
|
102
102
|
else apiDocMap[key] = generateTable(componentDoc, 'en');
|
103
103
|
}
|
104
104
|
} catch (e) {
|
105
|
-
if (e instanceof Error)
|
105
|
+
if (e instanceof Error) logger.error('[module-doc-plugin]', 'Generate API table error:\n', e);
|
106
106
|
}
|
107
107
|
}));
|
108
108
|
};
|
109
|
-
|
109
|
+
logger.info('[module-doc-plugin]', 'Start to generate API table...');
|
110
110
|
if (isToolEntries(entries)) {
|
111
111
|
const reactEntries = entries["react-docgen-typescript"];
|
112
112
|
const documentationEntries = entries.documentation;
|
@@ -116,7 +116,7 @@ const docgen = async ({ entries, languages, apiParseTool, appDir, parseToolOptio
|
|
116
116
|
]);
|
117
117
|
} else await genApiDoc(entries, apiParseTool);
|
118
118
|
if (!isProd) {
|
119
|
-
const watcher =
|
119
|
+
const watcher = external_chokidar_default.watch(Object.keys(watchFileMap), {
|
120
120
|
ignoreInitial: true,
|
121
121
|
ignorePermissionErrors: true,
|
122
122
|
ignored: [
|
@@ -127,12 +127,12 @@ const docgen = async ({ entries, languages, apiParseTool, appDir, parseToolOptio
|
|
127
127
|
watcher.on('change', (changed)=>{
|
128
128
|
if (isUpdate) return;
|
129
129
|
isUpdate = true;
|
130
|
-
|
130
|
+
logger.info('[module-doc-plugin]', 'updating API');
|
131
131
|
const watchFileInfo = watchFileMap[changed];
|
132
132
|
if (watchFileInfo) {
|
133
133
|
const { apiParseTool, moduleName } = watchFileInfo;
|
134
134
|
const updateSiteData = ()=>{
|
135
|
-
const siteDataPath =
|
135
|
+
const siteDataPath = external_node_path_default.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR, 'runtime', 'virtual-site-data.mjs');
|
136
136
|
import(siteDataPath).then((siteData)=>{
|
137
137
|
const data = {
|
138
138
|
...siteData.default
|
@@ -140,7 +140,7 @@ const docgen = async ({ entries, languages, apiParseTool, appDir, parseToolOptio
|
|
140
140
|
data.pages.forEach((page)=>{
|
141
141
|
page.apiDocMap = apiDocMap;
|
142
142
|
});
|
143
|
-
|
143
|
+
external_node_fs_default.writeFileSync(siteDataPath, `export default ${JSON.stringify(data)}`);
|
144
144
|
isUpdate = false;
|
145
145
|
});
|
146
146
|
};
|
@@ -150,7 +150,7 @@ const docgen = async ({ entries, languages, apiParseTool, appDir, parseToolOptio
|
|
150
150
|
}
|
151
151
|
});
|
152
152
|
}
|
153
|
-
|
153
|
+
logger.success('[module-doc-plugin]', 'Generate API table successfully!');
|
154
154
|
};
|
155
155
|
function generateTable(componentDoc, language) {
|
156
156
|
return componentDoc.map((param)=>{
|
@@ -226,14 +226,14 @@ function pluginApiDocgen(options) {
|
|
226
226
|
const apiCompRegExp = /(<API\s+moduleName=['"](\S+)['"]\s*(.*)?\/>)|(<API\s+moduleName=['"](\S+)['"]\s*(.*)?>(.*)?<\/API>)/;
|
227
227
|
await Promise.all(pages.map(async (page)=>{
|
228
228
|
const { _filepath, lang } = page;
|
229
|
-
let content = await
|
229
|
+
let content = await external_node_fs_default.promises.readFile(_filepath, 'utf-8');
|
230
230
|
let matchResult = apiCompRegExp.exec(content);
|
231
231
|
if (!matchResult) return;
|
232
232
|
while(null !== matchResult){
|
233
233
|
const matchContent = matchResult[0];
|
234
234
|
const moduleName = matchResult[2] ?? matchResult[5] ?? '';
|
235
235
|
const apiDoc = apiDocMap[moduleName] ?? apiDocMap[`${moduleName}-${lang ? lang : 'en'}`] ?? '';
|
236
|
-
if (matchContent && !apiDoc)
|
236
|
+
if (matchContent && !apiDoc) logger.warn(`No api doc found for module: ${moduleName} in lang: ${lang ?? 'en'}`);
|
237
237
|
content = content.replace(matchContent, apiDoc);
|
238
238
|
matchResult = apiCompRegExp.exec(content);
|
239
239
|
}
|
@@ -247,7 +247,7 @@ function pluginApiDocgen(options) {
|
|
247
247
|
},
|
248
248
|
markdown: {
|
249
249
|
globalComponents: [
|
250
|
-
|
250
|
+
external_node_path_default.join(__dirname, '..', 'static', 'global-components', 'API.tsx')
|
251
251
|
]
|
252
252
|
}
|
253
253
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-api-docgen",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.13",
|
4
4
|
"description": "A plugin for rspress to generate api doc.",
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
6
6
|
"repository": {
|
@@ -31,11 +31,11 @@
|
|
31
31
|
"remark-gfm": "^4.0.1",
|
32
32
|
"unified": "^11.0.5",
|
33
33
|
"unist-util-visit": "^5.0.0",
|
34
|
-
"@rspress/shared": "2.0.0-beta.
|
34
|
+
"@rspress/shared": "2.0.0-beta.13"
|
35
35
|
},
|
36
36
|
"devDependencies": {
|
37
37
|
"@microsoft/api-extractor": "^7.52.8",
|
38
|
-
"@rslib/core": "0.
|
38
|
+
"@rslib/core": "0.9.2",
|
39
39
|
"@types/hast": "^3.0.4",
|
40
40
|
"@types/mdast": "^4.0.4",
|
41
41
|
"@types/node": "^22.8.1",
|
@@ -48,7 +48,7 @@
|
|
48
48
|
"typescript": "^5.8.2"
|
49
49
|
},
|
50
50
|
"peerDependencies": {
|
51
|
-
"@rspress/core": "^2.0.0-beta.
|
51
|
+
"@rspress/core": "^2.0.0-beta.13",
|
52
52
|
"typescript": "^5.8.2"
|
53
53
|
},
|
54
54
|
"peerDependenciesMeta": {
|