#!/usr/bin/env node

/**
 * Build script — builds both web and api.
 * Usage: node scripts/build.mjs
 */

import { execSync } from "node:child_process";

const ROOT = new URL("..", import.meta.url).pathname;

function run(cmd, cwd) {
  console.log(`\n🔨 ${cmd} (in ${cwd})`);
  execSync(cmd, { cwd, stdio: "inherit" });
}

console.log("🏗️  Building fullstack project...\n");

try {
  run("npm run build", `${ROOT}/apps/api`);
  run("npm run build", `${ROOT}/apps/web`);
  console.log("\n✅ Build complete!");
} catch (e) {
  console.error("\n❌ Build failed:", e.message);
  process.exit(1);
}
