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

if (process.env.SKIP_BUNDLE_CHECK === "1") {
  console.log("[verify-bundle] SKIP_BUNDLE_CHECK=1 — skipping vendor check.");
  process.exit(0);
}

const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
const jar = path.join(root, "vendor", "sonarqube-mcp-server.jar");

if (!fs.existsSync(jar)) {
  console.error(`[verify-bundle] Missing bundled JAR: ${jar}`);
  console.error(
    "Run: node scripts/bundle-sonarqube.mjs <path-to-your-sonarqube-mcp-server.jar>\n" +
      "Or set SKIP_BUNDLE_CHECK=1 to publish without vendor (not recommended for end users)."
  );
  process.exit(1);
}

console.log("[verify-bundle] SonarQube MCP vendor JAR OK.");
