【发布时间】:2023-04-01 07:00:01
【问题描述】:
所以我有一个令人难以置信的想法,我的应用程序抓取了一个 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();
【问题讨论】:
-
存档代码在隔离时完美运行,并且已经引入了 repo
标签: javascript node.js async-await path