Skip to content

Commit 586b207

Browse files
authored
fix(plugin-api-docgen): fallback to en, and should report warning msg when no replacing (#2004) (#2097)
1 parent da3aec9 commit 586b207

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/plugin-api-docgen/src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fs from 'node:fs';
44
import path from 'node:path';
55
import type { RspressPlugin } from '@rspress/shared';
6+
import { logger } from '@rspress/shared/logger';
67
import { apiDocMap } from './constants';
78
import { docgen } from './docgen';
89
import type { PluginOptions, SupportLanguages } from './types';
@@ -26,9 +27,10 @@ export function pluginApiDocgen(options?: PluginOptions): RspressPlugin {
2627
},
2728
async beforeBuild(config, isProd) {
2829
// only support zh , en and ru
29-
const languages = (
30+
const languages: SupportLanguages[] = (
3031
config.themeConfig?.locales?.map(locale => locale.lang) ||
31-
config.locales?.map(locale => locale.lang) || [config.lang || 'en']
32+
config.locales?.map(locale => locale.lang) ||
33+
[]
3234
).filter((lang): lang is SupportLanguages =>
3335
['zh', 'en', 'ru'].includes(lang),
3436
) as SupportLanguages[];
@@ -57,7 +59,14 @@ export function pluginApiDocgen(options?: PluginOptions): RspressPlugin {
5759
const matchContent = matchResult[0];
5860
const moduleName = matchResult[2] ?? matchResult[5] ?? '';
5961
const apiDoc =
60-
apiDocMap[moduleName] ?? apiDocMap[`${moduleName}-${lang}`] ?? '';
62+
apiDocMap[moduleName] ??
63+
apiDocMap[`${moduleName}-${lang ? lang : 'en'}`] ??
64+
'';
65+
if (matchContent && !apiDoc) {
66+
logger.warn(
67+
`No api doc found for module: ${moduleName} in lang: ${lang ?? 'en'}`,
68+
);
69+
}
6170
content = content.replace(matchContent, apiDoc);
6271
matchResult = new RegExp(apiCompRegExp).exec(content);
6372
}

0 commit comments

Comments
 (0)