Rename `models.json` to `model-config.json`
The name `models.json` was potentially confusing since there are no models defined in that file.
This commit is contained in:
parent
3522f117c0
commit
3129f6495c
10
index.js
10
index.js
|
@ -20,7 +20,7 @@ var addInstructionsToBrowserify = require('./lib/bundler');
|
|||
* 1. Creates DataSources from the `datasources.json` file in the application
|
||||
* root directory.
|
||||
*
|
||||
* 2. Configures Models from the `models.json` file in the application
|
||||
* 2. Configures Models from the `model-config.json` file in the application
|
||||
* root directory.
|
||||
*
|
||||
* If the argument is an object, then it looks for `models`, `dataSources`,
|
||||
|
@ -37,9 +37,9 @@ var addInstructionsToBrowserify = require('./lib/bundler');
|
|||
* `/boot` subdirectory of the application root directory with `require()`.
|
||||
*
|
||||
* **NOTE:** The version 2.0 of loopback-boot changed the way how models
|
||||
* are created. The `models.json` file contains only configuration options like
|
||||
* dataSource and extra relations. To define a model, create a per-model
|
||||
* JSON file in `models/` directory.
|
||||
* are created. The `model-config.json` file contains only configuration
|
||||
* options like dataSource and extra relations. To define a model,
|
||||
* create a per-model JSON file in `models/` directory.
|
||||
*
|
||||
* **NOTE:** Mixing `bootLoopBackApp(app, bootConfig)` and
|
||||
* `app.model(name, modelConfig)` in multiple
|
||||
|
@ -58,7 +58,7 @@ var addInstructionsToBrowserify = require('./lib/bundler');
|
|||
* @property {Object} [models] Object containing `Model` configurations.
|
||||
* @property {Object} [dataSources] Object containing `DataSource` definitions.
|
||||
* @property {String} [modelsRootDir] Directory to use when loading
|
||||
* `models.json`. Defaults to `appRootDir`.
|
||||
* `model-config.json`. Defaults to `appRootDir`.
|
||||
* @property {String} [dsRootDir] Directory to use when loading
|
||||
* `datasources.json`. Defaults to `appRootDir`.
|
||||
* @property {String} [env] Environment type, defaults to `process.env.NODE_ENV`
|
||||
|
|
|
@ -78,7 +78,7 @@ function assertIsValidModelConfig(config) {
|
|||
|
||||
if (unsupported) {
|
||||
throw new Error(
|
||||
'The data in models.json is in the unsupported 1.x format.');
|
||||
'The data in model-config.json is in the unsupported 1.x format.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ ConfigLoader.loadDataSources = function(rootDir, env) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Load models config from `models.json` and friends.
|
||||
* Load model config from `model-config.json` and friends.
|
||||
* @param {String} rootDir Directory where to look for files.
|
||||
* @param {String} env Environment, usually `process.env.NODE_ENV`
|
||||
* @returns {Object}
|
||||
*/
|
||||
ConfigLoader.loadModels = function(rootDir, env) {
|
||||
/*jshint unused:false */
|
||||
return tryReadJsonConfig(rootDir, 'models') || {};
|
||||
return tryReadJsonConfig(rootDir, 'model-config') || {};
|
||||
};
|
||||
|
||||
/*-- Implementation --*/
|
||||
|
|
|
@ -198,7 +198,7 @@ describe('compiler', function() {
|
|||
|
||||
it('supports `modelsRootDir` option', function() {
|
||||
appdir.createConfigFilesSync();
|
||||
appdir.writeConfigFileSync('custom/models.json', {
|
||||
appdir.writeConfigFileSync('custom/model-config.json', {
|
||||
foo: { dataSource: 'db' }
|
||||
});
|
||||
|
||||
|
@ -228,7 +228,7 @@ describe('compiler', function() {
|
|||
expect(instructions.files).to.not.have.property('models');
|
||||
});
|
||||
|
||||
it('throws when models.json contains `properties` from 1.x', function() {
|
||||
it('throws when models-config.json contains 1.x `properties`', function() {
|
||||
appdir.createConfigFilesSync({}, {}, {
|
||||
foo: { properties: { name: 'string' } }
|
||||
});
|
||||
|
@ -237,7 +237,7 @@ describe('compiler', function() {
|
|||
.to.throw(/unsupported 1\.x format/);
|
||||
});
|
||||
|
||||
it('throws when models.json contains `options.base` from 1.x', function() {
|
||||
it('throws when model-config.json contains 1.x `options.base`', function() {
|
||||
appdir.createConfigFilesSync({}, {}, {
|
||||
Customer: { options: { base: 'User' } }
|
||||
});
|
||||
|
@ -268,7 +268,7 @@ describe('compiler', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('supports `sources` option in `models.json`', function() {
|
||||
it('supports `sources` option in `model-config.json`', function() {
|
||||
appdir.createConfigFilesSync({}, {}, {
|
||||
_meta: {
|
||||
sources: ['./custom-models']
|
||||
|
@ -313,7 +313,7 @@ describe('compiler', function() {
|
|||
}]);
|
||||
});
|
||||
|
||||
it('excludes models not listed in `models.json`', function() {
|
||||
it('excludes models not listed in `model-config.json`', function() {
|
||||
appdir.createConfigFilesSync({}, {}, {
|
||||
Car: { dataSource: 'db' }
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ appdir.createConfigFilesSync = function(appConfig, dataSources, models) {
|
|||
|
||||
models = extend({
|
||||
}, models);
|
||||
appdir.writeConfigFileSync ('models.json', models);
|
||||
appdir.writeConfigFileSync ('model-config.json', models);
|
||||
};
|
||||
|
||||
appdir.writeConfigFileSync = function(name, json) {
|
||||
|
|
Loading…
Reference in New Issue