#!/usr/bin/env node
/**
 * Copies your built SonarQube MCP .jar into vendor/ for publishing.
 *
 * Usage:
 *   node scripts/bundle-sonarqube.mjs <path-to.jar>
 *
 * Or set SONARQUBE_MCP_JAR_SRC.
 */
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
const vendor = path.join(root, "vendor");
fs.mkdirSync(vendor, { recursive: true });

const src = process.argv[2] || process.env.SONARQUBE_MCP_JAR_SRC?.trim();
if (!src) {
  console.error(
    "Usage: node scripts/bundle-sonarqube.mjs <path-to-sonarqube-mcp-server.jar>\n" +
      "   or: SONARQUBE_MCP_JAR_SRC=... node scripts/bundle-sonarqube.mjs"
  );
  process.exit(1);
}
if (!fs.existsSync(src)) {
  console.error(`Source not found: ${src}`);
  process.exit(1);
}

const dest = path.join(vendor, "sonarqube-mcp-server.jar");
fs.copyFileSync(src, dest);
console.log(`Bundled: ${src} -> ${dest}`);
