grunt-anon-tasks

0.2.2 • Public • Published

grunt-anon-tasks v0.2.2

What is this?

A plugin for Grunt that allows you to create anonymous tasks using grunt.task.then().

What's an anonymous task?

A task that you can run without ever calling grunt.registerTask() manually. Anonymous tasks are extremely useful for (1) completion callbacks and (2) dynamic task configuration.

Table of Contents

     Installation

     Example

     Descriptions

     Failability

     Lifecycle

Installation

In your terminal:

npm install --save-dev grunt-anon-tasks

In your Gruntfile.js:

grunt.loadNpmTasks("grunt-anon-tasks")

But I suggest using load-grunt-tasks:

require("load-grunt-tasks")(grunt) // loads every installed "grunt-*" module

Example

In the example below, the anonymous task runs after clean completes and before build starts.

grunt.task
  .run("clean")
  .then(function () {
    grunt.log.writeln(this.name)
  })
  .run("build")

The this variable in anonymous tasks is the same as in registered tasks.

Descriptions

Debugging is easier when an anonymous task has a description. Of course, this is optional.

grunt.task.then("A description of what I'm doing", function () {
  // do cool grunty things
})

If provided, the description will appear in your terminal (below the message that says Running "anon_x" task).

Failability

Anonymous tasks can signal failure either synchronously or asynchronously; just like registered tasks.

grunt.task
  .then(function () {
    return false // synchronous failure
  })
  .then(function () {
    var done = this.async()
    performAsyncOperation(function () {
      done(false) // asynchronous failure
    })
  })

Lifecycle

Anonymous tasks are deleted after completion; thus, it isn't possible to run the same anonymous task more than once.

Readme

Keywords

Package Sidebar

Install

npm i grunt-anon-tasks

Weekly Downloads

4

Version

0.2.2

License

none

Last publish

Collaborators

  • aleclarson