Read configuration from project directory
First introduce my use case:
My team develops a system in micro-service architecture which have several node.js projects. I'm trying to use mrm to unify configuration of all projects. I have defined a bunch of tasks according to our design guidelines. But not all configurations are common to all projects. Some configurations have to be set per-project. And also, some tasks should only be applied on part of projects.
I think if mrm would resolve configuration from .mrm file under project root directory, in which not only contains config items specific to current project but also defines which tasks from which preset should be applied, then I can run mrm without any argument inside each project to update its configuration according to latest version of preset/tasks published in our private npm registry.
It would be helpful for a big team to manage projects to keep them up-to-date with team's project template/configuration.
You can already do this with --dir option.
@sapegin --dir option doesn't solve my issue. I have done a test:
Create .mrm/config.json with config items to take precedence in project directory. mrm mytask --dir .mrm --preset mypreset doesn't work. Config item in .mrm/config.json isn't used.
If I use --config option: mrm mytask --config:foo foo_value --preset mypreset works.
Reading mrm source code, I found that https://github.com/sapegin/mrm/blob/3d5801eea0779b35b89e70e7ea7044b94697d5e0/src/index.js#L193 doesn't merge configuration from files and it only load configure from the first file. In my use case, I expect that config files in dir and in preset both take effect.
You’re right, it doesn’t merge configs. But you can change any option via command line.
Yes, config option works. But it looks not the best way to me for reasons:
- When there are more configure items the command line is long.
- To automatic the workflow, I have to create a shell script to call
mrmwith a long list of arguments. Whenever a config needs to be updated, the script will be modified. Embedding config in a script is not good for maintainence. - Or I create a property file to store configs. My script read it then pass configs to
mrm. But it adds complexity. It'd be ideal to handle inside mrm.
Would you consider to support merge config from files? If yes maybe I can contribute a PR.
Would be nice if you could try to implement it. Maybe we could use cosmiconfig for that.