@@ -33,25 +33,56 @@ const APPENDED_ARTICLES_PATH = path.join(
3333// Controlled via env var so we can re-enable Panel injection when needed.
3434const PANELS_ENABLED = process . env . MINTLIFY_INCLUDE_PANELS === "true" ;
3535
36- const MODULE_RENAMES = {
37- AgentsModule : "agents" ,
38- AnalyticsModule : "analytics" ,
39- AppLogsModule : "app-logs" ,
40- AuthModule : "auth" ,
41- ConnectorsModule : "connectors" ,
42- EntitiesModule : "entities" ,
43- FunctionsModule : "functions" ,
44- IntegrationsModule : "integrations" ,
45- SsoModule : "sso" ,
46- } ;
47-
48- const REVERSE_MODULE_RENAMES = Object . entries ( MODULE_RENAMES ) . reduce (
49- ( acc , [ k , v ] ) => {
50- acc [ v ] = k ;
51- return acc ;
52- } ,
53- { }
54- ) ;
36+ /**
37+ * Converts a PascalCase module name to kebab-case.
38+ * E.g., "AgentsModule" -> "agents", "AppLogsModule" -> "app-logs"
39+ *
40+ * @param {string } name - The PascalCase name (e.g., "AgentsModule")
41+ * @returns {string | null } - The kebab-case name, or null if not a module name
42+ */
43+ function deriveModuleRename ( name ) {
44+ if ( ! name . endsWith ( "Module" ) ) {
45+ return null ;
46+ }
47+
48+ // Remove "Module" suffix
49+ const withoutModule = name . slice ( 0 , - 6 ) ;
50+
51+ // Convert PascalCase to kebab-case
52+ // Insert hyphen before each capital letter (except the first), then lowercase
53+ const kebabCase = withoutModule
54+ . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1-$2" )
55+ . toLowerCase ( ) ;
56+
57+ return kebabCase ;
58+ }
59+
60+ /**
61+ * Checks if a name is a module name (ends with "Module") and returns its renamed version.
62+ * Uses the derived rename algorithm.
63+ *
64+ * @param {string } name - The name to check
65+ * @returns {string | null } - The renamed version, or null if not a module
66+ */
67+ function getModuleRename ( name ) {
68+ return deriveModuleRename ( name ) ;
69+ }
70+
71+ /**
72+ * Checks if a name is a renamed module (kebab-case) and returns its original name.
73+ *
74+ * @param {string } name - The kebab-case name to check
75+ * @returns {string | null } - The original PascalCase module name, or null if not found
76+ */
77+ function getReverseModuleRename ( name ) {
78+ // Convert kebab-case back to PascalCase and add "Module" suffix
79+ const pascalCase = name
80+ . split ( "-" )
81+ . map ( ( part ) => part . charAt ( 0 ) . toUpperCase ( ) + part . slice ( 1 ) )
82+ . join ( "" ) ;
83+
84+ return `${ pascalCase } Module` ;
85+ }
5586
5687/**
5788 * Get list of linked type names that should be suppressed
@@ -170,8 +201,9 @@ Access to additional integration packages.
170201 // If filename has extension, strip it for checking map
171202 const nameWithoutExt = filename . replace ( / \. m d x ? $ / , "" ) ;
172203
173- if ( MODULE_RENAMES [ nameWithoutExt ] ) {
174- pathParts [ pathParts . length - 1 ] = MODULE_RENAMES [ nameWithoutExt ] ;
204+ const moduleRename = getModuleRename ( nameWithoutExt ) ;
205+ if ( moduleRename ) {
206+ pathParts [ pathParts . length - 1 ] = moduleRename ;
175207 linkPath = pathParts . join ( "/" ) ;
176208 }
177209
@@ -223,15 +255,22 @@ function performModuleRenames(dir) {
223255 let targetName = nameWithoutExt ;
224256 let needsRename = false ;
225257
226- if ( MODULE_RENAMES [ nameWithoutExt ] ) {
227- targetName = MODULE_RENAMES [ nameWithoutExt ] ;
258+ const moduleRename = getModuleRename ( nameWithoutExt ) ;
259+ if ( moduleRename ) {
260+ targetName = moduleRename ;
228261 needsRename = true ;
229- } else if ( REVERSE_MODULE_RENAMES [ nameWithoutExt ] ) {
230- // It's already renamed (e.g. "entities"), but we should ensure title is correct
231- targetName = nameWithoutExt ;
262+ } else if ( nameWithoutExt . match ( / ^ [ a - z ] + ( - [ a - z ] + ) * $ / ) ) {
263+ // It's already in kebab-case (e.g. "entities", "app-logs"), might be a renamed module
264+ // Check if we can derive an original module name from it
265+ const possibleOriginal = getReverseModuleRename ( nameWithoutExt ) ;
266+ if ( possibleOriginal ) {
267+ targetName = nameWithoutExt ;
268+ }
232269 }
233270
234- if ( needsRename || REVERSE_MODULE_RENAMES [ targetName ] ) {
271+ // Process if it needs renaming OR if it looks like a module file (for title updates)
272+ const isModuleFile = needsRename || nameWithoutExt . match ( / ^ [ a - z ] + ( - [ a - z ] + ) * $ / ) ;
273+ if ( isModuleFile ) {
235274 const newPath = path . join ( dir , `${ targetName } .mdx` ) ; // Always use .mdx
236275
237276 let content = fs . readFileSync ( entryPath , "utf-8" ) ;
@@ -420,12 +459,16 @@ function processAllFiles(dir, linkedTypeNames, exposedTypeNames) {
420459 const relativePath = path . relative ( DOCS_DIR , entryPath ) ;
421460 const isTypeDoc = isTypeDocPath ( relativePath ) ;
422461
423- // Check if exposed. Handle renamed modules by checking reverse map .
462+ // Check if exposed. Handle renamed modules by deriving the original name .
424463 // Use both the raw filename and any potential original name
425- const originalName = REVERSE_MODULE_RENAMES [ fileName ] || fileName ;
464+ // If the filename is kebab-case, it might be a renamed module
465+ const possibleOriginalModule = fileName . match ( / ^ [ a - z ] + ( - [ a - z ] + ) * $ / )
466+ ? getReverseModuleRename ( fileName )
467+ : null ;
468+ const originalName = possibleOriginalModule || fileName ;
426469
427470 // If it's a renamed module (e.g. "entities"), treat it as exposed if "EntitiesModule" is exposed
428- const isRenamedModule = ! ! REVERSE_MODULE_RENAMES [ fileName ] ;
471+ const isRenamedModule = ! ! possibleOriginalModule ;
429472
430473 const isExposedType =
431474 ! isTypeDoc ||
@@ -627,12 +670,13 @@ function applyAppendedArticles(appendedArticles) {
627670 continue ;
628671 }
629672
630- // Check if host was renamed
673+ // Check if host was renamed (derives rename automatically for *Module names)
631674 let effectiveHostKey = hostKey ;
632675 const pathParts = hostKey . split ( "/" ) ;
633676 const hostName = pathParts [ pathParts . length - 1 ] ;
634- if ( MODULE_RENAMES [ hostName ] ) {
635- pathParts [ pathParts . length - 1 ] = MODULE_RENAMES [ hostName ] ;
677+ const hostModuleRename = getModuleRename ( hostName ) ;
678+ if ( hostModuleRename ) {
679+ pathParts [ pathParts . length - 1 ] = hostModuleRename ;
636680 effectiveHostKey = pathParts . join ( "/" ) ;
637681 }
638682
@@ -650,12 +694,13 @@ function applyAppendedArticles(appendedArticles) {
650694 const collectedHeadings = PANELS_ENABLED ? [ ] : null ;
651695
652696 for ( const appendKey of appendList ) {
653- // Check if appended file was renamed (unlikely for EntityHandler but good for consistency )
697+ // Check if appended file was renamed (derives rename automatically for *Module names )
654698 let effectiveAppendKey = appendKey ;
655699 const appendParts = appendKey . split ( "/" ) ;
656700 const appendName = appendParts [ appendParts . length - 1 ] ;
657- if ( MODULE_RENAMES [ appendName ] ) {
658- appendParts [ appendParts . length - 1 ] = MODULE_RENAMES [ appendName ] ;
701+ const appendModuleRename = getModuleRename ( appendName ) ;
702+ if ( appendModuleRename ) {
703+ appendParts [ appendParts . length - 1 ] = appendModuleRename ;
659704 effectiveAppendKey = appendParts . join ( "/" ) ;
660705 }
661706
0 commit comments