Live video on the AT Protocol
at eli/optional-convergence 57 lines 1.4 kB view raw
1#!/usr/bin/env node 2 3const { execSync } = require("child_process"); 4const fs = require("fs"); 5const path = require("path"); 6const pkg = require("../package.json"); 7 8function getGitInfo() { 9 try { 10 const hash = execSync("git rev-parse HEAD", { encoding: "utf-8" }).trim(); 11 const shortHash = execSync("git rev-parse --short HEAD", { 12 encoding: "utf-8", 13 }).trim(); 14 const branch = execSync("git rev-parse --abbrev-ref HEAD", { 15 encoding: "utf-8", 16 }).trim(); 17 18 let tag; 19 try { 20 tag = execSync("git describe --tags --always --dirty", { 21 encoding: "utf-8", 22 }).trim(); 23 } catch (error) { 24 // git describe fails in shallow clones, use package.json version + short hash 25 tag = `v${pkg.version}-${shortHash}`; 26 } 27 28 const isDirty = tag.endsWith("-dirty"); 29 30 return { 31 hash, 32 shortHash, 33 branch, 34 tag, 35 isDirty, 36 }; 37 } catch (error) { 38 console.warn("Could not get git info:", error.message); 39 return { 40 hash: "unknown", 41 shortHash: "unknown", 42 branch: "unknown", 43 tag: "unknown", 44 isDirty: false, 45 }; 46 } 47} 48 49const buildInfo = { 50 ...getGitInfo(), 51 buildTime: new Date().toISOString(), 52}; 53 54const outputPath = path.join(__dirname, "..", "src", "build-info.json"); 55fs.writeFileSync(outputPath, JSON.stringify(buildInfo, null, 2)); 56 57console.log("Generated build-info.json:", buildInfo);