#!/usr/bin/env node
// Copyright (c) 2026 phluzz.com. All rights reserved.

import { access } from "node:fs/promises";
import { spawn } from "node:child_process";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const binary = process.platform === "win32" ? "workflow.exe" : "workflow";
const nativePath = join(dirname(fileURLToPath(import.meta.url)), binary);

try {
  await access(nativePath);
} catch {
  console.error("workflow native binary is not installed. Run workflow-install.");
  process.exit(1);
}

const child = spawn(nativePath, process.argv.slice(2), { stdio: "inherit" });
child.on("exit", (code, signal) => {
  if (signal) {
    process.kill(process.pid, signal);
  }
  process.exit(code ?? 1);
});
