20

In my gulpfile.js I have a task that calls two other tasks. When the previous tasks have run, a notification should be triggered.

var notify = require('gulp-notify');

gulp.task('build', ['build:js', 'build:css'], function() {
  console.log('hello', arguments);
  gulp.src('gulpfile.js').pipe( notify({ title: 'Production Build', message: 'Done' }) );
});

Is there a way to trigger notify without calling gulp.src('gulpfile.js').pipe( first? While not a real problem, this approach feels unnecessary to me. It is entirely possible that my question results from an insufficient understanding of gulp. So feel free to point me to any misunderstanding.

tobi-or-not
  • 566
  • 4
  • 13

1 Answers1

31

You can use node-notifier directly:

var notifier = require('node-notifier');

gulp.task('build', ['build:js', 'build:css'], function() {
    notifier.notify({ title: 'Production Build', message: 'Done' });
});
Heikki
  • 15,329
  • 2
  • 54
  • 49
  • Ops, good thing you put in the import. I forgot to mention that I use `gulp-notify`. But even though it relies on `node-notifier` the same approach does not work there. – tobi-or-not Nov 06 '14 at 16:14
  • I edited my original question. With `gulp-notify` I have not found a way to call notify() without a pipe. – tobi-or-not Nov 07 '14 at 08:23
  • 4
    Gulp-notify is a wrapper around node-notifier that calls it for each file in a stream. If you don't have a stream the more natural approach is to call node-notifier directly as Heikki suggested. – Ghidello Nov 07 '14 at 10:12
  • 6
    I've used this to load notifier as gulp-notify dependency `var notifier = require('gulp-notify/node_modules/node-notifier');` – piotr_cz Mar 07 '15 at 14:37
  • Just fyi I got this to work for the OSX notifier that appears in the upper right hand corner of the screen but didn't see anything in the command line. I reverted to the OP's method and despite looking like a roundabout way of doing it, it works fine. – Scott L Sep 19 '16 at 15:35