【问题标题】:Gruntfile getting error codes from programs seriallyGruntfile 从程序中串行获取错误代码
【发布时间】:2023-04-07 05:05:01
【问题描述】:

我想创建一个 grunt 文件,该文件一个接一个地连续运行 3 个 grunt 任务,无论它们是失败还是通过。如果其中一个 grunts 任务失败,我想返回最后一个错误代码。

我试过了:

grunt.task.run('task1', 'task2', 'task3');

在运行时使用--force 选项。

这样做的问题是,当指定 --force 时,无论错误如何,它都会返回错误代码 0。

谢谢

【问题讨论】:

    标签: javascript gruntjs error-code


    【解决方案1】:

    使用grunt.util.spawnhttp://gruntjs.com/api/grunt.util#grunt.util.spawn

    grunt.registerTask('serial', function() {
      var done = this.async();
      var tasks = {'task1': 0, 'task2': 0, 'task3': 0};
      grunt.util.async.forEachSeries(Object.keys(tasks), function(task, next) {
        grunt.util.spawn({
          grunt: true,  // use grunt to spawn
          args: [task], // spawn this task
          opts: { stdio: 'inherit' }, // print to the same stdout
        }, function(err, result, code) {
          tasks[task] = code;
          next();
        });
      }, function() {
        // Do something with tasks now that each
        // contains their respective error code
        done();
      });
    });
    

    【讨论】:

    • opts: {stdio: 'inherit'} 后面多了一个逗号,非常感谢!!!
    • 它是故意的 ;) 尾随逗号在节点 >= 0.8 中很酷。至少我是这么认为的,呵呵
    猜你喜欢
    • 2017-10-12
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    相关资源
    最近更新 更多