@@ -58,6 +58,7 @@ app._models = [];
58
58
app . model = function ( Model , config ) {
59
59
if ( arguments . length === 1 ) {
60
60
assert ( typeof Model === 'function' , 'app.model(Model) => Model must be a function / constructor' ) ;
61
+ assert ( Model . pluralModelName , 'Model must have a "pluralModelName" property' ) ;
61
62
this . remotes ( ) . exports [ Model . pluralModelName ] = Model ;
62
63
this . _models . push ( Model ) ;
63
64
Model . shared = true ;
@@ -66,7 +67,7 @@ app.model = function (Model, config) {
66
67
return ;
67
68
}
68
69
var modelName = Model ;
69
- assert ( typeof modelName === 'string' , 'app.model(name, properties, options ) => name must be a string' ) ;
70
+ assert ( typeof modelName === 'string' , 'app.model(name, config ) => "name" name must be a string' ) ;
70
71
71
72
Model =
72
73
this . models [ modelName ] =
@@ -162,22 +163,26 @@ app.dataSources = app.datasources = {};
162
163
*/
163
164
164
165
app . boot = function ( options ) {
165
- var app = this ;
166
166
options = options || { } ;
167
- var cwd = options . cwd = options . cwd || process . cwd ( ) ;
167
+
168
+ if ( typeof options === 'string' ) {
169
+ options = { appRootDir : options } ;
170
+ }
171
+ var app = this ;
172
+ var appRootDir = options . appRootDir = options . appRootDir || process . cwd ( ) ;
168
173
var ctx = { } ;
169
174
var appConfig = options . app ;
170
175
var modelConfig = options . models ;
171
176
var dataSourceConfig = options . dataSources ;
172
177
173
178
if ( ! appConfig ) {
174
- appConfig = tryReadConfig ( cwd , 'app' ) || { } ;
179
+ appConfig = tryReadConfig ( appRootDir , 'app' ) || { } ;
175
180
}
176
181
if ( ! modelConfig ) {
177
- modelConfig = tryReadConfig ( cwd , 'models' ) || { } ;
182
+ modelConfig = tryReadConfig ( appRootDir , 'models' ) || { } ;
178
183
}
179
184
if ( ! dataSourceConfig ) {
180
- dataSourceConfig = tryReadConfig ( cwd , 'datasources' ) || { } ;
185
+ dataSourceConfig = tryReadConfig ( appRootDir , 'datasources' ) || { } ;
181
186
}
182
187
183
188
assertIsValidConfig ( 'app' , appConfig ) ;
@@ -206,8 +211,7 @@ app.boot = function(options) {
206
211
} ) ;
207
212
208
213
// require directories
209
- var requiredModels = requireDir ( path . join ( cwd , 'models' ) ) ;
210
- var requiredDataSources = requireDir ( path . join ( cwd , 'datasources' ) ) ;
214
+ var requiredModels = requireDir ( path . join ( appRootDir , 'models' ) ) ;
211
215
}
212
216
213
217
function assertIsValidConfig ( name , config ) {
@@ -224,10 +228,6 @@ function forEachKeyedObject(obj, fn) {
224
228
} ) ;
225
229
}
226
230
227
- function requireDirAs ( type , dir ) {
228
- return requireDir ( dir ) ;
229
- }
230
-
231
231
function classify ( str ) {
232
232
return stringUtils . classify ( str ) ;
233
233
}
0 commit comments