0
我試圖生成依賴於包含連接信息的ftp.json文件的FTP一飲而盡任務的其餘部分。該文件包含在.gitignore中,因此當開發人員克隆回購時,該文件不存在。我運行一個檢查來查看他們是否設置了ftp.json,如果不存在,它會下載一個空白的文件。等功能來完成,然後轉移到一個咕嘟咕嘟任務
我到運行的問題是,雖然它下載的文件,它也拋出一個錯誤,結束任務。我想要說的是「等待此功能完成,然後繼續執行其餘任務」,以防止發生錯誤。這是我目前的FTP任務:
// upload to FTP environment
gulp.task("ftp", function(callback) {
// development FTP directory
var ftpDirectory = dev;
// production FTP directory (if --dist is passed)
if (argv.dist) {
ftpDirectory = dist;
}
// check if the FTP.json exists
fs.exists("./ftp.json", function(exists) {
// if it doesn't, download it
if (!exists) {
download("https://gist.githubusercontent.com/revxx14/a04f5ba7e00b267e71e2/raw/197fcf2478cc7ee77afaa4d200f908ccdccbc822/ftp.json")
.pipe(gulp.dest("./"));
}
}); // should wait here, and only continue once the download completes.
// read FTP credentials fromt ftp.json
var host = json.read("./ftp.json").get("dev.host"),
user = json.read("./ftp.json").get("dev.user"),
pass = json.read("./ftp.json").get("dev.pass"),
path = json.read("./ftp.json").get("dev.path");
// read dist FTP credentials from ftp.json (if --dist is passed)
if (argv.dist) {
host = json.read("./ftp.json").get("dist.host"),
user = json.read("./ftp.json").get("dist.user"),
pass = json.read("./ftp.json").get("dist.pass"),
path = json.read("./ftp.json").get("dist.path");
}
// reconfigure ftp.json if a field is empty or if --config is passed
if (host === "" || user === "" || pass === "" || argv.config) {
gulp.src("./ftp.json")
.pipe(prompt.prompt([{
// prompt for the hostname
type: "input",
name: "host",
message: "host:",
default: host,
},
{
// prompt for the username
type: "input",
name: "user",
message: "username:",
default: user,
},
{
// prompt for the password
type: "password",
name: "pass",
message: "password:",
default: pass,
},
{
// prompt for the remote path
type: "input",
name: "path",
message: "remote path:",
default: path,
}], function(res) {
// open the ftp.json
var file = json.read("./ftp.json");
// set connection to dev
var connection = "dev";
// set connection to dist (if --dist is passed)
if (argv.dist) {
connection = "dist";
}
// update the file contents
file.set(connection + ".host", res.host);
file.set(connection + ".user", res.user);
file.set(connection + ".pass", res.pass);
file.set(connection + ".path", res.path);
// write the updated file contents
file.writeSync();
}));
}
// create the FTP connection
var conn = ftp.create({
host: host,
user: user,
pass: pass,
path: path,
})
// upload the changed files
return gulp.src(ftpDirectory + "/**/*")
.pipe(conn.newer(path))
.pipe(conn.dest(path));
})
我使用gulp-download
的下載功能,如果該事項。如果這意味着我可以得到這個工作,我會很樂意轉移到別的東西上。
我會separe這些不同的任務分解成不同的任務,然後,將它們添加爲依賴關係鏈接在一起,接下來的任務將只依賴啓動後完成[任務相關](https://github.com/gulpjs/gulp /blob/master/docs/recipes/running-tasks-in-series.md) – rmjoia
謝謝,將着眼於此。 – JacobTheDev
好吧,我到了類似的問題在我的新任務'FTP-init',其中只包含了下載的「完成」下載完成之前運行英寸嗯。 – JacobTheDev