// @bun
import {
  createCliLogger
} from "./chunk-t993tmz7.js";
import {
  require_semver
} from "./chunk-2a5b6azq.js";
import {
  __toESM
} from "./chunk-dhs2bg35.js";

// src/utils/node-version-check.ts
var semver = __toESM(require_semver(), 1);
import { execSync } from "child_process";
var REQUIRED_NODE_VERSION = "22.0.0";
function getCurrentNodeVersion() {
  try {
    const version = execSync("node -v", { encoding: "utf-8" }).trim();
    return version.replace(/^v/, "");
  } catch {
    return null;
  }
}
function checkNodeVersion(silent = false) {
  const logger = createCliLogger({ silent });
  const currentVersion = getCurrentNodeVersion();
  if (!currentVersion) {
    logger.error(`
\u2717 Node.js Not Found`);
    logger.error(`  Node.js is required to run Botpress ADK`);
    logger.error(`  Minimum required version: ${REQUIRED_NODE_VERSION}
`);
    logger.warn("  Please install Node.js:");
    logger.info(`    https://nodejs.org/
`);
    return false;
  }
  const current = semver.parse(currentVersion);
  const required = semver.parse(REQUIRED_NODE_VERSION);
  if (!current || !required) {
    logger.warn(`\u26A0\uFE0F  Could not parse Node.js version: ${currentVersion}`);
    return false;
  }
  if (semver.lt(current, required)) {
    logger.error(`
\u2717 Node.js Version Too Old`);
    logger.error(`  Current version: ${currentVersion}`);
    logger.error(`  Minimum required: ${REQUIRED_NODE_VERSION}
`);
    logger.warn("  Please upgrade Node.js:");
    logger.info(`    https://nodejs.org/
`);
    return false;
  }
  logger.info(`\u2713 Node.js ${currentVersion}`, "green");
  return true;
}
function requireNodeVersion() {
  if (!checkNodeVersion()) {
    process.exit(1);
  }
}
function getNodeVersionInfo() {
  const current = getCurrentNodeVersion();
  const isSatisfied = current ? semver.gte(current, REQUIRED_NODE_VERSION) : false;
  return {
    current,
    required: REQUIRED_NODE_VERSION,
    isSatisfied
  };
}

export { checkNodeVersion, requireNodeVersion, getNodeVersionInfo };
