Skip to content

Instantly share code, notes, and snippets.

@mhsattarian
Last active July 25, 2022 15:13
Embed
What would you like to do?
Use current Jalali Date as NPM package version. run with zx.
#!/usr/bin/env zx
const branch = (await $`git branch --show-current`).stdout.trim();
if (branch === "debug") {
const currentVersion = (
await $`awk '/version/{gsub(/("|",)/,"",$2);print $2}' package.json`
).stdout.trim();
const date = new Date();
const jdate = date.toLocaleDateString("fa-IR-u-nu-latn");
let version = jdate
.split("/")
.map((i) => i % 100)
.join(".");
if (currentVersion.startsWith(version))
version += `-${parseInt(currentVersion.split("-")[1] || 1) + 1}`;
await $`npm version ${version} --no-git-tag-version`;
}
@mhsattarian
Copy link
Author

in order to run, make sure zx is installed.
this script can be used as a git hook, take a look at husky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment