Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Support for .js files and multiple files per directory #2

wants to merge 2 commits into from

2 participants


Let me know if there would be a better approach or if this is a bad idea for some reason.

Basically detects if the request file is a js file, and if so requires it and merges it (with deepmerge).

Also pushes files onto configFiles array, as to not return from for loop, thereby allowing multiple files per directory.


The configFiles behavior is intentional so that you can have environment branching without merging.


I see, so the pattern I was going for was to have a default config.json provided by the application and then a config.local.json file to override parts of it.

If I understand correctly you would recommend using 1 config.json and then override it in whole by config.DEVELOPMENT.json?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 12, 2012
  1. consistent whitespace

    Zack Story authored
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 4 deletions.
  1. +14 −4 index.js
18 index.js
@@ -6,7 +6,9 @@ var figc = require('figc');
var optimist = require('optimist');
var exists = fs.existsSync || path.existsSync;
+var merge = require('./node_modules/figc/node_modules/deepmerge')
module.exports = function (opts) {
if (typeof opts === 'string') {
opts = { env : opts };
@@ -21,19 +23,27 @@ module.exports = function (opts) {
var dirs = parents(opts.dir || path.dirname(require.main.filename));
- var configFiles = dirs
- .map(function (dir) {
+ var configFiles = []
+ (dir) {
for (var i = 0; i < files.length; i++) {
var file = path.join(dir, files[i]);
- if (exists(file)) return file;
+ //if the file exists push it on to the configFiles list array
+ if (exists(file)) configFiles.push(file);
var argv = opts.argv || optimist.argv;
if (configFiles.length === 0) return argv;
return configFiles.reduce(function (config, file) {
+ //if the file is .js assume it will export a configuration object to be merged
+ if(file.split('.').pop() == 'js'){
+ var obj = require(file)
+ return merge(obj, config)
+ }
+ //else assume json and merge with figc
return figc(file, config);
}, argv);
Something went wrong with that request. Please try again.