import { spawnSync } from "node:child_process";
import { rmSync } from "node:fs";
import { BLOG_SITES } from "../src/blog-sites.js";

rmSync("dist", { force: true, recursive: true });

for (const site of BLOG_SITES) {
  console.log(`\nBuilding ${site.title} -> dist/${site.key}`);

  const result = spawnSync("npx", ["astro", "build"], {
    env: {
      ...process.env,
      BLOG_SITE: site.key,
    },
    stdio: "inherit",
  });

  if (result.status !== 0) {
    process.exit(result.status ?? 1);
  }
}
