@@ -47,7 +47,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
47
47
let fileContent = '' ;
48
48
let modelFile = path . join (
49
49
this . artifactInfo . modelDir ,
50
- ` ${ utils . kebabCase ( modelName ) } .model.ts` ,
50
+ utils . getModelFileName ( modelName ) ,
51
51
) ;
52
52
try {
53
53
fileContent = this . fs . read ( modelFile , { } ) ;
@@ -63,12 +63,12 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
63
63
* helper method to inspect and validate a repository type
64
64
*/
65
65
async _inferRepositoryType ( ) {
66
- if ( ! this . artifactInfo . dataSourceClassName ) {
66
+ if ( ! this . artifactInfo . dataSourceClass ) {
67
67
return ;
68
68
}
69
69
let result = this . _isConnectorOfType (
70
70
KEY_VALUE_CONNECTOR ,
71
- this . artifactInfo . dataSourceClassName ,
71
+ this . artifactInfo . dataSourceClass ,
72
72
) ;
73
73
debug ( `KeyValue Connector: ${ result } ` ) ;
74
74
@@ -81,17 +81,19 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
81
81
}
82
82
83
83
// assign the data source name to the information artifact
84
- let dataSourceName = this . artifactInfo . dataSourceClassName
84
+ let dataSourceName = this . artifactInfo . dataSourceClass
85
85
. replace ( 'Datasource' , '' )
86
86
. toLowerCase ( ) ;
87
- let dataSourceImportName = this . artifactInfo . dataSourceClassName . replace (
87
+
88
+ let dataSourceClassName = this . artifactInfo . dataSourceClass . replace (
88
89
'Datasource' ,
89
90
'DataSource' ,
90
91
) ;
91
92
92
93
Object . assign ( this . artifactInfo , {
93
- dataSourceImportName : dataSourceImportName ,
94
+ dataSourceClassName : dataSourceClassName ,
94
95
} ) ;
96
+
95
97
Object . assign ( this . artifactInfo , {
96
98
dataSourceName : dataSourceName ,
97
99
} ) ;
@@ -102,19 +104,17 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
102
104
* connectorType supplied for the given connector name
103
105
* @param {string } connectorType single or a comma separated string array
104
106
*/
105
- _isConnectorOfType ( connectorType , dataSourceClassName ) {
107
+ _isConnectorOfType ( connectorType , dataSourceClass ) {
106
108
debug ( `calling isConnectorType ${ connectorType } ` ) ;
107
109
let jsonFileContent = '' ;
108
110
let result = false ;
109
111
110
- if ( ! dataSourceClassName ) {
112
+ if ( ! dataSourceClass ) {
111
113
return false ;
112
114
}
113
115
let datasourceJSONFile = path . join (
114
116
this . artifactInfo . datasourcesDir ,
115
- dataSourceClassName
116
- . replace ( 'Datasource' , '.datasource.json' )
117
- . toLowerCase ( ) ,
117
+ dataSourceClass . replace ( 'Datasource' , '.datasource.json' ) . toLowerCase ( ) ,
118
118
) ;
119
119
120
120
try {
@@ -141,20 +141,20 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
141
141
_setupGenerator ( ) {
142
142
this . artifactInfo = {
143
143
type : 'repository ' ,
144
- rootDir : 'src' ,
144
+ rootDir : utils . sourceRootDir ,
145
145
} ;
146
146
147
147
this . artifactInfo . outDir = path . resolve (
148
148
this . artifactInfo . rootDir ,
149
- 'repositories' ,
149
+ utils . repositoriesDir ,
150
150
) ;
151
151
this . artifactInfo . datasourcesDir = path . resolve (
152
152
this . artifactInfo . rootDir ,
153
- 'datasources' ,
153
+ utils . datasourcesDir ,
154
154
) ;
155
155
this . artifactInfo . modelDir = path . resolve (
156
156
this . artifactInfo . rootDir ,
157
- 'models' ,
157
+ utils . modelsDir ,
158
158
) ;
159
159
160
160
this . artifactInfo . defaultTemplate = REPOSITORY_CRUD_TEMPLATE ;
@@ -230,7 +230,11 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
230
230
'datasource' ,
231
231
true ,
232
232
) ;
233
- debug ( `datasourcesList from src/datasources : ${ datasourcesList } ` ) ;
233
+ debug (
234
+ `datasourcesList from ${ utils . sourceRootDir } /${
235
+ utils . datasourcesDir
236
+ } : ${ datasourcesList } `,
237
+ ) ;
234
238
} catch ( err ) {
235
239
return this . exit ( err ) ;
236
240
}
@@ -244,17 +248,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
244
248
return result ;
245
249
} ) ;
246
250
247
- if ( availableDatasources . includes ( cmdDatasourceName ) ) {
248
- Object . assign ( this . artifactInfo , {
249
- dataSourceClassName : cmdDatasourceName ,
250
- } ) ;
251
- }
252
-
253
- debug (
254
- `artifactInfo.dataSourceClassName ${
255
- this . artifactInfo . dataSourceClassName
256
- } `,
257
- ) ;
251
+ debug ( `artifactInfo.dataSourceClass ${ this . artifactInfo . dataSourceClass } ` ) ;
258
252
259
253
if ( availableDatasources . length === 0 ) {
260
254
return this . exit (
@@ -267,13 +261,19 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
267
261
) ;
268
262
}
269
263
264
+ if ( availableDatasources . includes ( cmdDatasourceName ) ) {
265
+ Object . assign ( this . artifactInfo , {
266
+ dataSourceClass : cmdDatasourceName ,
267
+ } ) ;
268
+ }
269
+
270
270
return this . prompt ( [
271
271
{
272
272
type : 'list' ,
273
- name : 'dataSourceClassName ' ,
273
+ name : 'dataSourceClass ' ,
274
274
message : PROMPT_MESSAGE_DATA_SOURCE ,
275
275
choices : availableDatasources ,
276
- when : ! this . artifactInfo . dataSourceClassName ,
276
+ when : ! this . artifactInfo . dataSourceClass ,
277
277
default : availableDatasources [ 0 ] ,
278
278
validate : utils . validateClassName ,
279
279
} ,
@@ -310,7 +310,11 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
310
310
311
311
this . options . model = utils . toClassName ( this . options . model ) ;
312
312
// assign the model name from the command line only if it is valid
313
- if ( modelList . length > 0 && modelList . includes ( this . options . model ) ) {
313
+ if (
314
+ modelList &&
315
+ modelList . length > 0 &&
316
+ modelList . includes ( this . options . model )
317
+ ) {
314
318
Object . assign ( this . artifactInfo , { modelNameList : [ this . options . model ] } ) ;
315
319
} else {
316
320
modelList = [ ] ;
@@ -399,25 +403,31 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
399
403
400
404
if ( this . options . name ) {
401
405
this . artifactInfo . className = utils . toClassName ( this . options . name ) ;
402
- this . artifactInfo . outFile =
403
- utils . kebabCase ( this . options . name ) + '.repository.ts' ;
406
+ this . artifactInfo . outFile = utils . getRepositoryFileName (
407
+ this . options . name ,
408
+ ) ;
404
409
405
410
// make sure the name supplied from cmd line is only used once
406
411
delete this . options . name ;
407
412
} else {
408
413
this . artifactInfo . className = utils . toClassName (
409
414
this . artifactInfo . modelName ,
410
415
) ;
411
- this . artifactInfo . outFile =
412
- utils . kebabCase ( this . artifactInfo . modelName ) + '.repository.ts' ;
416
+ this . artifactInfo . outFile = utils . getRepositoryFileName (
417
+ this . artifactInfo . modelName ,
418
+ ) ;
413
419
}
414
420
415
421
if ( debug . enabled ) {
416
422
debug ( `Artifact output filename set to: ${ this . artifactInfo . outFile } ` ) ;
417
423
}
418
424
419
425
const source = this . templatePath (
420
- path . join ( 'src' , 'repositories' , this . artifactInfo . defaultTemplate ) ,
426
+ path . join (
427
+ utils . sourceRootDir ,
428
+ utils . repositoriesDir ,
429
+ this . artifactInfo . defaultTemplate ,
430
+ ) ,
421
431
) ;
422
432
423
433
if ( debug . enabled ) {
0 commit comments