@@ -31,7 +31,6 @@ const ERROR_READING_FILE = 'Error reading file';
31
31
const ERROR_NO_DATA_SOURCES_FOUND = 'No datasources found at' ;
32
32
const ERROR_NO_MODELS_FOUND = 'No models found at' ;
33
33
const ERROR_NO_MODEL_SELECTED = 'You did not select a valid model' ;
34
- const ERROR_NO_DIRECTORY = 'The directory was not found' ;
35
34
36
35
module . exports = class RepositoryGenerator extends ArtifactGenerator {
37
36
// Note: arguments and options should be defined in the constructor.
@@ -66,8 +65,9 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
66
65
if ( ! this . artifactInfo . dataSourceClass ) {
67
66
return ;
68
67
}
69
- let result = this . _isConnectorOfType (
68
+ let result = utils . isConnectorOfType (
70
69
KEY_VALUE_CONNECTOR ,
70
+ this . artifactInfo . datasourcesDir ,
71
71
this . artifactInfo . dataSourceClass ,
72
72
) ;
73
73
debug ( `KeyValue Connector: ${ result } ` ) ;
@@ -89,45 +89,6 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
89
89
utils . toClassName ( this . artifactInfo . dataSourceName ) + 'DataSource' ;
90
90
}
91
91
92
- /**
93
- * load the connectors available and check if the basedModel matches any
94
- * connectorType supplied for the given connector name
95
- * @param {string } connectorType single or a comma separated string array
96
- */
97
- _isConnectorOfType ( connectorType , dataSourceClass ) {
98
- debug ( `calling isConnectorType ${ connectorType } ` ) ;
99
- let jsonFileContent = '' ;
100
- let result = false ;
101
-
102
- if ( ! dataSourceClass ) {
103
- return false ;
104
- }
105
- let datasourceJSONFile = path . join (
106
- this . artifactInfo . datasourcesDir ,
107
- dataSourceClass . replace ( 'Datasource' , '.datasource.json' ) . toLowerCase ( ) ,
108
- ) ;
109
-
110
- try {
111
- jsonFileContent = this . fs . readJSON ( datasourceJSONFile , { } ) ;
112
- } catch ( err ) {
113
- debug ( `${ ERROR_READING_FILE } ${ datasourceJSONFile } : ${ err . message } ` ) ;
114
- return this . exit ( err ) ;
115
- }
116
-
117
- for ( let connector of Object . values ( connectors ) ) {
118
- const matchedConnector =
119
- jsonFileContent . connector === connector . name ||
120
- jsonFileContent . connector === `loopback-connector-${ connector . name } ` ;
121
-
122
- if ( matchedConnector && connectorType . includes ( connector . baseModel ) ) {
123
- result = true ;
124
- break ;
125
- }
126
- }
127
-
128
- return result ;
129
- }
130
-
131
92
_setupGenerator ( ) {
132
93
this . artifactInfo = {
133
94
type : 'repository ' ,
@@ -238,9 +199,10 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
238
199
}
239
200
240
201
const availableDatasources = datasourcesList . filter ( item => {
241
- debug ( `data source unfiltered list : ${ item } ` ) ;
242
- const result = this . _isConnectorOfType (
202
+ debug ( `data source inspecting item : ${ item } ` ) ;
203
+ const result = utils . isConnectorOfType (
243
204
VALID_CONNECTORS_FOR_REPOSITORY ,
205
+ this . artifactInfo . datasourcesDir ,
244
206
item ,
245
207
) ;
246
208
return result ;
0 commit comments