+ add the config file formats supports to any configs on plugin-base
This commit is contained in:
parent
5a4c5e5ddf
commit
fa45ce947d
|
@ -0,0 +1,8 @@
|
|||
var loadConfig = require('load-config-file');
|
||||
|
||||
// loadConfig.register('.json', JSON.parse);
|
||||
loadConfig.register(['.json', '.js'], function(ctx, opt, file){
|
||||
return require(file);
|
||||
});
|
||||
|
||||
module.exports = loadConfig;
|
|
@ -12,6 +12,7 @@ var assert = require('assert');
|
|||
var _ = require('lodash');
|
||||
var util = require('./utils');
|
||||
var g = require('./globalize');
|
||||
var loadConfig = require('./load-config');
|
||||
|
||||
module.exports = PluginBase;
|
||||
|
||||
|
@ -92,17 +93,23 @@ PluginBase.prototype.loadNamed = function(rootDir, env, name) {
|
|||
* @returns {Array.<String>} Array of absolute file paths.
|
||||
*/
|
||||
PluginBase.prototype.findConfigFiles = function(rootDir, env, name, exts) {
|
||||
var master = ifExists(name + '.json');
|
||||
if (!master && (ifExistsWithAnyExt(name + '.local') ||
|
||||
ifExistsWithAnyExt(name + '.' + env))) {
|
||||
var master;
|
||||
var vExts = Object.keys(loadConfig.prototype.configurators);
|
||||
for (var ext of vExts) {
|
||||
master = ifExists(name + ext);
|
||||
if (master) break;
|
||||
}
|
||||
|
||||
if (!master && (ifExistsWithAnyExt(name + '.local', vExts) ||
|
||||
ifExistsWithAnyExt(name + '.' + env, vExts))) {
|
||||
g.warn('WARNING: Main config file "%s{{.json}}" is missing', name);
|
||||
}
|
||||
if (!master) return [];
|
||||
|
||||
var candidates = [
|
||||
master,
|
||||
ifExistsWithAnyExt(name + '.local'),
|
||||
ifExistsWithAnyExt(name + '.' + env),
|
||||
ifExistsWithAnyExt(name + '.local', vExts),
|
||||
ifExistsWithAnyExt(name + '.' + env, vExts),
|
||||
];
|
||||
|
||||
return candidates.filter(function(c) {
|
||||
|
@ -114,11 +121,11 @@ PluginBase.prototype.findConfigFiles = function(rootDir, env, name, exts) {
|
|||
return util.fileExistsSync(filePath) ? filePath : undefined;
|
||||
}
|
||||
|
||||
function ifExistsWithAnyExt(fileName) {
|
||||
var extensions = exts || ['js', 'json'];
|
||||
function ifExistsWithAnyExt(fileName, extensions) {
|
||||
extensions = extensions || ['.js', '.json'];
|
||||
var file;
|
||||
for (var i = 0, n = extensions.length; i < n; i++) {
|
||||
file = ifExists(fileName + '.' + extensions[i]);
|
||||
file = ifExists(fileName + extensions[i]);
|
||||
if (file) {
|
||||
return file;
|
||||
}
|
||||
|
@ -134,7 +141,7 @@ PluginBase.prototype.findConfigFiles = function(rootDir, env, name, exts) {
|
|||
*/
|
||||
PluginBase.prototype._loadConfigFiles = function(files) {
|
||||
return files.map(function(f) {
|
||||
var config = require(f);
|
||||
var config = loadConfig(f);
|
||||
config = _.cloneDeep(config);
|
||||
Object.defineProperty(config, '_filename', {
|
||||
enumerable: false,
|
||||
|
|
|
@ -13,7 +13,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 loadConfig = require('../load-config');
|
||||
|
||||
var tryReadDir = utils.tryReadDir;
|
||||
var assertIsValidConfig = utils.assertIsValidConfig;
|
||||
|
@ -21,8 +21,6 @@ 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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue