1+ /* eslint-disable no-console */
2+ /* eslint-env node */
13import fs from 'fs' ;
24import path from 'path' ;
35import { fileURLToPath } from 'url' ;
@@ -9,11 +11,11 @@ import {
911const __filename = fileURLToPath ( import . meta. url ) ;
1012const __dirname = path . dirname ( __filename ) ;
1113
12- // Find the generated_docs_data .json file to determine output location
14+ // Find the generated_docs_data_v2 .json file to determine output location
1315function findGeneratedDocsPath ( ) {
1416 const generatedDir = path . join ( __dirname , 'generated' ) ;
15-
16- // Look for generated_docs_data .json recursively
17+
18+ // Look for generated_docs_data_v2 .json recursively
1719 function findFile ( dir ) {
1820 const files = fs . readdirSync ( dir ) ;
1921 for ( const file of files ) {
@@ -22,24 +24,21 @@ function findGeneratedDocsPath() {
2224 if ( stat . isDirectory ( ) ) {
2325 const result = findFile ( fullPath ) ;
2426 if ( result ) return result ;
25- } else if ( file === 'generated_docs_data .json' ) {
27+ } else if ( file === 'generated_docs_data_v2 .json' ) {
2628 return path . dirname ( fullPath ) ;
2729 }
2830 }
2931 return null ;
3032 }
31-
33+
3234 const docsPath = findFile ( generatedDir ) ;
3335 return docsPath || generatedDir ; // Fallback to generated root if not found
3436}
3537
3638// Configuration for admin surface
3739const config = {
3840 basePath : path . join ( __dirname , '../../../src/surfaces/admin' ) ,
39- outputPath : path . join (
40- findGeneratedDocsPath ( ) ,
41- 'targets.json' ,
42- ) ,
41+ outputPath : path . join ( findGeneratedDocsPath ( ) , 'targets.json' ) ,
4342 componentTypesPath : 'components' ,
4443 hasComponentTypes : true ,
4544} ;
@@ -77,8 +76,8 @@ function parseCheckoutComponents() {
7776 if ( checkoutComponentsCache . length === 0 ) {
7877 // Fallback: try to get just SUPPORTED_COMPONENTS
7978 const typeDefs = checkoutTypeResolver . getTypeDefinitions ( ) ;
80- if ( Array . isArray ( typeDefs [ ' SUPPORTED_COMPONENTS' ] ) ) {
81- checkoutComponentsCache = [ ...typeDefs [ ' SUPPORTED_COMPONENTS' ] ] ;
79+ if ( Array . isArray ( typeDefs . SUPPORTED_COMPONENTS ) ) {
80+ checkoutComponentsCache = [ ...typeDefs . SUPPORTED_COMPONENTS ] ;
8281 } else {
8382 checkoutComponentsCache = [ '[CheckoutComponentsNotFound]' ] ;
8483 }
@@ -120,23 +119,23 @@ function parseStringUnionType(filePath, componentTypesMap = {}) {
120119 const typeRefs = typeDef . match ( / \b ( [ A - Z ] \w + (?: C o m p o n e n t s ? ) ? ) \b / g) ;
121120
122121 if ( typeRefs ) {
123- const allComponents = [ ...quotedComponents ] ;
122+ const components = [ ...quotedComponents ] ;
124123
125124 for ( const typeRef of typeRefs ) {
126125 // Check if this is AnyComponent (imported from checkout)
127126 if ( typeRef === 'AnyComponent' ) {
128127 // Add all checkout components
129128 const checkoutComponents = parseCheckoutComponents ( ) ;
130- allComponents . push ( ...checkoutComponents ) ;
129+ components . push ( ...checkoutComponents ) ;
131130 }
132131 // If this type reference exists in our map, include its components
133132 else if ( componentTypesMap [ typeRef ] ) {
134- allComponents . push ( ...componentTypesMap [ typeRef ] ) ;
133+ components . push ( ...componentTypesMap [ typeRef ] ) ;
135134 }
136135 }
137136
138137 // Remove duplicates
139- return [ ...new Set ( allComponents ) ] ;
138+ return [ ...new Set ( components ) ] ;
140139 }
141140 }
142141
@@ -387,7 +386,7 @@ function parseRunnableTargetsFromInterfaceBody(interfaceBody, targets) {
387386
388387function getNestedApis ( apiName ) {
389388 // Check if we've already parsed this API
390- if ( apiDefinitionsCache . hasOwnProperty ( apiName ) ) {
389+ if ( Object . prototype . hasOwnProperty . call ( apiDefinitionsCache , apiName ) ) {
391390 return apiDefinitionsCache [ apiName ] ;
392391 }
393392
@@ -444,7 +443,7 @@ function getNestedApis(apiName) {
444443 }
445444
446445 // Find the end position (semicolon at the correct nesting level)
447- let startPos = startMatch . index + startMatch [ 0 ] . length ;
446+ const startPos = startMatch . index + startMatch [ 0 ] . length ;
448447 let endPos = startPos ;
449448 let braceDepth = 0 ;
450449 let angleDepth = 0 ;
@@ -489,15 +488,15 @@ function parseApis(apiString) {
489488 const apisSet = new Set ( ) ;
490489
491490 // Remove any comments
492- apiString = apiString
491+ const trimmedApiString = apiString
493492 . replace ( / \/ \/ [ ^ \n ] * / g, '' )
494493 . replace ( / \/ \* [ \s \S ] * ?\* \/ / g, '' ) ;
495494
496495 // Split by & and extract API names
497- const parts = apiString
496+ const parts = trimmedApiString
498497 . split ( '&' )
499- . map ( ( s ) => s . trim ( ) )
500- . filter ( ( s ) => s ) ;
498+ . map ( ( part ) => part . trim ( ) )
499+ . filter ( ( part ) => part ) ;
501500
502501 for ( const part of parts ) {
503502 // Match API names (e.g., StandardApi<'...'> or just ApiName)
@@ -539,10 +538,10 @@ function parseApis(apiString) {
539538 */
540539function parseComponents ( componentString , componentTypesMap ) {
541540 // Normalize whitespace
542- componentString = componentString . replace ( / \s + / g, ' ' ) . trim ( ) ;
541+ const trimmedComponentString = componentString . replace ( / \s + / g, ' ' ) . trim ( ) ;
543542
544543 // Handle AnyCheckoutComponentExcept<'Component1' | 'Component2'>
545- const checkoutExceptMatch = componentString . match (
544+ const checkoutExceptMatch = trimmedComponentString . match (
546545 / A n y C h e c k o u t C o m p o n e n t E x c e p t < ( [ ^ > ] + ) > / ,
547546 ) ;
548547 if ( checkoutExceptMatch ) {
@@ -552,27 +551,36 @@ function parseComponents(componentString, componentTypesMap) {
552551 // Parse the union of excluded components
553552 const excludedComponents = parseUnionOfStrings ( excludedUnion ) ;
554553 // Filter out the excluded components
555- return allCheckoutComponents . filter ( ( c ) => ! excludedComponents . includes ( c ) ) ;
554+ return allCheckoutComponents . filter (
555+ ( component ) => ! excludedComponents . includes ( component ) ,
556+ ) ;
556557 }
557558
558559 // Handle Exclude<BaseType, ExcludedComponent>
559- const excludeMatch = componentString . match ( / E x c l u d e < ( \w + ) , \s * ' ( [ ^ ' ] + ) ' > / ) ;
560+ const excludeMatch = trimmedComponentString . match (
561+ / E x c l u d e < ( \w + ) , \s * ' ( [ ^ ' ] + ) ' > / ,
562+ ) ;
560563 if ( excludeMatch ) {
561564 const baseType = excludeMatch [ 1 ] ;
562565 const excluded = excludeMatch [ 2 ] ;
563566 const baseComponents = resolveComponentType ( baseType , componentTypesMap ) ;
564- return baseComponents . filter ( ( c ) => c !== excluded ) ;
567+ return baseComponents . filter ( ( component ) => component !== excluded ) ;
565568 }
566569
567570 // Handle AllowedComponents<ComponentType>
568- const allowedMatch = componentString . match ( / A l l o w e d C o m p o n e n t s < ( [ ^ > ] + ) > / ) ;
571+ const allowedMatch = trimmedComponentString . match (
572+ / A l l o w e d C o m p o n e n t s < ( [ ^ > ] + ) > / ,
573+ ) ;
569574 if ( allowedMatch ) {
570575 const innerType = allowedMatch [ 1 ] . trim ( ) ;
571576 return resolveComponentType ( innerType , componentTypesMap ) ;
572577 }
573578
574579 // Check if it's a direct type reference
575- const result = resolveComponentType ( componentString , componentTypesMap ) ;
580+ const result = resolveComponentType (
581+ trimmedComponentString ,
582+ componentTypesMap ,
583+ ) ;
576584 if ( result . length > 0 ) {
577585 return result ;
578586 }
@@ -607,24 +615,24 @@ function parseUnionOfStrings(unionString) {
607615 * Resolve a component type name to a list of component names
608616 */
609617function resolveComponentType ( typeName , componentTypesMap ) {
610- typeName = typeName . trim ( ) ;
618+ const trimmedTypeName = typeName . trim ( ) ;
611619
612620 // Check if it's in our component types map
613- if ( componentTypesMap [ typeName ] ) {
614- return componentTypesMap [ typeName ] ;
621+ if ( componentTypesMap [ trimmedTypeName ] ) {
622+ return componentTypesMap [ trimmedTypeName ] ;
615623 }
616624
617625 // Handle special checkout types
618626 if (
619- typeName === 'AnyCheckoutComponent' ||
620- typeName === 'AnyComponent' ||
621- typeName === 'AnyThankYouComponent'
627+ trimmedTypeName === 'AnyCheckoutComponent' ||
628+ trimmedTypeName === 'AnyComponent' ||
629+ trimmedTypeName === 'AnyThankYouComponent'
622630 ) {
623631 return parseCheckoutComponents ( ) ;
624632 }
625633
626634 // Check if it's a quoted string literal
627- const quotedMatch = typeName . match ( / ^ ' ( [ ^ ' ] + ) ' $ / ) ;
635+ const quotedMatch = trimmedTypeName . match ( / ^ ' ( [ ^ ' ] + ) ' $ / ) ;
628636 if ( quotedMatch ) {
629637 return [ quotedMatch [ 1 ] ] ;
630638 }
0 commit comments