#!/usr/bin/env node

var version = process.version;
var [majorVersion, minorVersion] = version.replace("v", "").split(".");
if (Number(majorVersion) < 18) {
  console.error(
    "Builder.io Dev Tools requires Node.js 18.11 or higher. You are currently running Node.js " +
      version,
  );
  process.exit(1);
} else if (Number(majorVersion) === 18) {
  if (Number(minorVersion) < 4) {
    console.error(
      "Builder.io Dev Tools requires Node.js 18.4 or higher. You are currently running Node.js" +
        version,
    );
    process.exit(1);
  } else if (Number(minorVersion) < 11) {
    console.error(
      "Node.js 18.11 or higher is REQUIRED. From Node 18.0.0 to 18.11.0, there is a bug preventing correct behaviour of Builder.io. You are currently running Node.js " +
        version,
    );
  }
}

// Filter out any PATH entries that contain "builder-electron-node-bin"
// This prevents fake node paths from the CLI caller from being passed through
if (process.env.PATH) {
  const pathSeparator = process.platform === "win32" ? ";" : ":";
  const pathEntries = process.env.PATH.split(pathSeparator);
  const filteredPaths = pathEntries.filter(
    (pathEntry) => !pathEntry.includes("builder-electron-node-bin"),
  );
  process.env.PATH = filteredPaths.join(pathSeparator);
}

require("./index.cjs");
