@@ -101,14 +101,48 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
101
101
this . artifactInfo . modelDir ,
102
102
utils . getModelFileName ( modelName ) ,
103
103
) ;
104
- try {
105
- fileContent = this . fs . read ( modelFile , { } ) ;
106
- } catch ( err ) {
107
- debug ( `${ ERROR_READING_FILE } ${ modelFile } : ${ err . message } ` ) ;
108
- return this . exit ( err ) ;
104
+
105
+ // Check if the model file exists directly in the modelDir
106
+ if ( fs . existsSync ( modelFile ) ) {
107
+ try {
108
+ fileContent = this . fs . read ( modelFile , { } ) ;
109
+ } catch ( err ) {
110
+ debug ( `${ ERROR_READING_FILE } ${ modelFile } : ${ err . message } ` ) ;
111
+ return this . exit ( err ) ;
112
+ }
113
+
114
+ return tsquery . getIdFromModel ( fileContent ) ;
115
+ }
116
+
117
+ // If the model file is not found directly, search in subdirectories
118
+ const subdirectories = await utils . getSubdirectories (
119
+ this . artifactInfo . modelDir ,
120
+ ) ;
121
+
122
+ for ( const subdirectory of subdirectories ) {
123
+ const subdirectoryModelFile = path . join (
124
+ subdirectory ,
125
+ utils . getModelFileName ( modelName ) ,
126
+ ) ;
127
+
128
+ if ( fs . existsSync ( subdirectoryModelFile ) ) {
129
+ try {
130
+ fileContent = this . fs . read ( subdirectoryModelFile , { } ) ;
131
+ } catch ( err ) {
132
+ debug (
133
+ `${ ERROR_READING_FILE } ${ subdirectoryModelFile } : ${ err . message } ` ,
134
+ ) ;
135
+ return this . exit ( err ) ;
136
+ }
137
+
138
+ return tsquery . getIdFromModel ( fileContent ) ;
139
+ }
109
140
}
110
141
111
- return tsquery . getIdFromModel ( fileContent ) ;
142
+ // If the model file is not found in any subdirectory, return an error
143
+ return this . exit (
144
+ new Error ( `Model ${ modelName } not found in any subdirectory.` ) ,
145
+ ) ;
112
146
}
113
147
114
148
/**
@@ -344,7 +378,6 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
344
378
) ;
345
379
modelList = modelList . concat ( subdirectoryModelList ) ;
346
380
} catch ( err ) {
347
- // Handle errors for subdirectory model retrieval
348
381
console . error (
349
382
`Error retrieving models from subdirectory ${ subdirectory } : ${ err } ` ,
350
383
) ;
0 commit comments