Gulp-filter is filtering .. nothing

1.1k views Asked by At

Actually this is how my directory look's like :

-Project
  -app
    -js
      -some.js
      -libs
        -some.js
        -some.js
  -dist
    -js
      -some.js
      -libs
        -some.js
        -some.js

I'm using gulp to manage this and here is my problem, I can't success to filter out the libs directory to my js lint. (I just want to scan my own js, not the lib)

so i tried this :

gulp.task('js', function(){
    var filter = gulpFilter(['**/*', '!app/js/libs/**/*.js']);
    gulp.src('app/js/**')
        .pipe(filter)
        .pipe(jshint())
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(filter.restore())
        .pipe(gulp.dest('./dist/js'))
});

but jshint is still apply on the libs :/

Any help would be welcome ! :)

1

There are 1 answers

1
AlexToudic On

Actually you don't need filter to achieve what you want since gulp.src supports path exclusion. Change your task for the following and you'll be good ;)

gulp.task('js', function () {
    return gulp.src(['app/js/**/*.js', '!app/js/libs/**'])
        .pipe(jshint())
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(gulp.dest('./dist/js'))
});

EDIT: Considering your comment you should use

gulp.task('js', function(){
    var filter = gulpFilter(['*.js', '!app/js/libs/**']);
    return gulp.src('app/js/**')
        .pipe(filter)
        .pipe(jshint())
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(filter.restore())
        .pipe(gulp.dest('./dist/js'))
});