lib/task.js
function Task(phase, name, func) {
  if (typeof name === 'function') {
    func = name;
    name = 'anonymous';
  }

  if (phases.indexOf(phase) < 0) {
    throw new Error('Phase ' + phase + ' is not valid.');
  }

  if (typeof func !== 'function') {
    throw new TypeError('Expected function, got ' + typeof func);
  }

  /**
   * The unique identifier for this task
   * @member {string}
   * @public
   */
  this.name = name;

  /**
   * The phase under which this task is to be run
   * @member {string}
   * @public
   */
  this.phase = phase;

  /**
   * The wrapped task function (func)
   * @member {Function}
   * @public
   * @returns Promise
   */
  this.func = function () {
    var wheel = new Pinwheel('TASK: '+this.name+' ('+this.phase+')')
      , task = this;
    return new Promise(function (done, fail) {
      if (process.env.ENV !== 'test') wheel.start();
      func.call(task, function (err) {
        if (err) return fail(err);
        return done();
      });
    })
    .then(function () {
      if (process.env.ENV !== 'test') wheel.stop();
    })
    .catch(function (err) {
      if (process.env.ENV !== 'test') wheel.stop(err);
      return console.error(err);
    });
  };
}
function Task(phase, name, func) {
  if (typeof name === 'function') {
    func = name;
    name = 'anonymous';
  }

  if (phases.indexOf(phase) < 0) {
    throw new Error('Phase ' + phase + ' is not valid.');
  }

  if (typeof func !== 'function') {
    throw new TypeError('Expected function, got ' + typeof func);
  }

  /**
   * The unique identifier for this task
   * @member {string}
   * @public
   */
  this.name = name;

  /**
   * The phase under which this task is to be run
   * @member {string}
   * @public
   */
  this.phase = phase;

  /**
   * The wrapped task function (func)
   * @member {Function}
   * @public
   * @returns Promise
   */
  this.func = function () {
    var wheel = new Pinwheel('TASK: '+this.name+' ('+this.phase+')')
      , task = this;
    return new Promise(function (done, fail) {
      if (process.env.ENV !== 'test') wheel.start();
      func.call(task, function (err) {
        if (err) return fail(err);
        return done();
      });
    })
    .then(function () {
      if (process.env.ENV !== 'test') wheel.stop();
    })
    .catch(function (err) {
      if (process.env.ENV !== 'test') wheel.stop(err);
      return console.error(err);
    });
  };
}
function Task ( phase , name , func ) { if ( typeof name === 'function' ) { func = name ; name = 'anonymous' ; } if ( phases . indexOf ( phase ) < 0 ) { throw new Error ( 'Phase ' + phase + ' is not valid.' ) ; } if ( typeof func !== 'function' ) { throw new TypeError ( 'Expected function, got ' + typeof func ) ; } /**
   * The unique identifier for this task
   * @member {string}
   * @public
   */ this . name = name ; /**
   * The phase under which this task is to be run
   * @member {string}
   * @public
   */ this . phase = phase ; /**
   * The wrapped task function (func)
   * @member {Function}
   * @public
   * @returns Promise
   */ this . func = function ( ) { var wheel = new Pinwheel ( 'TASK: ' + this . name + ' (' + this . phase + ')' ) , task = this ; return new Promise ( function ( done , fail ) { if ( process . env . ENV !== 'test' ) wheel . start ( ) ; func . call ( task , function ( err ) { if ( err ) return fail ( err ) ; return done ( ) ; } ) ; } ) . then ( function ( ) { if ( process . env . ENV !== 'test' ) wheel . stop ( ) ; } ) . catch ( function ( err ) { if ( process . env . ENV !== 'test' ) wheel . stop ( err ) ; return console . error ( err ) ; } ) ; } ; }
Task constructor, wraps task function and stores information about the task
@constructor
@param {string} phase - The phase under which this task is to be run
@param {string} [name='anonymous'] - The unique identifier for this task
@param {Function} func - The task function to be called
Task constructor wraps task function and stores information about the task