## CHANGES

- Version stamping now includes package.json version plus short git hash 🧩
- Local build label switched to clearer “(local)” suffix for sanity 🏷️
- Script now reads package.json robustly with safe “unknown” fallback 🛡️
- Added proper ESM path resolution using fileURLToPath/dirname utilities 🧭
This commit is contained in:
Pedram Amini
2025-12-29 08:03:50 -06:00
parent b2aa5828dd
commit b6e0d14059

View File

@@ -8,8 +8,14 @@
*/
import { execFileSync, spawn } from 'child_process';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import process from 'process';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
function getGitHash() {
try {
const hash = execFileSync('git', ['rev-parse', '--short=8', 'HEAD'], {
@@ -22,8 +28,18 @@ function getGitHash() {
}
}
function getPackageVersion() {
try {
const packageJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
return packageJson.version;
} catch {
return 'unknown';
}
}
const gitHash = getGitHash();
const version = `LOCAL ${gitHash}`;
const packageVersion = getPackageVersion();
const version = `${packageVersion} ${gitHash} (local)`;
// Set environment variable
process.env.VITE_APP_VERSION = version;