Skip to content

Instantly share code, notes, and snippets.

@pvenkatakrishnan
Last active August 29, 2015 13:58
Show Gist options
  • Save pvenkatakrishnan/b1cae982a813c8b29953 to your computer and use it in GitHub Desktop.
Save pvenkatakrishnan/b1cae982a813c8b29953 to your computer and use it in GitHub Desktop.
Proposal 1: For config in kraken
// make a config object use a confit factory in order to merge two configs
exports.create = function create(options) {
var deferred, protocols, baseFactory, appFactory;
deferred = q.defer();
protocols = createHandlers(options);
//create a baseFactory
baseFactory = confit({ basedir: path.join(path.dirname(__dirname), 'config'), protocols: protocols });
baseFactory.create(function(err, config) {
if (err) {
deferred.reject(err);
return;
}
//create App Factory
appFactory = confit({basedir: path.join(options.basedir, 'config'), protocols: protocols });
//feed appFactory into config from baseFactory
config.use(appFactory, function(err, conf) {
//config returned has the final merged object
if(err) {
deferred.reject(err);
} else {
deferred.resolve(conf);
}
});
});
return deferred.promise;
};
//I had to change confit to implement use a little differently...
//I know this is a bad practice of the same function acting async as well as sync...
//need to fix that or separate out the different kinds of usage
use: function use(obj, callback) {
if (callback) {
obj.create(function (err, data) {
if (err) {
callback(err);
return;
}
data.use(store);
callback(null, data);
});
} else {
common.merge(obj, store);
}
}
@pvenkatakrishnan
Copy link
Author

This solves only the scanning config and {env} .json cases
Still need to solve
[ ] Reference to other files which loads config
[ ] Reference other configs from a config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment