21 lines
1002 B
JavaScript
21 lines
1002 B
JavaScript
// Writes dist/buildInfo.json after tsc so every deployed build carries its provenance.
|
|
// Why: "is commit X actually live?" was unanswerable except by behavior — functions:log's
|
|
// lagging window caused a false outage alarm and a mis-attributed landmine cause, and a
|
|
// stale committed dist shipped twice before anyone could tell (FUNCTIONS-DIST-STALE).
|
|
// With this, one log line at cold start answers it. Fail-safe: no git → "unknown".
|
|
const { execSync } = require('node:child_process')
|
|
const { writeFileSync, mkdirSync } = require('node:fs')
|
|
|
|
function run(cmd) {
|
|
try { return execSync(cmd, { encoding: 'utf8' }).trim() } catch { return 'unknown' }
|
|
}
|
|
|
|
const info = {
|
|
sha: run('git rev-parse --short HEAD'),
|
|
branch: run('git rev-parse --abbrev-ref HEAD'),
|
|
builtAt: new Date().toISOString(),
|
|
}
|
|
mkdirSync('dist', { recursive: true })
|
|
writeFileSync('dist/buildInfo.json', JSON.stringify(info, null, 2) + '\n')
|
|
console.log(`[stamp-build] ${info.sha} (${info.branch}) built ${info.builtAt}`)
|