22
33/**
44 * Post-processing script for TypeDoc-generated MDX files
5- *
5+ *
66 * TypeDoc now emits .mdx files directly, so this script:
77 * 1. Processes links to make them Mintlify-compatible
88 * 2. Removes files for linked types that should be suppressed
@@ -149,7 +149,7 @@ base44.integrations.MyCustomPackage.MyFunction({ param: 'value' });
149149 }
150150 }
151151 }
152-
152+
153153 // Remove .md and .mdx extensions from markdown links
154154 // This handles both relative and absolute paths
155155 // Regex breakdown:
@@ -162,7 +162,7 @@ base44.integrations.MyCustomPackage.MyFunction({ param: 'value' });
162162 let newContent = content . replace (
163163 linkRegex ,
164164 ( match , linkText , linkPath , ext ) => {
165- modified = true ;
165+ modified = true ;
166166
167167 // Check if the link points to a renamed module
168168 const pathParts = linkPath . split ( "/" ) ;
@@ -179,20 +179,20 @@ base44.integrations.MyCustomPackage.MyFunction({ param: 'value' });
179179 // Handle relative links that might be missing context (basic cleanup)
180180 // e.g. if linkPath is just "entities" but it should be relative
181181
182- return `[${ linkText } ](${ linkPath } )` ;
182+ return `[${ linkText } ](${ linkPath } )` ;
183183 }
184184 ) ;
185185
186186 // Also check for links that might have already been processed (no extension)
187187 // or if the above regex missed them (though it matches .mdx?)
188188 // The regex requires .md or .mdx extension. If links are already extensionless, this won't run.
189189 // But TypeDoc usually outputs links with extensions.
190-
190+
191191 if ( modified ) {
192192 fs . writeFileSync ( filePath , newContent , "utf-8" ) ;
193193 return true ;
194194 }
195-
195+
196196 return false ;
197197}
198198
@@ -272,18 +272,18 @@ function scanDocsContent() {
272272 } ;
273273
274274 const sections = [ "functions" , "interfaces" , "classes" , "type-aliases" ] ;
275-
275+
276276 for ( const section of sections ) {
277277 const sectionDir = path . join ( CONTENT_DIR , section ) ;
278278 if ( ! fs . existsSync ( sectionDir ) ) continue ;
279-
279+
280280 const files = fs . readdirSync ( sectionDir ) ;
281281 const mdxFiles = files
282282 . filter ( ( file ) => file . endsWith ( ".mdx" ) )
283283 . map ( ( file ) => path . basename ( file , ".mdx" ) )
284284 . sort ( )
285285 . map ( ( fileName ) => `content/${ section } /${ fileName } ` ) ;
286-
286+
287287 const key = section === "type-aliases" ? "typeAliases" : section ;
288288 result [ key ] = mdxFiles ;
289289 }
@@ -298,7 +298,7 @@ function getGroupName(section, categoryMap) {
298298 if ( categoryMap [ section ] ) {
299299 return categoryMap [ section ] ;
300300 }
301-
301+
302302 return section ;
303303}
304304
@@ -314,30 +314,30 @@ function generateDocsJson(docsContent) {
314314 // If file doesn't exist or can't be read, return empty object
315315 console . error ( `Error: Category map file not found: ${ CATEGORY_MAP_PATH } ` ) ;
316316 }
317-
317+
318318 const groups = [ ] ;
319-
319+
320320 if ( docsContent . functions . length > 0 && categoryMap . functions ) {
321321 groups . push ( {
322322 group : getGroupName ( "functions" , categoryMap ) ,
323323 pages : docsContent . functions ,
324324 } ) ;
325325 }
326-
326+
327327 if ( docsContent . interfaces . length > 0 && categoryMap . interfaces ) {
328328 groups . push ( {
329329 group : getGroupName ( "interfaces" , categoryMap ) ,
330330 pages : docsContent . interfaces ,
331331 } ) ;
332332 }
333-
333+
334334 if ( docsContent . classes . length > 0 && categoryMap . classes ) {
335335 groups . push ( {
336336 group : getGroupName ( "classes" , categoryMap ) ,
337337 pages : docsContent . classes ,
338338 } ) ;
339339 }
340-
340+
341341 if ( docsContent . typeAliases . length > 0 && categoryMap [ "type-aliases" ] ) {
342342 // Merge into existing group if name matches
343343 const groupName = getGroupName ( "type-aliases" , categoryMap ) ;
@@ -348,13 +348,13 @@ function generateDocsJson(docsContent) {
348348 existingGroup . pages . push ( ...docsContent . typeAliases ) ;
349349 existingGroup . pages . sort ( ) ; // Sort combined pages alphabetically
350350 } else {
351- groups . push ( {
351+ groups . push ( {
352352 group : groupName ,
353- pages : docsContent . typeAliases ,
354- } ) ;
353+ pages : docsContent . typeAliases ,
354+ } ) ;
355355 }
356356 }
357-
357+
358358 // Find or create SDK Reference tab
359359 let sdkTab = template . navigation . tabs . find (
360360 ( tab ) => tab . tab === "SDK Reference"
@@ -363,9 +363,9 @@ function generateDocsJson(docsContent) {
363363 sdkTab = { tab : "SDK Reference" , groups : [ ] } ;
364364 template . navigation . tabs . push ( sdkTab ) ;
365365 }
366-
366+
367367 sdkTab . groups = groups ;
368-
368+
369369 const docsJsonPath = path . join ( DOCS_DIR , "docs.json" ) ;
370370 fs . writeFileSync (
371371 docsJsonPath ,
@@ -405,10 +405,10 @@ function isTypeDocPath(relativePath) {
405405 */
406406function processAllFiles ( dir , linkedTypeNames , exposedTypeNames ) {
407407 const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
408-
408+
409409 for ( const entry of entries ) {
410410 const entryPath = path . join ( dir , entry . name ) ;
411-
411+
412412 if ( entry . isDirectory ( ) ) {
413413 processAllFiles ( entryPath , linkedTypeNames , exposedTypeNames ) ;
414414 } else if (
@@ -433,7 +433,7 @@ function processAllFiles(dir, linkedTypeNames, exposedTypeNames) {
433433 exposedTypeNames . has ( originalName ) ||
434434 exposedTypeNames . has ( fileName ) ||
435435 isRenamedModule ;
436-
436+
437437 // Remove any type doc files that are not explicitly exposed
438438 if ( isTypeDoc && ! isExposedType ) {
439439 fs . unlinkSync ( entryPath ) ;
@@ -683,7 +683,7 @@ function applyAppendedArticles(appendedArticles) {
683683 console . warn (
684684 `Warning: Appended article not found: ${ appendKey } (checked content/ and docs/ roots)`
685685 ) ;
686- continue ;
686+ continue ;
687687 }
688688 }
689689 }
@@ -692,7 +692,7 @@ function applyAppendedArticles(appendedArticles) {
692692 const { section, headings } = prepareAppendedSection ( appendPath ) ;
693693 combinedSections += `\n\n${ section } ` ;
694694 if ( PANELS_ENABLED && collectedHeadings ) {
695- collectedHeadings . push ( ...headings ) ;
695+ collectedHeadings . push ( ...headings ) ;
696696 }
697697
698698 try {
@@ -768,29 +768,29 @@ function applyHeadingDemotion(dir) {
768768 */
769769function main ( ) {
770770 console . log ( "Processing TypeDoc MDX files for Mintlify...\n" ) ;
771-
771+
772772 if ( ! fs . existsSync ( DOCS_DIR ) ) {
773773 console . error ( `Error: Documentation directory not found: ${ DOCS_DIR } ` ) ;
774774 console . error ( 'Please run "npm run docs:generate" first.' ) ;
775775 process . exit ( 1 ) ;
776776 }
777-
777+
778778 // Get list of linked types to suppress
779779 const linkedTypeNames = getLinkedTypeNames ( ) ;
780780 const exposedTypeNames = getTypesToExpose ( ) ;
781781
782782 // First, perform module renames (EntitiesModule -> entities, etc.)
783783 performModuleRenames ( DOCS_DIR ) ;
784-
784+
785785 // Process all files (remove suppressed ones and fix links)
786- processAllFiles ( DOCS_DIR , linkedTypeNames , exposedTypeNames ) ;
786+ processAllFiles ( DOCS_DIR , linkedTypeNames , exposedTypeNames ) ;
787787
788788 // Append configured articles
789789 const appendedArticles = loadAppendedArticlesConfig ( ) ;
790790 applyAppendedArticles ( appendedArticles ) ;
791791
792792 applyHeadingDemotion ( DOCS_DIR ) ;
793-
793+
794794 // Clean up the linked types file
795795 try {
796796 if ( fs . existsSync ( LINKED_TYPES_FILE ) ) {
@@ -799,14 +799,14 @@ function main() {
799799 } catch ( e ) {
800800 // Ignore errors
801801 }
802-
802+
803803 // Scan content and generate docs.json
804804 const docsContent = scanDocsContent ( ) ;
805805 generateDocsJson ( docsContent ) ;
806-
806+
807807 // Copy styling.css
808808 copyStylingCss ( ) ;
809-
809+
810810 console . log ( `\n✓ Post-processing complete!` ) ;
811811 console . log ( ` Documentation directory: ${ DOCS_DIR } ` ) ;
812812}
0 commit comments