简体   繁体   English

只有在所有默认项都无误通过后,才能运行Gulp任务吗?

[英]How can I run Gulp tasks only after all of the default items pass with no error?

What I would like to do is only run the console.log if all three of the tasks complete successfully. 我只想在所有三个任务成功完成后才运行console.log。 Currently, the js lint item is the only item that seems to have built in functionality to break out if there is an error. 当前,js lint项目是唯一似乎具有内置功能的项目,如果有错误,该功能可以中断。

var gulp = require('gulp');
var csslint = require('gulp-csslint');
var eslint = require('gulp-eslint');
var htmlhint = require('gulp-htmlhint');

gulp.task('default', ['lint', 'css', 'html'], function() {
  console.log('hi');
});

gulp.task('css', function() {
  gulp.src('*.css')
    .pipe(csslint())
    .pipe(csslint.reporter());
});

gulp.task('lint', function() {
  return gulp.src(['**/*.js', '!node_modules/**'])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.result(function(result) {
      console.log('ESLint result: ' + result.filePath);
      console.log('# Messages: ' + result.messages.length);
      console.log('# Warnings: ' + result.warningCount);
      console.log('# Errors: ' + result.errorCount);
    }))
    .pipe(eslint.failAfterError());
});

gulp.task('html', function() {
  return gulp.src('*.html')
    .pipe(htmlhint())
    .pipe(htmlhint.reporter());
});

Add fail to the CSS linter's reporter call, .pipe(csslint.reporter('fail')); fail添加到CSS .pipe(csslint.reporter('fail'));的报告程序调用中.pipe(csslint.reporter('fail')); and use the HTML linter's failReport htmlhint.failReporter() vs .pipe(htmlhint.reporter()); 并使用HTML linter的failReport htmlhint.failReporter().pipe(htmlhint.reporter()); .

So in full: 因此完整:

var gulp = require('gulp');
var csslint = require('gulp-csslint');
var eslint = require('gulp-eslint');
var htmlhint = require('gulp-htmlhint');

gulp.task('default', ['lint', 'css', 'html'], function() {
  console.log('hi');
});

gulp.task('css', function() {
  gulp.src('*.css')
    .pipe(csslint())
    .pipe(csslint.reporter('fail'));
});

gulp.task('lint', function() {
  return gulp.src(['**/*.js', '!node_modules/**'])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.result(function(result) {
      console.log('ESLint result: ' + result.filePath);
      console.log('# Messages: ' + result.messages.length);
      console.log('# Warnings: ' + result.warningCount);
      console.log('# Errors: ' + result.errorCount);
    }))
    .pipe(eslint.failAfterError());
});

gulp.task('html', function() {
  return gulp.src('*.html')
    .pipe(htmlhint())
    .pipe(htmlhint.failReporter());
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM