firstandthird / load-grunt-config

Grunt plugin that lets you break up your Gruntfile config by task
firstandthird.github.io/load-grunt-config/
MIT License
374 stars 64 forks source link

Merging configuration array values #104

Closed danielkcz closed 9 years ago

danielkcz commented 9 years ago

Here is the use case. I have directory with base and client specific configuration files and I want to merge them together in a single config for grunt to run. The base configuration can be like this:

module.exports = files: ['common/config/*.cson]'

The client specific is similar, but different directories are used obviously. I want to merge these two so resulting files contains paths from both sources. Unfortunately result contains only client specific paths. Sadly it is the way how lodash merge works ... http://jsbin.com/vofocakabi/1/

I am wondering what would be good way how to overcome this. I was thinking about handling it in common config by looking it there is any existing configuration and merge it by myself, but in that time the configuration is not available yet.

module.exports = (grunt, options) ->
    options['myTaskName'] # doesn't exists yet
SolomoN-ua commented 9 years ago

Hi @FredyC, you can try to use postProcess functionality for this

SolomoN-ua commented 9 years ago

or you can also try something like this:

module.exports = files: ['common/config/*.cson', '<%= client.config %>']

and then just pass clients config into data:

require('load-grunt-config')(grunt, {
    //...
    data: {
        client: { ... }
    }
    //...
}
danielkcz commented 9 years ago

Yeah, I have pretty much ended with something similar like that. However I had also found recursive-merge which can handle array values properly. I think it would be more convenient for loading configuration files. Would you consider adding option to specify actual merging function?

SolomoN-ua commented 9 years ago

I'm not the one who is making decisions ;)

P.S.: I think, recursive merging will increase build time.

danielkcz commented 9 years ago

Well I think that having clear solution of how config files are structured wins over the performance. Either way, already working on pull request so it can be configurable :)