Skip to content

Commit

Permalink
ADDED: Release package builder script
Browse files Browse the repository at this point in the history
  • Loading branch information
SagnikGanguly96 committed Dec 14, 2022
1 parent 4dc1d8d commit 5f5e607
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions build/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2022 SGNetworks. All rights reserved.
*
* The software is an exclusive copyright of "SGNetworks" and is provided as is exclusively with only "USAGE" access. "Modification", "Alteration", "Re-distribution" is completely prohibited.
* VIOLATING THE ABOVE TERMS IS A PUNISHABLE OFFENSE WHICH MAY LEAD TO LEGAL CONSEQUENCES.
*/

const fs = require("fs"),
archiver = require("archiver"),
args = require("./args.js"),
info = require("../package.json");

/**
* Creates a new release for the build
* @param {string} [flavor=free] The flavor of the build
*/
const createRelease = function(flavor = "free") {
const name = (flavor === "pro") ? `SGNUIKit v${info.version} (Stable)-Pro` : `SGNUIKit v${info.version} (Stable)`,
file = `release\\${name}.zip`;
if(fs.existsSync(file)) {
console.warn(`The release '${name}' already exists.`);
console.warn(`Deleting release: ${name}...`);
fs.unlinkSync(file);
}

const output = fs.createWriteStream(file),
archive = archiver("zip", {zlib: {level: 9}});

output.on("close", function() {
console.log(archive.pointer() + " total bytes");
console.log("Archiver has been finalized and the output file descriptor has closed.");
});

archive.on("warning", function(err) {
throw err;
});

archive.on("error", function(err) {
throw err;
});

archive.pipe(output);

// append files from a subdirectory, putting its contents at the root of archive
archive.directory("dist/", false);

archive.finalize().then(r => console.log(`The release '${name}' has been created.`));
};

if(args.flavor === "free" || args.flavor === "pro") {
console.info(`Creating release with build flavor: ${args.flavor}`);
createRelease(args.flavor);
} else
console.error(`Failed to create release: Invalid flavor supplied: ${args.flavor}`);

0 comments on commit 5f5e607

Please sign in to comment.