1

Instead of adding the destinations in the dest attribute I would like to make it dynamic so I can assign the destinations when I run the task from the command line or when I run it from another task. That way I can copy the file to any folder(s) I want whenever I call the task.

copy: {
        nightlyBuild: {
            files: [{
                expand: true,
                cwd: '../',
                src: ['index.html'],
                dest: 'destinations'
            }]
         }
      },

I am assuming I need to use grunt.option and grunt.config but can't seem to get it right. I have multiple scripts that I would like to reuse in a similar way.

1 Answers1

4

I think you were in the right track. This should help

copy: {
    nightlyBuild: {
        files: [{
            expand: true,
            cwd: '../',
            src: ['index.html'],
            dest: '<%= dest %>',
        }]
    }
},

grunt.task.registerTask('copyTo', 'copy into a specific destination', function(dest) {
  if (arguments.length === 0) {
    grunt.log.writeln(this.name + ", missing destination");
  } else {
    grunt.log.writeln(this.name + " to " + dest);
    grunt.config.set('dest', dest);

    grunt.task.run([
      'copy:nightlyBuild'
    ]);
  }
});

You would then call the task like this: grunt copyTo:mydestination

Rachid
  • 812
  • 6
  • 7