fix windows archive issue #10

Merged
roman merged 1 commits from dev into master 2 years ago
  1. 45
      helpers.js

45
helpers.js

@ -126,46 +126,33 @@ export function capitalize(str) {
export async function zipProject(srcDir, outputFileName = 'dist.zip') { export async function zipProject(srcDir, outputFileName = 'dist.zip') {
// create a file to stream archive data to. // create a file to stream archive data to.
const output = await fsExtra.createWriteStream(outputFileName); const output = await fsExtra.createWriteStream(outputFileName);
const archive = archiver('zip', {});
// listen for all archive data to be written return new Promise((resolve, reject) => {
// 'close' event is fired only when a file descriptor is involved // Create a file to write the archive data
output.on('close', function () { const archive = archiver('zip', {
console.log(archive.pointer() + ' total bytes'); zlib: {level: 9} // Compression level
console.log('archiver has been finalized and the output file descriptor has closed.');
});
// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
output.on('end', function () {
console.log('Data has been drained');
}); });
// good practice to catch warnings (ie stat failures and other non-blocking errors) // Listen for errors on the archiver
archive.on('warning', function (err) { archive.on('error', function (err) {
if (err.code === 'ENOENT') { reject(err);
// log warning
} else {
// throw error
throw err;
}
}); });
// good practice to catch this error explicitly // Handle closure of the output file stream
archive.on('error', function (err) { output.on('close', function () {
throw err; console.log(`Archive created successfully and it is ${archive.pointer()} total bytes`);
resolve();
}); });
// pipe archive data to the file // Pipe archive data to the file
archive.pipe(output); archive.pipe(output);
// append files from a subdirectory, putting its contents at the root of archive // Add files to the archive
archive.directory(srcDir, false); archive.directory(srcDir, false);
// finalize the archive (ie we are done appending files but streams have to finish yet) // Finalize the archive - this is very important to ensure the file stream is finished
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand archive.finalize();
await archive.finalize(); });
} }
export async function buildExportFiles(blockName, platform) { export async function buildExportFiles(blockName, platform) {

Loading…
Cancel
Save