Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,49 @@ var addInstructionsToBrowserify = require('./lib/bundler');
* 2. Configures Models from the `model-config.json` file in the application
* root directory.
*
* 3. Configures the LoopBack Application object from the `config.json` file
* in the application root directory. These properties can be accessed
* using app.get('propname').
*
* If the argument is an object, then it looks for `models`, `dataSources`,
* and `appRootDir` properties of the object.
* 'config', modelRootDir, dsRootDir, appConfigRootDir and `appRootDir`
* properties of the object.
* If the object has no `appRootDir` property then it sets the current working
* directory as the application root directory.
* The execution environment, {env}, is establised from, in order,
* 'options.env',
* Process.env.NODE_ENV,
* the literal 'development'
*
* Then it:
*
* 1. Creates DataSources from the `options.dataSources` object.
* 1. Creates DataSources from the `options.dataSources` object, if provided;
* otherwise, it searches for the files
* 'datasources.json',
* 'datasources.local.js' or 'datasources.local.json' (only one),
* 'datasources.{env}.js' or 'datasources.{env}.json' (only one)
* in the directory designated by 'options.dsRootDir', if present, or the
* application root directory. It merges the data source definitions from
* the files found.
*
* 2. Creates Models from the `options.models` object, if provided;
* otherwise, it searches for the files
* 'model-config.json',
* 'model-config.local.js' or 'model-config.local.json' (only one),
* 'model-config.{env}.js' or 'model-config.{env}.json' (only one)
* in the directory designated by 'options.modelsRootDir', if present, or
* the application root directory. It merges the model definitions from the
* files found.
*
* 2. Configures Models from the `options.models` object.
* 3. Configures the Application object from the `options.config` object,
* if provided;
* otherwise, it searches for the files
* 'config.json',
* 'config.local.js' or 'config.local.json' (only one),
* 'config.{env}.js' or 'config.{env}.json' (only one)
* in the directory designated by 'options.appConfigRootDir', if present, or
* the application root directory. It merges the properties from the files
* found.
*
* In both cases, the function loads JavaScript files in the
* `/boot` subdirectory of the application root directory with `require()`.
Expand Down
4 changes: 3 additions & 1 deletion lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ 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.config || ConfigLoader.loadAppConfig(appRootDir, env);
var appConfigRootDir = options.appConfigRootDir || appRootDir;
var appConfig = options.config ||
ConfigLoader.loadAppConfig(appConfigRootDir, env);
assertIsValidConfig('app', appConfig);

var modelsRootDir = options.modelsRootDir || appRootDir;
Expand Down
17 changes: 17 additions & 0 deletions test/compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ describe('compiler', function() {
expect(appConfig).to.have.property('fromJs', true);
});

it('supports `appConfigRootDir` option', function() {
appdir.createConfigFilesSync({port:3000});

var customDir = path.resolve(appdir.PATH, 'custom');
fs.mkdirsSync(customDir);
fs.renameSync(
path.resolve(appdir.PATH, 'config.json'),
path.resolve(customDir, 'config.json'));

var instructions = boot.compile({
appRootDir: appdir.PATH,
appConfigRootDir: path.resolve(appdir.PATH, 'custom')
});

expect(instructions.config).to.have.property('port');
});

it('supports `dsRootDir` option', function() {
appdir.createConfigFilesSync();

Expand Down