import { spawnSync } from "node:child_process";

function commandExists(command) {
  const result = spawnSync(command, ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()"], {
    stdio: "ignore",
    windowsHide: true
  });

  return result.status === 0;
}

export function findPowerShell() {
  for (const candidate of ["pwsh", "powershell"]) {
    if (commandExists(candidate)) {
      return candidate;
    }
  }

  return "powershell";
}
