Interface IMultiTask

{@link http://gruntjs.com/inside-tasks#inside-multi-tasks}

Hierarchy

Index

Properties

Methods

Properties

public args: Array<string>

An array of arguments passed to the task. For example, if a "sample" task was run as grunt sample:foo:bar, inside the task function, this.args would be ["foo", "bar"].

public data: T in grunt.task.IMultiTask<T>

In a multi task, this is the actual data stored in the Grunt config object for the given target. For example, if a "sample" multi task was run as grunt sample:foo with the config data {sample: {foo: "bar"}}, inside the task function, this.data would be "bar".

note

It is recommended that this.options this.files and this.filesSrc are used instead of this.data, as their values are normalized.

public errorCount: number

The number of grunt.log.error calls that occurred during this task. This can be used to fail a task if errors were logged during the task.

public files: IFilesArray

In a multi task, all files specified using any Grunt-supported file formats and options, globbing patterns or dynamic mappings will automatically be normalized into a single format: the Files Array file format.

What this means is that tasks don't need to contain a ton of boilerplate for explicitly handling custom file formats, globbing patterns, mapping source files to destination files or filtering out files or directories. A task user can just specify files per the Configuring tasks guide, and Grunt will handle all the details.

Your task should iterate over the this.files array, utilizing the src and dest properties of each object in that array. The this.files property will always be an array. The src property will also always be an array, in case your task cares about multiple source files per destination file.

note

it's possible that nonexistent files might be included in src values, so you may want to explicitly test that source files exist before using them.

public filesSrc: Array<string>

In a multi task, all src files files specified via any file format are reduced to a single array. If your task is "read only" and doesn't care about destination filepaths, use this array instead of this.files.

public flags: IFlag[]

An object generated from the arguments passed to the task. For example, if a "sample" task was run as grunt sample:foo:bar, inside the task function, this.flags would be {foo: true, bar: true}.

public name: string

The name of the task, as defined in grunt.registerTask. For example, if a "sample" task was run as grunt sample or grunt sample:foo, inside the task function, this.name would be "sample".

public nameArgs: string

The name of the task, including any colon-separated arguments or flags specified on the command-line. For example, if a "sample" task was run as grunt sample:foo, inside the task function, this.nameArgs would be "sample:foo".

public target: string

In a multi task, this property contains the name of the target currently being iterated over. For example, if a "sample" multi task was run as grunt sample:foo with the config data {sample: {foo: "bar"}}, inside the task function, this.target would be "foo".

Methods

public async(): AsyncResultCatcher

If a task is asynchronous, this method must be invoked to instruct Grunt to wait. It returns a handle to a "done" function that should be called when the task has completed.

// Tell Grunt this task is asynchronous. var done = this.async(); // Your async code. setTimeout(function() { // Let's simulate an error, sometimes. var success = Math.random() > 0.5; // All done! done(success); }, 1000);

Returns

AsyncResultCatcher

public options(defaultsObj: any): ITaskOptions

Returns an options object. Properties of the optional defaultsObj argument will be overridden by any task-level options object properties, which will be further overridden in multi tasks by any target-level options object properties.

Parameters

  • defaultsObj: any

Returns

ITaskOptions

public options(defaultsObj: T): T

Parameters

  • defaultsObj: T

Returns

T

public requires(tasks: Array<string>)

If one task depends on the successful completion of another task (or tasks), this method can be used to force Grunt to abort if the other task didn't run, or if the other task failed.

note

that this won't actually run the specified task(s), it will just fail the current task if they haven't already run successfully.

Parameters

  • tasks: Array<string>

    an array of task names or individual task names, as arguments.

public requires(tasks: string, otherTasks?: Array<string>)

Parameters

  • tasks: string
  • otherTasks?: Array<string> optional

public requires(tasks: Array<string>, otherTasks?: Array<string[]>)

Parameters

  • tasks: Array<string>
  • otherTasks?: Array<string[]> optional

public requiresConfig(prop: string, andProps?: Array<string>)

Fail the current task if one or more required config properties is missing. One or more string or array config properties may be specified. this.requiresConfig(prop [, prop [, ...]])

Parameters

  • prop: string
  • andProps?: Array<string> optional