2014-09-04 61 views
1

我正在使用Gulp观看文件,通过ftp上传文件,并在上传完成时发送通知。我不知道如何连接这些插件来使其工作。现在,我有:Gulp - 通过ftp上传文件后通知

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'}); 
    }); 

我认为需要通知要传递给.pipe(),但我不知道该怎么做,在这方面(的回调内.on())。在控制台上打印“测试”,但通知无声。

这似乎是一个简单的任务,但不熟悉Node会让Gulp变得困难。

感谢您的任何建议。

+0

什么使你使用'finish'事件,而不是仅仅通过管道流'通知'? – Ben 2014-09-04 21:07:12

+0

如果您只是通过管道通知,那么通知将在文件上传完成之前显示。 – nichoth 2014-09-05 22:10:23

回答

3

我想你可能想,因为你需要通知上比流的data事件之外的事件,直接使用node-notifier

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'}); 
    }); 
+0

它的工作原理!谢谢。 – nichoth 2014-09-11 18:11:30