隐藏任务回调上的错误非null

时间:2014-09-12 00:24:22

标签: gulp

我有2个任务应该按顺序运行并静默产生错误,以免停止监视。我做了一个任务取决于另一个任务和第一个任务有一个回调,当它完成一个参数,以指示是否成功时调用。现在我的问题是,当使用非null参数调用回调来指示错误时,会出现一个错误的消息,这实际上很烦人,因为它会分散我发生的实际错误,因此有一种方法可以隐藏该错误味精。

让我告诉你,我拥有的是那样的

gulp.task('stylus', function (cb) {
    var err = null;
    gulp.src('app/**/*.styl')
        .pipe(plumber(function(error){
            err = true;
            gutil.log(error.toString());
        }))
        .pipe(changed('build/css/',{ extension: '.css' }))
        .pipe(stylus())
        .pipe(gulp.dest('build/css/'))
        .on('end',function(){cb(err)});
});
gulp.task('css-concat',['stylus'], function(){  // depends on stylus task
    gulp.src('build/css/**/*.css')
       .pipe(plumber())
       .pipe(concat('app.css'))
       .pipe(gulp.dest('build/'));
});

gulp.task('watch', ['css-concat'], function () { // run css concat first which in trun runs stylus first

    var cssWatch = gulp.watch('app/**/*.styl', ['css-concat']); // watch the same files in our scripts task


    cssWatch.on('change', function (event) {
        if (event.type === 'deleted') {                   // if a file is deleted, delete it from build
            var t = event.path.replace(".styl",".css").replace(/^.+\\app\\/,"build/css/");
           del(t);
        }

    });
}); 



因此,css-concat取决于stylus,如果stylus产生错误,也会监视文件以及更改调用css-concat任务,则stylus无效。

< / p>

现在这是{{1}}产生错误时出现的错误(粗体文本是我所说的错误)


[03:14:38] Starting 'stylus'...
[03:14:39] ParseError in plugin 'gulp-stylus'
Message:
    D:\angularjs\app\app.styl:1:19
   1| my-color = blue.............
------------------------^
   2| 
   3| body
   4|   background-color my-color

illegal unary "...", missing left-hand operand

[03:14:39] 'stylus' errored after 14 ms
[03:14:39] Error: true
    at formatError (C:\Users\Karim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:161:10)
    at Gulp. (C:\Users\Karim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:187:15)
    at Gulp.emit (events.js:95:17)
    at Gulp.Orchestrator._emitTaskDone (D:\angularjs\node_modules\gulp\node_modules\orchestrator\index.js:264:8)
    at D:\angularjs\node_modules\gulp\node_modules\orchestrator\index.js:275:23
    at finish (D:\angularjs\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:21:8)
    at cb (D:\angularjs\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:29:3)
    at DestroyableTransform. (D:\angularjs\gulpfile.js:28:30)
    at DestroyableTransform.emit (events.js:117:20)
    at D:\angularjs\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:965:16

0 个答案:

没有答案