const fs = require("fs");
const path = require("path");

const targets = process.argv.slice(2);

if (targets.length === 0) {
  console.error("Usage: node scripts/clean-output-dir.js <path...>");
  process.exit(1);
}

function removeDir(target) {
  fs.rmSync(target, {
    recursive: true,
    force: true,
    maxRetries: 8,
    retryDelay: 120,
  });
}

for (const target of targets) {
  const resolved = path.resolve(process.cwd(), target);
  removeDir(resolved);
  fs.mkdirSync(resolved, { recursive: true });
  console.log(`Cleaned ${target}.`);
}
