import fs from "node:fs/promises";
import path from "node:path";
import { execFileSync } from "node:child_process";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(__dirname, "..");
const distZipPath = path.join(rootDir, "dist", "Sensa_basic_v1.0.0.zip");
const siteDownloadsDir = path.join(rootDir, "site", "downloads");
const siteZipPath = path.join(siteDownloadsDir, "Sensa_basic_v1.0.0.zip");

await fs.mkdir(siteDownloadsDir, { recursive: true });
await fs.copyFile(distZipPath, siteZipPath);

execFileSync("npx", ["wrangler@latest", "pages", "deploy", "site", "--project-name", "sensa-basic", "--commit-dirty=true"], {
  cwd: rootDir,
  stdio: "inherit"
});
