[英]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. 我正在使用Gulp来观看文件,通过ftp上传更改文件,并在上传完成后发送通知。 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()
). 我认为通知需要传递给
.pipe()
,但我不知道如何在这个上下文中(在.on()
的回调中)。 "test" is printed on the console, but notify is silent. “test”打印在控制台上,但通知是静默的。
This seems like a simple task, but being unfamiliar with Node makes Gulp difficult. 这似乎是一项简单的任务,但对Node不熟悉会让Gulp变得困难。
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: 我想您可能希望直接使用node-notifier ,因为您需要通知除流的
data
事件之外的事件:
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'});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.