#!/usr/bin/env node
import CJS_COMPAT_NODE_URL from 'node:url';
import CJS_COMPAT_NODE_PATH from 'node:path';
import CJS_COMPAT_NODE_MODULE from "node:module";

const __filename = CJS_COMPAT_NODE_URL.fileURLToPath(import.meta.url);
const __dirname = CJS_COMPAT_NODE_PATH.dirname(__filename);
const require = CJS_COMPAT_NODE_MODULE.createRequire(import.meta.url);
// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
  a as t
} from "../_node-chunks/chunk-FKZAYFJ3.js";
import {
  a as i,
  e as n
} from "../_node-chunks/chunk-JNV2AX5Q.js";
import {
  a as l
} from "../_node-chunks/chunk-5G5PMXGR.js";
import {
  a,
  f as g
} from "../_node-chunks/chunk-HRN2KQZP.js";

// src/bin/dispatcher.ts
import { spawn as m } from "node:child_process";
import { logger as u } from "storybook/internal/node-logger";
var d = g(l(), 1);
var [c, p] = process.versions.node.split(".").map(Number);
(c < 20 || c === 20 && p < 19 || c === 22 && p < 12) && (u.error(
  d.dedent`To run Storybook, you need Node.js version 20.19+ or 22.12+.
    You are currently running Node.js ${process.version}. Please upgrade your Node.js installation.`
), process.exit(1));
async function k() {
  let e = process.argv.slice(2);
  if (["dev", "build", "index"].includes(e[0])) {
    await import(i(n("storybook"), "dist/bin/core.js"));
    return;
  }
  let o = e[0] === "init" ? {
    pkg: "create-storybook",
    args: e.slice(1)
  } : {
    pkg: "@storybook/cli",
    args: e
  }, s;
  try {
    let { default: r } = await import(`${o.pkg}/package.json`, {
      with: { type: "json" }
    });
    r.version === t[o.pkg] && (s = [
      "node",
      i(n(o.pkg), "dist/bin/index.js"),
      ...o.args
    ]);
  } catch {
  }
  s ??= ["npx", "--yes", `${o.pkg}@${t[o.pkg]}`, ...o.args], m(s[0], s.slice(1), { stdio: "inherit", shell: !0 }).on("exit", (r) => {
    process.exit(r);
  });
}
a(k, "run");
k();
