Skip to content

Instantly share code, notes, and snippets.

@bramtechs
Created May 27, 2023 09:42
Show Gist options
  • Save bramtechs/16c5de0e54254aeea8d71d429481373d to your computer and use it in GitHub Desktop.
Save bramtechs/16c5de0e54254aeea8d71d429481373d to your computer and use it in GitHub Desktop.
Provide a zipped version of the client in the dist directory.
import { zip } from "zip-a-folder";
import fs from "fs";
const FOLDER = "./dist/client";
const ZIP_OUT = "./dist/client/packages/latest.zip";
async function run() {
// check if directory exists
if (!fs.existsSync(FOLDER)) {
throw new Error(`Directory ${dir} does not exist. Did you build the client?`);
}
// delete old zip
if (fs.existsSync(ZIP_OUT)) {
fs.unlinkSync(ZIP_OUT);
console.log(`Deleted ${ZIP_OUT}...`);
}
const folder = ZIP_OUT.substring(0, ZIP_OUT.lastIndexOf("/"));
fs.mkdirSync(folder, { recursive: true });
console.log(`Creating ${ZIP_OUT}...`);
await zip(FOLDER, ZIP_OUT);
console.log(`Created ${ZIP_OUT}...`);
// write version file of parent node package
const packageJson = JSON.parse(fs.readFileSync("./package.json"));
const info = {
displayName: packageJson.displayName,
version: packageJson.version,
};
fs.writeFileSync(folder + "/app.json", JSON.stringify(info, null, 2));
console.log(`Wrote ${folder}/app.json...`);
}
await run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment