2

I am using the gulp-notify plugin. This is an example of how I'm implementing it in a gulpfile.js ( You can see I'm using gutil and livereload as well. I don't know if they play any factors, but let me know if they do.)

gulp.task('js', function() {
  return gulp.src('./dev/scripts/*.coffee')
    .pipe(coffee({bare: true}).on('error', gutil.log))
    .pipe( gulp.dest('./build/js'))
    .pipe(notify('Coffeescript compile successful'))
    .pipe(livereload(server));
});

This plugin works on OS X and Linux. On Windows, which doesn't have a notification feature, it returns an error and breaks the gulp-watch plugin. This is an example of how I have gulp-watch setup:

gulp.task('watch', function () {
  server.listen(35729, function (err) {
    if (err) {
      return console.log(err);
    }
    gulp.watch('./dev/scripts/*.coffee',['js']);
  });
});

So, I read in the documentation the gulp-pipe plugin can help me not break gulp-watch when on Windows, but I can't find an example of how I could use it in a setup like this.

harrypujols
  • 2,264
  • 3
  • 19
  • 30
  • 1
    gulp-notify now fails silently, with the option to catch error if you so choose. See option emitError (https://github.com/mikaelbr/gulp-notify#optionsemiterror) – mikaelb May 27 '14 at 20:04

1 Answers1

7

You can use the gulp-if plugin in combination with the os node module to determine if you are on Windows, then exclude gulp-notify, like so:

var _if = require('gulp-if');

//...

// From http://stackoverflow.com/questions/8683895/variable-to-detect-operating-system-in-node-scripts
var isWindows = /^win/.test(require('os').platform());

//...

     // use like so:
    .pipe(_if(!isWindows, notify('Coffeescript compile successful')))
OverZealous
  • 39,252
  • 15
  • 98
  • 100
  • Note: the test for windows is [from here](http://stackoverflow.com/questions/8683895/variable-to-detect-operating-system-in-node-scripts), but I can't confirm it works. – OverZealous Feb 25 '14 at 15:50
  • Thanks. I failed to mention I have tried this approach with gulp-if unsuccessfully. If anyone else can try it and make it work, let me know. I may be doing something wrong. – harrypujols Feb 25 '14 at 16:09
  • I'm sorry, it's not something I can easily test. It looks like the notifier shouldn't be called if you are using `gulp-if`, so you shouldn't see an error. Can you edit your original question to include the exact error message? – OverZealous Feb 25 '14 at 18:40
  • I tried this approach again to include the error message with the question, but it ran fine. In fact, this approach works. So my best guess is that the problem was due to a syntax error somewhere. I wish this plugin didn't need another plugin to play nice with Windows. Again, thanks! – harrypujols Feb 25 '14 at 20:38
  • 1
    It's worth mentioning: gulp-notify now supports Windows, so this solution should be unnecessary - but it is a good tip for something like deactivating notification on the CI. – mikaelb Mar 11 '14 at 11:22