Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.4 kB · 57 lines
JavaScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758#!/usr/bin/env node
const { execSync } = require("child_process");const fs = require("fs");const path = require("path");const pkg = require("../package.json");
function getGitInfo() { try { const hash = execSync("git rev-parse HEAD", { encoding: "utf-8" }).trim(); const shortHash = execSync("git rev-parse --short HEAD", { encoding: "utf-8", }).trim(); const branch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf-8", }).trim();
let tag; try { tag = execSync("git describe --tags --always --dirty", { encoding: "utf-8", }).trim(); } catch (error) { // git describe fails in shallow clones, use package.json version + short hash tag = `v${pkg.version}-${shortHash}`; }
const isDirty = tag.endsWith("-dirty");
return { hash, shortHash, branch, tag, isDirty, }; } catch (error) { console.warn("Could not get git info:", error.message); return { hash: "unknown", shortHash: "unknown", branch: "unknown", tag: "unknown", isDirty: false, }; }}
const buildInfo = { ...getGitInfo(), buildTime: new Date().toISOString(),};
const outputPath = path.join(__dirname, "..", "src", "build-info.json");fs.writeFileSync(outputPath, JSON.stringify(buildInfo, null, 2));
console.log("Generated build-info.json:", buildInfo);