Grunt registerTask()未在列表中运行任务

时间:2014-02-13 17:20:36

标签: javascript node.js gruntjs rendr

我已向此registerTask

添加了以下Gruntfile.js次调用
grunt.task.registerTask('runDebug', 'Run the app with debug flag', function() {
  var done = this.async();
  grunt.util.spawn({
      cmd: 'node',
      args: ['--debug', './node_modules/nodemon/nodemon.js', 'index.js'],
      opts: {
        stdio: 'inherit'
      }
    }, function (error, result, code) {
      if (error) {
          grunt.log.write (result);
          grunt.fail.fatal(error);
      }
      done();
    });
  grunt.log.writeln ('node started');
  grunt.util.spawn({
      cmd: 'node-inspector',
      args: ['&'],
      opts: {
          //cwd: current working directory
      }
    },
    function (error, result, code) {
      if (error) {
        grunt.log.write (result);
        grunt.fail.fatal(error);
      }
      done();
    });
  grunt.log.writeln ('inspector started');
});

grunt.task.registerTask('debug', ['runDebug', 'compile', 'watch']);

新的debug任务类似于现有的server任务。但是,grunt server命令运行compilewatchrunNode任务,而grunt debug命令仅运行runDebug任务。

我在这里缺少什么?为什么compilewatch任务不能与grunt debug命令一起运行。

1 个答案:

答案 0 :(得分:0)

您的代码多次调用done()返回的this.async()函数。这可能会让Grunt感到困惑。我建议您调用自己的函数,该函数可以命名为spawned(),而不是直接在回调函数中调用done()。该功能可能类似于:

var expected_spawns = 2;
function spawned() {
    if (!--expected_spawns)
        done();

    if (expected_spawns < 0)
        throw new Error("too many spawns!") // Or some of Grunt's fail functions.
}

这种方式done()将被调用一次。