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
11 changes: 6 additions & 5 deletions lib/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ function loadNamed(rootDir, env, name, mergeFn) {
* @returns {Array.<String>} Array of absolute file paths.
*/
function findConfigFiles(appRootDir, env, name) {
var candidates = [];
var master = ifExists(name + '.json');
if (!master) return [];

var candidates = [
master,
if (master) {
candidates.push(master);
}
candidates.push(
ifExistsWithAnyExt(name + '.local'),
ifExistsWithAnyExt(name + '.' + env)
];
);

return candidates.filter(function(c) { return c !== undefined; });

Expand Down
19 changes: 19 additions & 0 deletions test/compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ describe('compiler', function() {
expect(actualLoadOrder, 'load order').to.eql(expectedLoadOrder);
});

it('accepts alternative .js config files', function() {
appdir.createConfigFilesSync();
// delete generated config.json
// It shouldn't be needed when an alternative config is supplied
appdir.deleteConfigFileSync('config.json');

appdir.writeFileSync('config.local.js',
'module.exports = ' +
'{ port: 3000, host: "127.0.0.1", restApiRoot: "/api" };');

var instructions = boot.compile(appdir.PATH);

expect(instructions.config).to.eql({
port: 3000,
host: '127.0.0.1',
restApiRoot: '/api'
});
});

it('supports .js for custom datasource config files', function() {
appdir.createConfigFilesSync();
appdir.writeFileSync('datasources.local.js',
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/appdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ appdir.writeFileSync = function(name, content) {
fs.writeFileSync(filePath, content, 'utf-8');
return filePath;
};

appdir.deleteConfigFileSync = function(name) {
var filePath = path.resolve(PATH, name);
return fs.removeSync(filePath);
};