Files
TX/scripts/update-version.mjs
T
riyadhafraa 80429920b9 Add automatic build version generation from git
Implement a script to automatically generate build version information from git commit hash and date, updating version.json and creating latest.json.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 77cfe984-2c65-4152-bb7a-0df28274fe66
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: ab5429c1-7925-4a30-a964-b3db9c5772da
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/c3c252e4-c83d-40ca-9fff-99a3ea60701e/77cfe984-2c65-4152-bb7a-0df28274fe66/1WKAcHk
Replit-Helium-Checkpoint-Created: true
2026-05-17 15:16:02 +00:00

33 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
import { execSync } from "node:child_process";
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
const __dirname = dirname(fileURLToPath(import.meta.url));
const versionPath = resolve(__dirname, "..", "version.json");
function git(args) {
return execSync(`git ${args}`, { encoding: "utf8" }).trim();
}
let commit = "unknown";
let date = new Date().toISOString().slice(0, 10).replace(/-/g, "");
try {
commit = git("log -1 --format=%h");
date = git("log -1 --format=%cd --date=format:%Y%m%d");
} catch (err) {
console.warn(`[update-version] git unavailable, using fallback: ${err.message}`);
}
const build = `${date}.${commit}`;
const current = JSON.parse(readFileSync(versionPath, "utf8"));
const next = { ...current, build };
if (current.build === build) {
console.log(`[update-version] build unchanged: ${build}`);
} else {
writeFileSync(versionPath, JSON.stringify(next, null, 2) + "\n");
console.log(`[update-version] ${current.build} -> ${build}`);
}