import { buildSiteAtomic, withSiteBuildLock } from "./site-build.mjs";

try {
  const build = () => buildSiteAtomic({ onOutput: (text) => process.stdout.write(text) });
  if (process.argv.includes("--inside-lock")) {
    if (process.env.QIYOUXUE_SITE_LOCK_HELD !== "1") throw new Error("build:inside-lock 只能在共享构建锁中运行");
    await build();
  } else {
    await withSiteBuildLock(build);
  }
} catch (error) {
  console.error(error instanceof Error ? error.message : error);
  process.exitCode = 1;
}
