// Writes src/shared/version.gen.ts (gitignored) with the "Build n" version: // n = commit count since the repo root, Sublime Text style. Regenerated by // postinstall and by every dev/build/release script — never committed, since // committing it would bump the very count it records. import path from "node:path"; function git(args: string[]): string | null { try { const proc = Bun.spawnSync(["git", ...args], { cwd: import.meta.dir, stdout: "pipe", stderr: "ignore", }); if (!proc.success) return null; return proc.stdout.toString().trim() || null; } catch { return null; } } const number = Number(git(["rev-list", "--count", "HEAD"]) ?? 0); const commit = git(["rev-parse", "--short", "HEAD"]) ?? "dev"; const date = new Date().toISOString().slice(0, 10); let electrobun = "unknown"; try { const pkg = await Bun.file( path.join(import.meta.dir, "..", "node_modules", "electrobun", "package.json"), ).json(); electrobun = pkg.version; } catch { // not installed yet (postinstall ordering) — fine } const out = `// GENERATED by scripts/gen-version.ts — do not edit, do not commit. export const BUILD = { number: ${number}, commit: ${JSON.stringify(commit)}, date: ${JSON.stringify(date)}, electrobun: ${JSON.stringify(electrobun)}, } as const; `; const target = path.join(import.meta.dir, "..", "src", "shared", "version.gen.ts"); await Bun.write(target, out); console.log(`[version] Build ${number} (${commit}) -> ${path.relative(process.cwd(), target)}`);