Bakes the git short commit hash into the client bundle at build time and exposes the same info from the server via GET /api/version. The header displays the loaded build's commit and flags when it no longer matches what the server is running, so a stale open tab is easy to spot after a deploy. The Docker build now includes .git so the hash can be resolved during the image build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
20 lines
530 B
JavaScript
20 lines
530 B
JavaScript
const { execSync } = require('node:child_process');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
function getCommit() {
|
|
try {
|
|
return execSync('git rev-parse --short HEAD', { cwd: __dirname }).toString().trim();
|
|
} catch {
|
|
return 'dev';
|
|
}
|
|
}
|
|
|
|
const version = {
|
|
commit: getCommit(),
|
|
builtAt: new Date().toISOString(),
|
|
};
|
|
|
|
const outDir = path.join(__dirname, '..', 'dist');
|
|
fs.mkdirSync(outDir, { recursive: true });
|
|
fs.writeFileSync(path.join(outDir, 'version.json'), JSON.stringify(version));
|