Grunt this.files for non-multi-tasking

When defining multitasking in Gruntjs, I can execute

grunt.registerMultiTask("taskName", "taskDescription", function () {
  this.files.forEach(function (mapping) {
    // mapping.src and mapping.dest are defined here,
    // no matter which format was used to configure files in the task
  });
});

Why is this.filesnot available at run time grunt.registerTask? Or is it that I’m just not allowed to use different file formats in the task configuration when it’s not multitasking (compact format, object format, array format defined here )?

What is the easiest way to access src and destination file associations if they are not inside multitasking? I want to do

grunt.initConfig({
  my_task: {
    // I don't want to define a target here
    files: {
      // I want to be able to use any format here
      "my/target/folder": "my/src/files/*"
    }
}

grunt.registerTask("my_task", "description", function () {
  this.files // ==> undefined
});
+4
source share
1 answer

API Grunts , taskFunction.

grunt foo, foo, no args, grunt foo:testing:123, foo, testing 123.

grunt.registerTask('foo', 'A sample task that logs stuff.', function(arg1, arg2) {
  if (arguments.length === 0) {
    grunt.log.writeln(this.name + ", no args");
  } else {
    grunt.log.writeln(this.name + ", " + arg1 + " " + arg2);
  }
});

this grunt.registerTask taskFunction .

{ nameArgs: 'foo',
  name: 'foo',
  args: [],
  flags: {},
  async: [Function],
  errorCount: [Getter],
  requires: [Function],
  requiresConfig: [Function],
  options: [Function] }

grunt.registerMultiTask taskFunction .

{ nameArgs: 'my_task:files',
  name: 'my_task',
  args: [],
  flags: {},
  async: [Function],
  errorCount: [Getter],
  requires: [Function],
  requiresConfig: [Function],
  options: [Function],
  data: { thefile: 'thesource' },
  files: [],
  filesSrc: [Getter],
  target: 'files' }

, files my_task , .

+1

All Articles