无法使gulp-notify在gulp-jshint失败时弹出错误消息 [英] Cant make gulp-notify to pop up a error message when gulp-jshint fail

查看:179
本文介绍了无法使gulp-notify在gulp-jshint失败时弹出错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们整天工作在新的FE工作流程上,主要想法是通过观察者运行一些任务,我们将拥有IDE和一个窗口,浏览器在每次改变时都会刷新(scss,js ,html等)。



所以,如果一切顺利,我们不会看到任何东西:浏览器将重新加载,我们将继续工作。



但是,我们希望使用gulp来通知错误,所以如果我们出现问题,会弹出通知程序,此时您可以检查控制台并查看错误。 / p>

我们的sass任务失败时的示例:



对于我们的样式任务,一切正常,但我无法完成这对于JS文件。



主要是,我不能让gulp-jshint工作,因为我想。



像这样:你保存你的js文件,如果失败,弹出窗口出现,当你看到这个,你去控制台,你会看到jshint时尚的输出。



有人可以帮我吗?

<这是我的(非工作)解决方案:

  gulp.task('js-hint',function(){
return gulp.src(config.source)
.pipe(plumber())
.pipe(jshint(config.jsHintRules))
.pipe(jshint.reporter('jshint '))
.on('error',notify.onError({message:'JS hint fail'}));
});

很明显,我有一个概念问题,所以,有人可以请我把正确的方向?



请注意,我只是一直想发出相同的消息JS提示失败



然后,控制台(感谢jshint时尚)会给我们更多的信息。



另外,这将在一个观察者。
在JS提示通过后,会执行更多的任务,比如borwserify,所以它的重要是,如果它停下来,等待直到我完成修复然后继续。



感谢!

PS,Im使用:

gulp 3.8.10
gulp- jshint 1.8.6
gulp-notify 2.0.1



在OSX 10.9.4中

解决方案

在gulp中的错误事件仅在流中发生错误时触发。



添加一个错误记者到 gulp-jshint 通过失败记者传递:

  gulp.task('js-hint',function(){
return gulp.src(config.source)
.pipe(plumber())
.pipe(jshint(config.jsHintRules))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter ''失败'))
.on('error',notify.onError({message:'JS hint fail'}));
});


So, was the whole day working on our new FE workflow, the main idea is to run a few tasks through a watcher, we will have our IDE's and a window with the browsers getting refreshed each time something change (scss, js, html, etc).

So, we wont see nothing if all went good: the browser will get reload and we will keep working.

But, we want to use gulp notify for errors, so in case we have something wrong, the notifier pop up will appear, and at that point, you can check the console and see the error.

Example for our sass task when fail:

For our styles tasks, everything works fine, but Im not able to accomplish this for JS files.

Mainly, I cant make gulp-jshint works as I want.

Which will be like this: you save your js file, if it fails, the popup appear and when you see this, you go to the console and you see the output of jshint-stylish.

Can somebody help me ?

This is my (non working) solution:

gulp.task( 'js-hint', function() {
    return gulp.src( config.source )
        .pipe( plumber() )
        .pipe( jshint( config.jsHintRules ) )
        .pipe( jshint.reporter( 'jshint-stylish' ) )
        .on('error', notify.onError( { message: 'JS hint fail' } ) );
});

Obviously, I have a problem with concepts, so, will somebody can please put me on the right direction ?

Note that I just want to emit the same message all the time "JS hint fail"

Then, the console (thanks to jshint-stylish) will gave us more info.

Also, this will be on a watcher. After JS hint pass, will execute more tasks, like borwserify, so its important that if its stop, "wait" till I finish fixing it and then keep going.

Thanks !

PS, Im using:

gulp 3.8.10 gulp-jshint 1.8.6 gulp-notify 2.0.1

Over a OSX 10.9.4

解决方案

The error event in gulp only fires when an error in the stream occurs.

To add an error reporter to gulp-jshint pass it through the fail reporter:

 gulp.task('js-hint', function() {
      return gulp.src(config.source)
        .pipe(plumber())
        .pipe(jshint( config.jsHintRules))
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(jshint.reporter('fail'))
        .on('error', notify.onError({ message: 'JS hint fail'}));
  });

这篇关于无法使gulp-notify在gulp-jshint失败时弹出错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆