From 8d4194772e4ef4746a852c49745abb7c7d09cab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Thu, 28 Dec 2023 20:38:45 +0000 Subject: [PATCH] build: include commit hash in version.txt --- scripts/write-version.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/write-version.mjs b/scripts/write-version.mjs index 5efa414..cdf71ab 100644 --- a/scripts/write-version.mjs +++ b/scripts/write-version.mjs @@ -2,10 +2,13 @@ import { readFileSync, writeFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname } from 'node:path'; +import { execSync } from 'node:child_process'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); +const commitHash = execSync('git rev-parse --short HEAD').toString('utf-8').trim(); + const pkgJson = JSON.parse(readFileSync(__dirname + '/../package.json', 'utf-8')); -const pkgVer = (pkgJson.version ?? 'unknown') + '\n'; +const pkgVer = `${pkgJson.version ?? 'unknown'}-${commitHash ?? 'unknown'}` + '\n'; writeFileSync(__dirname + '/../dist/version.txt', pkgVer, 'utf-8');