@@ -121,14 +121,35 @@ function generateIndexFiles(abisDir: string, contracts: ContractInfo[]): void {
121121 contractsByDir . get ( dir ) ! . push ( contract ) ;
122122 }
123123
124- // Sort directories for consistent output
125- const sortedDirs = Array . from ( contractsByDir . keys ( ) ) . sort ( ) ;
124+ // Find all directories that need index files (including intermediate ones)
125+ const allDirs = new Set < string > ( ) ;
126126
127- // Generate index.ts for each directory that has contracts
128- for ( const dir of sortedDirs ) {
129- if ( dir === '.' ) continue ; // Skip root directory for now
127+ for ( const contract of contracts ) {
128+ const dir = path . dirname ( contract . srcPath ) ;
129+ const parts = dir . split ( path . sep ) ;
130+
131+ // Add all parent directories
132+ for ( let i = 1 ; i <= parts . length ; i ++ ) {
133+ const parentDir = parts . slice ( 0 , i ) . join ( path . sep ) ;
134+ if ( parentDir !== '.' ) {
135+ allDirs . add ( parentDir ) ;
136+ }
137+ }
138+ }
130139
131- const dirContracts = contractsByDir . get ( dir ) ! ;
140+ // Sort directories by depth (deepest first) to ensure subdirectories are processed before parents
141+ const sortedDirs = Array . from ( allDirs ) . sort ( ( a , b ) => {
142+ const depthA = a . split ( path . sep ) . length ;
143+ const depthB = b . split ( path . sep ) . length ;
144+ if ( depthA !== depthB ) {
145+ return depthB - depthA ; // Deeper directories first
146+ }
147+ return a . localeCompare ( b ) ;
148+ } ) ;
149+
150+ // Generate index.ts for each directory
151+ for ( const dir of sortedDirs ) {
152+ const dirContracts = contractsByDir . get ( dir ) || [ ] ;
132153 generateDirectoryIndex ( abisDir , dir , dirContracts , contracts ) ;
133154 }
134155
0 commit comments