gulp-tasks加载的任务失败后退出并出错

时间:2017-07-10 08:05:21

标签: error-handling gulp

我正在使用magento2-frontools并尝试解决此问题:

https://github.com/SnowdogApps/magento2-frontools/issues/231

问题是,如果出现错误,gulp styles应该有一个非零退出代码,但它会以0退出。

gulp文件如下所示:

// Tasks loading
require('gulp-task-loader')({
  dir    : 'task',
  plugins: plugins,
  configs: config
});

这样的styles.js任务:

  'use strict';
  module.exports = function() { // eslint-disable-line func-names
    // Global variables
    const gulp    = this.gulp,
      plugins = this.opts.plugins,
      config  = this.opts.configs,
      themes  = plugins.getThemes(),
      streams = plugins.mergeStream();

    // Generate all necessary symlinks before styles compilation, but ony if not a part of tasks pipeline
    if (!plugins.util.env.pipeline) {
      plugins.runSequence('inheritance');
    }

    // Loop through themes to compile scss or less depending on your config.json
    themes.forEach(name => {
      streams.add(require('../helper/scss')(gulp, plugins, config, name));
    });

    return streams;
  };

(它可以都是found on GitHub

如果看过this approach来解决问题:

.once("error", function () {
   this.once("finish", () => process.exit(1));
})

但我可以在哪里添加该代码?

1 个答案:

答案 0 :(得分:1)

只需要使用--ci标志。