Created
May 27, 2023 09:42
-
-
Save bramtechs/16c5de0e54254aeea8d71d429481373d to your computer and use it in GitHub Desktop.
Provide a zipped version of the client in the dist directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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