diff --git a/lib/config-loader.js b/lib/config-loader.js index b8a6dfe..c6d28fa 100644 --- a/lib/config-loader.js +++ b/lib/config-loader.js @@ -58,14 +58,15 @@ function loadNamed(rootDir, env, name, mergeFn) { * @returns {Array.} 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; }); diff --git a/test/compiler.test.js b/test/compiler.test.js index 5df2ed5..0215774 100644 --- a/test/compiler.test.js +++ b/test/compiler.test.js @@ -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', diff --git a/test/helpers/appdir.js b/test/helpers/appdir.js index 1a31be5..12c62b2 100644 --- a/test/helpers/appdir.js +++ b/test/helpers/appdir.js @@ -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); +};