Skip to content

Instantly share code, notes, and snippets.

Last active July 25, 2022 15:13
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`
const date = new Date();
const jdate = date.toLocaleDateString("fa-IR-u-nu-latn");
let version = jdate
.map((i) => i % 100)
if (currentVersion.startsWith(version))
version += `-${parseInt(currentVersion.split("-")[1] || 1) + 1}`;
await $`npm version ${version} --no-git-tag-version`;
Copy link

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