@@ -31,7 +31,7 @@ const ERROR_READING_FILE = 'Error reading file';
3131const ERROR_NO_DATA_SOURCES_FOUND = 'No datasources found in' ;
3232const ERROR_NO_MODELS_FOUND = 'No models found in' ;
3333const ERROR_NO_MODEL_SELECTED = 'You did not select a valid model' ;
34- const ERROR_NO_DIRECTORY = "couldn't find the directory" ;
34+ const ERROR_NO_DIRECTORY = 'The directory was not found' ;
3535
3636module . exports = class RepositoryGenerator extends ArtifactGenerator {
3737 // Note: arguments and options should be defined in the constructor.
@@ -140,7 +140,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
140140
141141 _setupGenerator ( ) {
142142 this . artifactInfo = {
143- type : 'datasource to use ' ,
143+ type : 'repository ' ,
144144 rootDir : 'src' ,
145145 } ;
146146
@@ -171,6 +171,12 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
171171 description : 'A valid ID property name for the specified model' ,
172172 } ) ;
173173
174+ this . option ( 'datasource' , {
175+ type : String ,
176+ required : false ,
177+ description : 'A valid datasource name' ,
178+ } ) ;
179+
174180 return super . _setupGenerator ( ) ;
175181 }
176182
@@ -212,8 +218,8 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
212218 let datasourcesList ;
213219
214220 // grab the datasourcename from the command line
215- cmdDatasourceName = this . options . name
216- ? utils . toClassName ( this . options . name ) + 'Datasource'
221+ cmdDatasourceName = this . options . datasource
222+ ? utils . toClassName ( this . options . datasource ) + 'Datasource'
217223 : '' ;
218224
219225 debug ( `command line datasource is ${ cmdDatasourceName } ` ) ;
@@ -344,6 +350,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
344350
345351 async promptModelId ( ) {
346352 if ( this . shouldExit ( ) ) return false ;
353+ let idType ;
347354
348355 debug ( `Model ID property name from command line: ${ this . options . id } ` ) ;
349356 debug ( `Selected Models: ${ this . artifactInfo . modelNameList } ` ) ;
@@ -364,26 +371,22 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
364371 } ,
365372 ] ;
366373
367- let idType = await this . _getModelIdType ( item ) ;
368-
369- /**
370- * fallback by asking the user for ID property name if the user
371- * didn't supplied any from the command line. If we inferred it, then
372- * the supplied argument is ignored
373- */
374- if ( idType === null ) {
375- if ( this . options . id ) {
376- idType = this . options . id ;
377- /** make sure it is only used once, in case user selected more
378- * than one model.
379- */
380- delete this . options . id ;
381- } else {
374+ // user supplied the id from the command line
375+ if ( this . options . id ) {
376+ debug ( `passing thru this.options.id with value : ${ this . options . id } ` ) ;
377+
378+ idType = this . options . id ;
379+ /** make sure it is only used once, in case user selected more
380+ * than one model.
381+ */
382+ delete this . options . id ;
383+ } else {
384+ idType = await this . _getModelIdType ( item ) ;
385+ if ( idType === null ) {
382386 const answer = await this . prompt ( prompts ) ;
383387 idType = answer . propertyName ;
384388 }
385389 }
386-
387390 this . artifactInfo . idType = idType ;
388391 // Generate this repository
389392 await this . _scaffold ( ) ;
@@ -394,12 +397,20 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
394397 async _scaffold ( ) {
395398 if ( this . shouldExit ( ) ) return false ;
396399
397- this . artifactInfo . className = utils . toClassName (
398- this . artifactInfo . modelName ,
399- ) ;
400+ if ( this . options . name ) {
401+ this . artifactInfo . className = utils . toClassName ( this . options . name ) ;
402+ this . artifactInfo . outFile =
403+ utils . kebabCase ( this . options . name ) + '.repository.ts' ;
400404
401- this . artifactInfo . outFile =
402- utils . kebabCase ( this . artifactInfo . modelName ) + '.repository.ts' ;
405+ // make sure the name supplied from cmd line is only used once
406+ delete this . options . name ;
407+ } else {
408+ this . artifactInfo . className = utils . toClassName (
409+ this . artifactInfo . modelName ,
410+ ) ;
411+ this . artifactInfo . outFile =
412+ utils . kebabCase ( this . artifactInfo . modelName ) + '.repository.ts' ;
413+ }
403414
404415 if ( debug . enabled ) {
405416 debug ( `Artifact output filename set to: ${ this . artifactInfo . outFile } ` ) ;
0 commit comments