0.1.10 • Published 5 years ago

grunt-task-hooker v0.1.10

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

grunt-task-hooker

Add pre-execution and post-execution "hooks" to grunt task, see issues/542.

Install

npm install grunt-task-hooker --save-dev

Usage

// Gruntfile.js
module.exports = function (grunt) {

  // Don't forget to pass "grunt" object into the function!!!
  require('grunt-task-hooker')(grunt);

  grunt.initConfig({
    clean: {
      src: {},
      dist: {}
    }
  });

  grunt.registerTask('build', [...]);

  // pre hook without description
  grunt.hookTask('build', 'clean:dist');

  // pre hook multi task
  grunt.hookTask(['build', 'dev'], 'clean:dist');

  // post hook with description
  grunt.hookTask('clean:src', 'post clean src', function() {
    const done = this.async();
    setTimeout(function() {
      done();
    }, false);
  }, true);

  // hook multi-type task
  grunt.hookTask('clean', 'pre clean all', function() {
    console.log('do something before all clean tasks');
  });

  // hook replace task
  grunt.hookTask('clean', 'ignore task clean', function() {
    console.log('replace original clean task');
  }, 'replace');

  // grunt.hookTask(taskName, desc, task, where);
  // where:
  // undefined/false => pre
  // true => post
  // pre/post/replace

  // unhook all hooks
  grunt.unhookTask('clean');

  // unhook multi hooks
  grunt.unhookTask(['clean', 'build']);

  // unhook all pre hooks
  grunt.unhookTask('build', 'pre');

  // unhook all post hooks
  grunt.unhookTask('build', 'post');
};

License

The MIT License (MIT)

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago