I want to zip a folder and then I have to delete it in a Gulp task. I'm trying to use archiver in a synchronous way.
I use the code like in the quick start guide in the npm page of archiver and it successfully create the zip file.
But if i try also to delete the zipped folder, then archiver has no enough time to create the zip.
const output = fs.createWriteStream(__dirname + '/example.zip');
//
// code as in https://www.npmjs.com/package/archiver
// ...
archive.finalize();
execSync(
`rm -rf ${config.paths.dest}`,
);
Now I switched to zip-local package and it works in a synch way so I "solved" the problem, but now I'm forced to zip the entire folder, instead of selecting specific files and folders and the output zip is too much bigger.
I'm not an expert and I'm sure this is a problem caused only from my limits in understanding how archiver works.
Could someone help me?
Using archiver, I succeded in doing what I want, deleting the folder inside the "close" event:
output.on('close', function () {
console.log(`Zip created`);
execSync(
`rm -rf ${config.paths.dest}`,
);
});
But I don't like very much this solution.
I tried to use promises and watched a lot o videos but it is a concept that can not remain in my brain and I'm a little bit frustrated.
The best way to do is by using Promise (PromiseAll) here's the example