import { readFile } from "node:fs/promises";
import { execFileSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { sourceFiles, sourceDigest } from "./source-files.mjs";
const root = fileURLToPath(new URL("..", import.meta.url));
const untracked = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], { cwd: root }).toString().trim().split("\n").filter(path => /^(app|lib|worker|public|scripts|db|drizzle|build|types)\//.test(path));
if (untracked.length) throw new Error(`Stage new source files before publishing: ${untracked.join(", ")}`);
const manifest = JSON.parse(await readFile(new URL("../lib/source-manifest.json", import.meta.url), "utf8"));
if (!manifest.head) console.log("Local fork: public Git packaging has not been enabled.");
else if (sourceDigest(await sourceFiles(root)) !== manifest.sourceDigest) throw new Error("Public Git source is out of date. Stage source files and run npm run source:package before building.");
else console.log(`Public source matches this build: ${manifest.head.slice(0, 8)}`);
