33import fs from 'node:fs' ;
44import path from 'node:path' ;
55import type { RspressPlugin } from '@rspress/shared' ;
6+ import { logger } from '@rspress/shared/logger' ;
67import { apiDocMap } from './constants' ;
78import { docgen } from './docgen' ;
89import 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