Last active
February 24, 2023 08:44
-
-
Save coskuntekin/9a22b45d43ccefa8cb108369b64f073e to your computer and use it in GitHub Desktop.
Set version number to VERSION.txt and env.production file
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 { createWriteStream, readFileSync, writeFileSync } from "node:fs"; | |
import { stdin as input, stdout as output } from "node:process"; | |
import { execSync } from "node:child_process"; | |
import * as readline from "node:readline/promises"; | |
let currentSplitVersion; | |
let currentVersion; | |
let currentMajor; | |
let currentMinor; | |
let currentPatch; | |
try { | |
currentVersion = readFileSync("VERSION.txt", "utf8"); | |
currentSplitVersion = currentVersion.slice(1).split("."); | |
currentMajor = currentSplitVersion[0]; | |
currentMinor = currentSplitVersion[1]; | |
currentPatch = currentSplitVersion[2]; | |
} catch (error) { | |
console.error(error); | |
} | |
let userInputMajor; | |
let userInputMinor; | |
let userInputPatch; | |
try { | |
const rl = readline.createInterface({ input, output }); | |
const version = await rl.question( | |
`\u001b[33mInput version number (Current version is ${currentVersion})? \u001b[0m` | |
); | |
const splitVersion = version.split("."); | |
userInputMajor = splitVersion[0]; | |
userInputMinor = splitVersion[1]; | |
userInputPatch = splitVersion[2]; | |
rl.close(); | |
const logger = createWriteStream("VERSION.txt", { | |
flags: "w", | |
}); | |
const writeLine = (line) => logger.write(line); | |
writeLine("v" + version); | |
console.log("Written version number to VERSION.txt"); | |
const data = readFileSync(".env.production", "utf8"); | |
const envVersion = currentMajor + "-" + currentMinor + "-" + currentPatch; | |
const regex = new RegExp(envVersion, "gmi"); | |
const newValue = data.replace( | |
regex, | |
userInputMajor + "-" + userInputMinor + "-" + userInputPatch | |
); | |
writeFileSync(".env.production", newValue, "utf-8"); | |
console.log("Written version number to .env.production"); | |
} catch (error) { | |
console.error(error); | |
} | |
try { | |
console.log("🛠 Build for production"); | |
execSync("yarn run vite build --mode production", { | |
stdio: "inherit", | |
}); | |
} catch (error) { | |
console.log(error); | |
} | |
try { | |
console.log("🗜️ Compress dist folder"); | |
execSync("tar czf dist.tar.gz dist"); | |
} catch (error) { | |
console.log(error); | |
} | |
const zipFileName = `v${userInputMajor}-${userInputMinor}-${userInputPatch}.tar.gz`; | |
try { | |
console.log("🖊️ Rename folder name"); | |
execSync(`mv dist.tar.gz ${zipFileName}`); | |
} catch (error) { | |
console.log(error); | |
} | |
try { | |
console.log("🚚 Move to downloads folder"); | |
execSync(`mv ${zipFileName} ~/Downloads`); | |
} catch (error) { | |
console.log(error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment