Skip to content

Instantly share code, notes, and snippets.

@mhsattarian
Last active July 25, 2022 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhsattarian/d2aae73eee894e6cc49f7c3f612cf64c to your computer and use it in GitHub Desktop.
Save mhsattarian/d2aae73eee894e6cc49f7c3f612cf64c to your computer and use it in GitHub Desktop.
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