From 32d438b80bd29db91aca6de341a86d3ed1d0cca7 Mon Sep 17 00:00:00 2001 From: NoCymer <61873313+NoCymer@users.noreply.github.com> Date: Mon, 31 Jul 2023 17:48:09 +0200 Subject: [PATCH] dist auto zipping --- manifest.js | 30 ++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 31 insertions(+) diff --git a/manifest.js b/manifest.js index cbe79f4..6759278 100644 --- a/manifest.js +++ b/manifest.js @@ -1,4 +1,21 @@ const fs = require('fs'); +const archiver = require('archiver'); + +function zipDir(sourceDir, outPath) { + const ar = archiver('zip', { zlib: { level: 9 }}); + const writeStream = fs.createWriteStream(outPath); + + return new Promise((resolve, reject) => { + ar + .directory(sourceDir, false) + .on('error', err => reject(err)) + .pipe(writeStream) + ; + + writeStream.on('close', () => resolve()); + ar.finalize(); + }); +} const args = process.argv; @@ -30,6 +47,19 @@ const main = () => { break; } }); + if (fs.existsSync("./dist/dist.zip")) + fs.rmSync("./dist/dist.zip"); + + if (fs.existsSync("./dist.zip")) + fs.rmSync("./dist.zip"); + + zipDir("./dist", "./dist.zip").then(() => { + fs.copyFileSync("./dist.zip", "./dist/dist.zip"); + + if (fs.existsSync("./dist.zip")) + fs.rmSync("./dist.zip"); + + }); } main(); \ No newline at end of file diff --git a/package.json b/package.json index b59b3aa..3de1a02 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@types/node": "^18.15.13", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", + "archiver": "^5.3.1", "axios": "^1.1.3", "babel-jest": "^29.5.0", "babel-loader": "^8.2.5",