0

I know I can use node-notifier but is there a better way to set up a notification which is dependent on a task being complete (and which does not use .pipe)

The below works but is there a way to achieve this within a single task?

// Perform data task
gulp.task('imgData1', function() { 
  imageExport.record({
    path: path.images_src,
    output: path.images_data,
    template: 'custom.hbs',
    breakpointDelimiter: '--'
  })
});

// Perform notification task 
gulp.task('imgData2', ['imgData1'], function() {
  notifier.notify({
  'title': 'My notification',
  'message': 'Data task complete!'
});
});

// Perform data task then the notification task 
gulp.task('imgData', ['imgData2']);
Community
  • 1
  • 1
fivedoor
  • 389
  • 7
  • 24

1 Answers1

1

image-size-export accepts a callback that is invoked when imageExport.record() has finished. Simply run notifier.notify() in that callback:

gulp.task('imgData', function() { 
  imageExport.record({
    path: path.images_src,
    output: path.images_data,
    template: 'custom.hbs',
    breakpointDelimiter: '--'
  }, function() {
     notifier.notify({
       'title': 'My notification',
       'message': 'Data task complete!'
     });
  });
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
  • Thanks Sven. I did give that a go but was getting an error re `var tpl = template.toString();` - `TypeError: Cannot read property 'toString' of undefined`. Will take another look. – fivedoor Jul 25 '16 at 16:34
  • That's [this line](https://github.com/Sebastian-Fitzner/image-size-export/blob/e13dba47c3f9f52851e4f904611a26e6d7955cff/lib/imagesizeExport.js#L148). Probably means the `custom.hbs` file cannot be read for some reason (wrong path?). – Sven Schoenung Jul 25 '16 at 16:41
  • Ah that makes sense. yes exactly. I was being an eedyat and not updated my file paths correctly. Working perfectly now. Thanks for your help! – fivedoor Jul 25 '16 at 16:46