0

I have the following glupfile.js, it works fine but I need to run the default gulp task when a files in folder.

How to change my script in order to support gulp watch?

var gulp = require('gulp');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var noop = function () { };
var stylish = require('gulp-jscs-stylish');

var folders = [
    './a/**/*.js',
    './b/**/*.js',
    './c/**/*.js',
    'a.js',
    'b.js',
    'c.js',
    'd.js'
];

gulp.task('default', function () {
    gulp.src(folders)
        .pipe(jshint())                           // hint (optional)
        .pipe(jscs())                             // enforce style guide
        .on('error', noop)                        // don't stop on error
        .pipe(stylish.combineWithHintResults())   // combine with jshint results
        .pipe(jshint.reporter('jshint-stylish')); // use any jshint reporter to log hint and style guide errors
});
awe
  • 21,938
  • 6
  • 78
  • 91
GibboK
  • 71,848
  • 143
  • 435
  • 658

1 Answers1

1

Try adding a gulp task as given below

gulp.task('watch',function(){
   gulp.watch(folders,['default']); 

});
gulp.task('default',['watch']);

Basically it watches the folders for any change and if any change happens, it executes your default task.

plbit
  • 413
  • 2
  • 13
  • could you please post full code, at the moment adding your task does not allow me to show up in console the report for jscs and jshing. Only output in console is Starting 'watch' Finished 'watch' no other reports. – GibboK Aug 14 '15 at 07:42
  • Could you please rename your default task and then modify the last line in the answer as gulp.task('default',['newName','watch']); where newName is the new name of your default task. – plbit Aug 14 '15 at 07:56
  • yes I did it but I have the same problem, so watch works when saving files but the report is not being displayed at all. plase let me know if you have a solution thanks for your time on this – GibboK Aug 14 '15 at 08:05