build: include commit hash in version.txt

This commit is contained in:
Jixun Wu 2023-12-28 20:38:45 +00:00
parent 8f2d306835
commit 07d6dba277
1 changed files with 4 additions and 1 deletions

View File

@ -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');