#!/usr/bin/env node
/**
 * Kong Link server CLI — start daemon and manage local runtime.
 */
import { existsSync } from "node:fs";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";

const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const cliEntry = path.join(packageRoot, "dist/manager/cli.js");

if (!existsSync(cliEntry)) {
  process.stderr.write(
    "Kong Link CLI is not built. Reinstall @kong-link/server or run from a built checkout.\n",
  );
  process.exit(1);
}

const { runCommand } = await import(pathToFileURL(cliEntry).href);
const exitCode = await runCommand(process.argv.slice(2));
process.exit(exitCode);
