我有一个 ftp 服务器,用于通过 Grunt 任务进行部署。我现在正在使用 Gulp。
我很快就找到了 gulp-ftp,除了它将 ftp 密码存储在 gulpfile 中...所以我找到了 gulp-prompt,它允许脚本每次都提示。很好。
但是,我在将它们一起使用时遇到问题。我不确定如何以及在何处将 ftp 任务集成到密码提示中:
gulp.task('deploy', function () {
return gulp.src('build/*')
.pipe(prompt.prompt({
type: 'password',
name: 'pass',
message: 'Please enter your password'
}, function(res){
//value is in res.pass
ftp({
host: 'ftp.mysite.com',
user: 'mrwonderful',
pass: res.pass
});
}))
这显然是错误的,因为它会引发一大堆难以理解的错误。
最佳答案
我以前没有使用过 gulp-prompt。您现在认为 ftp 不是安全的连接方式,并且您的密码发送时未加密?但我让 gulp-ftp 和 gulp 提示正常工作:
gulp.task('deploy', function () {
return gulp.src('/')//it may be anything
.pipe(prompt.prompt({
type: 'password',
name: 'pass',
message: 'Please enter your password'
}, function(res){
gulp.src(['archive.zip'],{ base: './' })//now you have to target what you want to send
.pipe(ftp({
host: 'yourhost',
user: 'youruser',
pass: res.pass
}));
}));
});
我建议您使用 scp 或 ssh 发送。我在上传之前压缩项目,然后通过 ssh 解压缩它。
关于javascript - 一起使用 gulp-prompt 和 gulp-ftp 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27533424/