From 57b966d7c08f02d31f4d1c80b70a741d1a78b509 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 6 Nov 2023 22:40:20 +0100 Subject: [PATCH] [yarn] Add regen-version script --- package.json | 3 ++- scripts/regen-version.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 scripts/regen-version.js diff --git a/package.json b/package.json index 677390153..8584ab7fb 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "clean": "node ./scripts/clean.js", "clean-all": "node ./scripts/clean-all.js", "cleanall": "yarn clean-all", - "focus-production": "node ./scripts/focus-production.js" + "focus-production": "node ./scripts/focus-production.js", + "regen-version": "node ./scripts/regen-version.js" }, "workspaces": [ "packages/backend", diff --git a/scripts/regen-version.js b/scripts/regen-version.js new file mode 100644 index 000000000..a25c62839 --- /dev/null +++ b/scripts/regen-version.js @@ -0,0 +1,16 @@ +const { join } = require("node:path"); +const fs = require("node:fs"); +const exec = require("execa"); + +(async () => { + const file = join(__dirname, "../package.json"); + const json = require(file); + + const match = json['version'].match(/^[\d.]*(?:-pre\d+|)?/); + const version = match ? `${match[0]}-dev` : "dev"; + const { stdout: revision } = await exec("git", ["rev-parse", "--short", "HEAD"]);; + + json['version'] = `${version}-${revision}`; + console.log(json['version']); + fs.writeFileSync(file, JSON.stringify(json, null, '\t')); +})();