如何将一个npm脚本转换成一个咕噜的任务?

我有我的nodeJS下面的脚本。

"scripts": { "start": "grunt", "test": "node --debug --harmony node_modules/grunt-cli/bin/grunt test" } 

我正在运行节点v0.11.13,所以我需要设置 – 和谐标志。 在咕噜的testingconfiguration正确,如果我用npmtesting启动它们,但我宁愿将它全部在一个grunt文件。 有没有办法configurationgrunt来启动服务器,并运行testing?

你可以创build一个别名任务,用这些节点标志来产生咕噜声,就像这样:

 grunt.registerTask('debug', function() { var done = this.async(); // Specify tasks to run spawned var tasks = Array.prototype.slice.call(arguments, 0); grunt.util.spawn({ // Use the existing node path cmd: process.execPath, // Add the flags and use process.argv[1] to get path to grunt bin args: ['--debug', '--harmony', process.argv[1]].concat(tasks), // Print everything this process is doing to the parent stdio opts: { stdio: 'inherit' } }, done); }); 

然后你可以启动服务器并运行testing: grunt default debug:test

或者真的是任何组合:

  • grunt server test (运行时没有节点标志)
  • grunt debug:server:test (与节点标志一起运行)。