From 893d8c03d22743fddd27744207ef2788f94af837 Mon Sep 17 00:00:00 2001 From: Kartavya Patel <82671701+patelka2211@users.noreply.github.com> Date: Mon, 20 Nov 2023 13:06:48 +0530 Subject: [PATCH] Automatic release creator done. --- .gitignore | 4 +++- create-release.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 ++++- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 create-release.js diff --git a/.gitignore b/.gitignore index ca7c165..dd7915e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ /node_modules -package-lock.json \ No newline at end of file +package-lock.json + +release.zip \ No newline at end of file diff --git a/create-release.js b/create-release.js new file mode 100644 index 0000000..765a37c --- /dev/null +++ b/create-release.js @@ -0,0 +1,54 @@ +const archiver = require("archiver"); +const fs = require("fs"); +const path = require("path"); + +// Create a writable stream for the zip file +const output = fs.createWriteStream("release.zip"); +const archive = archiver("zip", { + zlib: { level: 9 }, // compression level +}); + +// Specify the files and folders to be included in the zip +const filesToZip = [ + "back-end/bin/index.cjs.js", + "front-end/out/", + "LICENSE", + "package.json", + "README.md", +]; + +// Listen for all archive data to be written +output.on("close", () => { + console.log(`${archive.pointer()} total bytes`); + console.log( + "archiver has been finalized and the output file descriptor has closed." + ); +}); + +archive.on("warning", (err) => { + if (err.code === "ENOENT") { + console.warn(err); + } else { + // throw error + throw err; + } +}); + +archive.on("error", (err) => { + throw err; +}); + +// Pipe archive data to the file +archive.pipe(output); + +// Add files and folders to the archive +filesToZip.forEach((fileOrFolder) => { + const fullPath = path.resolve(__dirname, fileOrFolder); + const stats = fs.statSync(fullPath); + + if (stats.isDirectory()) archive.directory(fullPath, fileOrFolder); + else archive.file(fullPath, { name: fileOrFolder }); +}); + +// Finalize the archive (write the zip file) +archive.finalize(); diff --git a/package.json b/package.json index 727870d..273800e 100644 --- a/package.json +++ b/package.json @@ -40,5 +40,8 @@ "express": "^4.18.2", "open": "^8.4.2", "table": "^6.8.1" + }, + "devDependencies": { + "archiver": "^6.0.1" } -} \ No newline at end of file +}