outaTiME / grunt-replace

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

change destination file name #86

Closed donalmurtagh closed 9 years ago

donalmurtagh commented 9 years ago

I would like to replace the variables in /template/foo.js.tpl and store the result in /config/foo.js. I tried the following configuration

    files: [
      {
        expand: true,
        flatten: true,
        src: ['/config/template/config.js.tpl'],
        dest: '/config/config.js'
      }
    ]

But that results in the output file /config/config.js/config.js. Is it possible to specify an output filename that is different from the template file name?

outaTiME commented 9 years ago

Hi pal,

you could try the following:

files: [
  {
    expand: true,
    cwd: 'config/',
    src: ['template/config.js.tpl'],
    dest: 'config/',
    rename: function(dest, src) {
      return dest + src.replace(/\.tpl$/, "");
    }
  }
]
donalmurtagh commented 9 years ago

@outaTiME thanks a lot, it worked like a charm. Is rename covered in the docs? If so, I must have overlooked it

outaTiME commented 9 years ago

The readme attribute is part from grunt core, take a look:

http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically