所以我有一个令人难以置信的问题,我的应用程序获取一个git repo(简单git(,然后在里面的文件(shelljs(上生成一个npm I,然后使用archiver压缩。当然,它需要异步,但第一部分和第二部分可以工作,但在归档时失败了(下一步是让axios等待zip完成(,在此之前,当我用抓取的repo代码运行zip代码时,它会在正确的根目录中创建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();
解决它,移动到其他文件并正确设置路径