简体   繁体   中英

Gulp – notify after uploading a file via ftp

I'm using Gulp to watch files, upload them on change via ftp, and send a notification when uploading is complete. I'm not sure how to connect these plugins to make it work. Right now I have:

var gulp      = require('gulp'),
    ftp       = require('gulp-ftp'),
    watch     = require('gulp-watch'),
    notify    = require('gulp-notify');

var markupWatcher = watch({ glob: 'src/*.php', name: 'markup' });
markupWatcher.gaze.on('all', function(event, path) {
  options.remotePath = ftpData.remotePath;
  gulp.src(path)
    .pipe(ftp(options))
    .on('finish', function() {
      console.log('test');
      notify({title: 'File Uploaded', message: 'test'});
    });

I think notify needs to be passed to .pipe() , but I don't know how to do that in this context (within a callback in .on() ). "test" is printed on the console, but notify is silent.

This seems like a simple task, but being unfamiliar with Node makes Gulp difficult.

Thanks for any advice.

I think you may want to use node-notifier directly since you need to notify on an event other than the stream's data event:

var gulp            = require('gulp'),
    ftp             = require('gulp-ftp'),
    watch           = require('gulp-watch'),
    Notification    = require('node-notifier');

var notifier = new Notification();
var markupWatcher = watch({ glob: 'src/*.php', name: 'markup' });
markupWatcher.gaze.on('all', function(event, path) {
  options.remotePath = ftpData.remotePath;
  gulp.src(path)
    .pipe(ftp(options))
    .on('finish', function() {
      console.log('test');
      notifier.notify({title: 'File Uploaded', message: 'test'});
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM