Domanda

I'm using load-grunt-config and grunt-contrib-copy, and I'm trying to get the copy task to replace some template tags with the 'process' option.

I know that replacing template tags is possible (from the grunt-contrib-copy documentation), but I'm not able to get it to work. What I'm trying to do is replace the string <%= init.project.name %> in "style.css" with the template variable of the same name (entered by the user with grunt-prompt).

On copy I want grunt to replace the template variable in the style.css file, with the value that it has in memory. But it doesn't do this when I use the code I have below. Does anyone know what I'm doing wrong?

Grunt copy task

// -------------------------------------
// Grunt copy
// -------------------------------------

module.exports = {

  // ----- Copy files for initialization (selected with grunt prompt) ----- //

  init: {
    files: [{
      cwd: 'init/php/templates',
      src: '<%= init.php.templates %>',
      dest: 'src/php/templates',
      expand: true
    }, {
      cwd: 'init/php/includes',
      src: '<%= init.php.includes %>',
      dest: 'src/php/includes',
      expand: true
    }, {
      cwd: 'init/js',
      src: '<%= init.scripts %>',
      dest: 'src/js',
      expand: true
    }, {
      cwd: 'init/css',
      src: 'style.css',
      dest: 'src/css',
      expand: true,
      options: {
        process: function (content, srcpath) {
          return grunt.template.process(content);
        }
      }
    }]
  }
};

Css file (wordpress)

/*
Theme Name: <%= init.project.name %>
Theme URI: 
Description: Description
Version: 1.0
Author: Name
Author URI: uri
Tags: Tags
*/

I've tried this answer, but processContent has been replaced by process, and this answer does not seem to work any longer (even when changing processContent to process).

È stato utile?

Soluzione

You put options in wrong place, move it out and it should work.

module.exports = function (grunt) {
  return {
      init: {
        files: [{
          cwd: 'init/php/templates',
          src: '<%= init.php.templates %>',
          dest: 'src/php/templates',
          expand: true
        }, {
          cwd: 'init/php/includes',
          src: '<%= init.php.includes %>',
          dest: 'src/php/includes',
          expand: true
        }, {
          cwd: 'init/js',
          src: '<%= init.scripts %>',
          dest: 'src/js',
          expand: true
        }, {
          cwd: 'init/css',
          src: 'style.css',
          dest: 'src/css',
          expand: true
        }],
        options: {
          process: function (content, srcpath) {
            return grunt.template.process(content);
          }
        }
      }
  }
};

Updated to suit to load-grunt-config

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top