outaTiME / grunt-replace

Replace text patterns with applause.
MIT License
411 stars 47 forks source link

How to get default conf overrided by environment conf? #75

Closed jmeiss closed 9 years ago

jmeiss commented 9 years ago

Hi guys!

I'm using replace and I really like it! It's an awesome package to generate my environment conf but I've found any way to get a default config file and a specific environment config file that will override default config file.

Ex:

config-default.json

{ foo: "bar", toto: "tata" }

config-dev.json

config-prod.json

{ foo: "prod-bar" }

should generate:

dev.json

{ foo: "bar", toto: "tata" }

prod.json

{ foo: "prod-bar", toto: "tata" }

Is there any way to do that?

Thanks for your help

outaTiME commented 9 years ago

Hi pal,

Thanks for your feedback i need to think how can implement this feature ... stay in touch ...

outaTiME commented 9 years ago

You could try the following example:

var merge = require('merge');

grunt.initConfig({

  replace: {
    dev: {
      options: {
        patterns: [
          {
            json: merge(
              grunt.file.readJSON('./config/default.json'),
              grunt.file.readJSON('./config/dev.json')
            )
          }
        ]
      },
      files: [
        {expand: true, flatten: true, src: ['test/dev.json'], dest: 'tmp/'}
      ]
    },
    prod: {
      options: {
        patterns: [
          {
            json: merge(
              grunt.file.readJSON('./config/default.json'),
              grunt.file.readJSON('./config/prod.json')
            )
          }
        ]
      },
      files: [
        {expand: true, flatten: true, src: ['test/prod.json'], dest: 'tmp/'}
      ]
    }
  }

});
outaTiME commented 9 years ago

Please ... tell me if it fits in your scenario, thks !!!

outaTiME commented 9 years ago

Pal any updates, It was useful example ??

outaTiME commented 9 years ago

No updates, closing for now ...