#!/usr/bin/env node
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const skillDir = path.resolve(__dirname, "..");
const sampleDir = path.join(skillDir, "assets", "zhenyu-ai-prep-0530");

const args = process.argv.slice(2);
const force = args.includes("--force");
const targetArg = args.find((arg) => arg !== "--force");

if (!targetArg) {
  console.error("Usage: node scaffold-prep-site.mjs <target-dir> [--force]");
  process.exit(1);
}

const targetDir = path.resolve(process.cwd(), targetArg);

if (fs.existsSync(targetDir) && !force) {
  console.error(`Target exists: ${targetDir}`);
  console.error("Use --force only after confirming it is safe to overwrite files.");
  process.exit(1);
}

fs.mkdirSync(targetDir, { recursive: true });

for (const filename of ["index.html", "styles.css", "script.js"]) {
  fs.copyFileSync(path.join(sampleDir, filename), path.join(targetDir, filename));
}

const todo = `# Next Steps

This site was scaffolded from the Zhenyu AI prep reference.

Update these before preview/deploy:
- Company name, short brand mark, course name, course date
- Prep deadline and deadline strip
- Tool/platform links
- Required prep tasks and classroom materials
- Checklist items and final note
- Page title, description, OG title/description, footer

Then preview locally and deploy with:

\`\`\`bash
npx wrangler pages deploy . --project-name <project-slug> --branch main
\`\`\`
`;

fs.writeFileSync(path.join(targetDir, "PREP_SITE_TODO.md"), todo, "utf8");
console.log(`Created prep site scaffold at ${targetDir}`);

