Enhancement: Local config
benurb opened this issue ยท 4 comments
Hello there!
I don't know if you want this behavior in dynamic-config, but for our use case it would be a huge improvement to be able to use local configs.
Explanation:
Let's assume you have a config.js
with the following content:
module.exports = {
"path": "/etc/blubb.conf"
"log": {
"level": "debug"
}
"a lot of": "other stuff"
};
This file is under version control and fits for most of your systems. But there is a specific configuration on a server/dev machine/whatsoever that just needs a tiny bit of the config changed. In this case I would propose a config.local.js
with only the specific changes. For example for the config above:
module.exports = {
"path": "/home/benurb/blubb.conf"
};
This would make it a lot easier to have dev/local configurations without messing around with the base configuration.
What do you think about it? If you like it I can create a PR ofc ๐
Ben
Thanks for your proposal @benurb!
I like the idea of having a local config. It could be a plugin and used if needed.
Another option would be to add the logic to your config.js
//config/index.js
const path = require("path");
const dynamicConfig = require("dynamic-config");
let localConfigPath = path.join(__dirname, "config.local.js");
let config = dynamicConfig(__dirname, "config.js");
if(fs.existsSync(localConfigPath) {
config = Object.assign(config, fs.readFileSync(localConfigPath));
}
module.exports = config;
But i'd be happy with a PR adding this functionality as a plugin ๐
We already have an extend
plugin which reads from env
and argv
. Maybe it's extend/file
or extend/localfile
?
Hey @meaku
I created a PR, that follows your suggestion. Instead of Object.assign
I used the deep-assign module, because of two reasons:
Object.assign
is not available in node 0.12Object.assign
is only shallow, but imho it should be possible to also overwrite nested properties without specifying the whole child object chain in the overwrite file
Let me know what you think ๐
Ben
Looks good! I added some comments about some copy & paste things. If you agree this PR can land :)