javascript - 为什么我的 async 在第三个调用中不能很好地工作,但在前两个调用中却很完美
问题描述
所以我有一个令人难以置信的想法,我的应用程序抓取了一个 git repo(simple-git)然后在里面的文件(shelljs)上创建一个 npm i,然后使用归档器压缩。当然它需要是异步的,但是第一部分和第二部分可以工作,但是在归档时它失败了(下一步是让 axios 等待 zip 完成),在此之前,当我用抓取运行邮政编码时repo 代码它会在正确的根目录中创建 zip 文件,但现在在文件夹目录中创建 (repo/folder) ,虽然现在 zip 是空的,但不是压缩其他内容。如果可以,请提供帮助代码:
// // //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();
解决方案
解决它,移动到其他文件并正确设置路径
推荐阅读
- google-cloud-platform - 最佳实践 GCP - GKE | 多种服务
- r - 如何根据来自另一个 data.frame 的信息更新一个 data.frame
- macos - 如何修复“zsh:找不到命令:vue”?
- ssh - Vagrant:登录没有 ssh 私钥的用户帐户
- rxjs - 订阅 observable 后点击
- python - 如何在两个图像类别(二进制)上重用具有多个图像类别的预训练模型
- c++ - 如何在 NS-3 或 DCE-NS-3 中获取当前数据速率或可用带宽值?
- keras - Keras fit 与 fit_generator 额外的 smaples
- list - 我可以将 Moshi @JsonQualifier 应用于类型参数吗?
- html - 使用 Tika 从文本文件 XML、HTML 等中提取文本