+ make model definition file use more config formats via load-config-file

This commit is contained in:
Riceball LEE 2017-01-21 18:31:59 +08:00
parent 79d9ddb835
commit 8a5ebdadbe
1 changed files with 5 additions and 2 deletions
lib/plugins

View File

@ -11,6 +11,7 @@ var debug = require('debug')('loopback:boot:model');
var _ = require('lodash');
var toposort = require('toposort');
var utils = require('../utils');
var loadConfig = require('load-config-file');
var tryReadDir = utils.tryReadDir;
var assertIsValidConfig = utils.assertIsValidConfig;
@ -18,6 +19,8 @@ var tryResolveAppPath = utils.tryResolveAppPath;
var fixFileExtension = utils.fixFileExtension;
var g = require('../globalize');
loadConfig.register('.json', JSON.parse);
module.exports = function(options) {
return new Model(options);
};
@ -186,7 +189,7 @@ function findModelDefinitions(rootDir, sources) {
files
.filter(function(f) {
return f[0] !== '_' && path.extname(f) === '.json';
return f[0] !== '_' && loadConfig.prototype.configurators[path.extname(f)] != null;
})
.forEach(function(f) {
var fullPath = path.resolve(srcDir, f);
@ -205,8 +208,8 @@ function findModelDefinitions(rootDir, sources) {
}
function loadModelDefinition(rootDir, jsonFile, allFiles) {
var definition = require(jsonFile);
var basename = path.basename(jsonFile, path.extname(jsonFile));
var definition = loadConfig(basename);
definition.name = definition.name || _.upperFirst(_.camelCase(basename));
// find a matching file with a supported extension like `.js` or `.coffee`