Javascript 为什么我的async不能很好地处理第三个调用,但却能很好地处理前两个调用
因此,我有一个令人难以置信的想法,我的应用程序获取了一个git repo(简单git),然后对其中的文件(shelljs)进行npm I,然后使用archiver进行压缩。当然,它需要异步,但第一部分和第二部分可以工作,但在归档时失败了(下一步是axios等待zip完成),同样在这之前,当我使用抓取repo代码运行zip代码时,它会在正确的根目录中创建zip文件,但现在改为在文件夹目录中创建(repo/folder),虽然没有压缩其他内容,但压缩文件现在是空的。如果可以,请提供帮助 守则:Javascript 为什么我的async不能很好地处理第三个调用,但却能很好地处理前两个调用,javascript,node.js,async-await,path,Javascript,Node.js,Async Await,Path,因此,我有一个令人难以置信的想法,我的应用程序获取了一个git repo(简单git),然后对其中的文件(shelljs)进行npm I,然后使用archiver进行压缩。当然,它需要异步,但第一部分和第二部分可以工作,但在归档时失败了(下一步是axios等待zip完成),同样在这之前,当我使用抓取repo代码运行zip代码时,它会在正确的根目录中创建zip文件,但现在改为在文件夹目录中创建(repo/folder),虽然没有压缩其他内容,但压缩文件现在是空的。如果可以,请提供帮助 守则: //
// // //Make call
function makeCall() {
return new Promise((resolve) => {
resolve(
git()
.silent(true)
.clone(remote, ["-b", branch])
.then(() => console.log("finished"))
.catch((err) => console.error("failed: ", err))
);
});
}
//Make NPM Modules
async function makeModules() {
await makeCall();
const pathOfFolder = path.join(__dirname, "folder/sub");
shell.cd(pathOfFolder)
return new Promise((resolve) => {
resolve(
shell.exec("npm i"));
});
}
async function makeZip() {
await makeModules();
const output = fs.createWriteStream(`${branch}.zip`);
const archive = archiver("zip");
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log(
"archiver has been finalized and the output file descriptor has closed."
);
});
archive.pipe(output);
// append files from a sub-directory, putting its contents at the root of archive
archive.directory("folder", false);
// append files from a sub-directory and naming it `new-subdir` within the archive
archive.directory("subdir/", "new-subdir");
archive.finalize();
}
makeZip();
解决它,移动到其他文件并正确设置路径存档程序代码在隔离且已引入回购时工作正常