Rename `app.json` to `config.json`
The new loopback project layout adds a concept of components like 'rest server' and 'isomorphic client', each component having its own set of boot files. The name `app.json` is confusing, since it is configuring a component, not the app (which is the whole project).
This commit is contained in:
parent
0a0a6f5d01
commit
ac16d92a8b
|
@ -27,7 +27,7 @@ module.exports = function compile(options) {
|
|||
var appRootDir = options.appRootDir = options.appRootDir || process.cwd();
|
||||
var env = options.env || process.env.NODE_ENV || 'development';
|
||||
|
||||
var appConfig = options.app || ConfigLoader.loadAppConfig(appRootDir, env);
|
||||
var appConfig = options.config || ConfigLoader.loadAppConfig(appRootDir, env);
|
||||
assertIsValidConfig('app', appConfig);
|
||||
|
||||
var modelsRootDir = options.modelsRootDir || appRootDir;
|
||||
|
@ -51,7 +51,7 @@ module.exports = function compile(options) {
|
|||
modelsRootDir, modelsConfig, modelSources);
|
||||
|
||||
return {
|
||||
app: appConfig,
|
||||
config: appConfig,
|
||||
dataSources: dataSourcesConfig,
|
||||
models: modelInstructions,
|
||||
files: {
|
||||
|
|
|
@ -10,7 +10,7 @@ var ConfigLoader = exports;
|
|||
* @returns {Object}
|
||||
*/
|
||||
ConfigLoader.loadAppConfig = function(rootDir, env) {
|
||||
return loadNamed(rootDir, env, 'app', mergeAppConfig);
|
||||
return loadNamed(rootDir, env, 'config', mergeAppConfig);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,7 @@ function setHost(app, instructions) {
|
|||
process.env.OPENSHIFT_SLS_IP ||
|
||||
process.env.OPENSHIFT_NODEJS_IP ||
|
||||
process.env.HOST ||
|
||||
instructions.app.host ||
|
||||
instructions.config.host ||
|
||||
process.env.npm_package_config_host ||
|
||||
app.get('host');
|
||||
|
||||
|
@ -69,7 +69,7 @@ function setPort(app, instructions) {
|
|||
process.env.OPENSHIFT_SLS_PORT,
|
||||
process.env.OPENSHIFT_NODEJS_PORT,
|
||||
process.env.PORT,
|
||||
instructions.app.port,
|
||||
instructions.config.port,
|
||||
process.env.npm_package_config_port,
|
||||
app.get('port'),
|
||||
3000
|
||||
|
@ -85,7 +85,7 @@ function setPort(app, instructions) {
|
|||
|
||||
function setApiRoot(app, instructions) {
|
||||
var restApiRoot =
|
||||
instructions.app.restApiRoot ||
|
||||
instructions.config.restApiRoot ||
|
||||
app.get('restApiRoot') ||
|
||||
'/api';
|
||||
|
||||
|
@ -98,7 +98,7 @@ function setApiRoot(app, instructions) {
|
|||
}
|
||||
|
||||
function applyAppConfig(app, instructions) {
|
||||
var appConfig = instructions.app;
|
||||
var appConfig = instructions.config;
|
||||
for(var configKey in appConfig) {
|
||||
var cur = app.get(configKey);
|
||||
if(cur === undefined || cur === null) {
|
||||
|
@ -195,7 +195,7 @@ function enableAnonymousSwagger(app, instructions) {
|
|||
var swagger = app.remotes().exports.swagger;
|
||||
if (!swagger) return;
|
||||
|
||||
var appConfig = instructions.app;
|
||||
var appConfig = instructions.config;
|
||||
var requireTokenForSwagger = appConfig.swagger &&
|
||||
appConfig.swagger.requireToken;
|
||||
swagger.requireToken = requireTokenForSwagger || false;
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('compiler', function() {
|
|||
var options, instructions, appConfig;
|
||||
beforeEach(function() {
|
||||
options = {
|
||||
app: {
|
||||
config: {
|
||||
port: 3000,
|
||||
host: '127.0.0.1',
|
||||
restApiRoot: '/rest-api',
|
||||
|
@ -35,7 +35,7 @@ describe('compiler', function() {
|
|||
}
|
||||
};
|
||||
instructions = boot.compile(options);
|
||||
appConfig = instructions.app;
|
||||
appConfig = instructions.config;
|
||||
});
|
||||
|
||||
it('has port setting', function() {
|
||||
|
@ -148,13 +148,13 @@ describe('compiler', function() {
|
|||
it('merges app configs from multiple files', function() {
|
||||
appdir.createConfigFilesSync();
|
||||
|
||||
appdir.writeConfigFileSync('app.local.json', { cfgLocal: 'applied' });
|
||||
appdir.writeConfigFileSync('config.local.json', { cfgLocal: 'applied' });
|
||||
|
||||
var env = process.env.NODE_ENV || 'development';
|
||||
appdir.writeConfigFileSync('app.' + env + '.json', { cfgEnv: 'applied' });
|
||||
appdir.writeConfigFileSync('config.' + env + '.json', { cfgEnv: 'applied' });
|
||||
|
||||
var instructions = boot.compile(appdir.PATH);
|
||||
var appConfig = instructions.app;
|
||||
var appConfig = instructions.config;
|
||||
|
||||
expect(appConfig).to.have.property('cfgLocal', 'applied');
|
||||
expect(appConfig).to.have.property('cfgEnv', 'applied');
|
||||
|
@ -169,11 +169,11 @@ describe('compiler', function() {
|
|||
|
||||
it('supports .js for custom app config files', function() {
|
||||
appdir.createConfigFilesSync();
|
||||
appdir.writeFileSync('app.local.js',
|
||||
appdir.writeFileSync('config.local.js',
|
||||
'module.exports = { fromJs: true };');
|
||||
|
||||
var instructions = boot.compile(appdir.PATH);
|
||||
var appConfig = instructions.app;
|
||||
var appConfig = instructions.config;
|
||||
|
||||
expect(appConfig).to.have.property('fromJs', true);
|
||||
});
|
||||
|
|
|
@ -20,7 +20,7 @@ describe('executor', function() {
|
|||
});
|
||||
|
||||
var dummyInstructions = someInstructions({
|
||||
app: {
|
||||
config: {
|
||||
port: 3000,
|
||||
host: '127.0.0.1',
|
||||
restApiRoot: '/rest-api',
|
||||
|
@ -174,7 +174,7 @@ describe('executor', function() {
|
|||
function bootWithDefaults() {
|
||||
app = loopback();
|
||||
boot.execute(app, someInstructions({
|
||||
app: {
|
||||
config: {
|
||||
port: undefined,
|
||||
host: undefined
|
||||
}
|
||||
|
@ -242,12 +242,12 @@ describe('executor', function() {
|
|||
}
|
||||
|
||||
it('should honor 0 for free port', function() {
|
||||
boot.execute(app, someInstructions({ app: { port: 0 } }));
|
||||
boot.execute(app, someInstructions({ config: { port: 0 } }));
|
||||
assert.equal(app.get('port'), 0);
|
||||
});
|
||||
|
||||
it('should default to port 3000', function() {
|
||||
boot.execute(app, someInstructions({ app: { port: undefined } }));
|
||||
boot.execute(app, someInstructions({ config: { port: undefined } }));
|
||||
assert.equal(app.get('port'), 3000);
|
||||
});
|
||||
});
|
||||
|
@ -282,7 +282,7 @@ assert.isFunc = function (obj, name) {
|
|||
|
||||
function someInstructions(values) {
|
||||
var result = {
|
||||
app: values.app || {},
|
||||
config: values.config || {},
|
||||
models: values.models || [],
|
||||
dataSources: values.dataSources || { db: { connector: 'memory' } },
|
||||
files: {
|
||||
|
|
|
@ -22,7 +22,7 @@ appdir.init = function(cb) {
|
|||
appdir.createConfigFilesSync = function(appConfig, dataSources, models) {
|
||||
appConfig = extend({
|
||||
}, appConfig);
|
||||
appdir.writeConfigFileSync ('app.json', appConfig);
|
||||
appdir.writeConfigFileSync ('config.json', appConfig);
|
||||
|
||||
dataSources = extend({
|
||||
db: {
|
||||
|
|
Loading…
Reference in New Issue