import ESM_COMPAT_Module from "node:module";
import { fileURLToPath as ESM_COMPAT_fileURLToPath } from 'node:url';
import { dirname as ESM_COMPAT_dirname } from 'node:path';
const __filename = ESM_COMPAT_fileURLToPath(import.meta.url);
const __dirname = ESM_COMPAT_dirname(__filename);
const require = ESM_COMPAT_Module.createRequire(import.meta.url);
var t = /* @__PURE__ */ ((o) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(o, {
  get: (c, e) => (typeof require < "u" ? require : c)[e]
}) : o)(function(o) {
  if (typeof require < "u") return require.apply(this, arguments);
  throw Error('Dynamic require of "' + o + '" is not supported');
});

// src/bin/index.ts
import { spawn as k } from "node:child_process";
import { readFileSync as a } from "node:fs";
import { dirname as p, join as i } from "node:path";

// src/common/versions.ts
var s = {
  "@storybook/addon-a11y": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/addon-docs": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/addon-jest": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/addon-links": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/addon-onboarding": "0.0.0-pr-31893-sha-9eb4ec95",
  "storybook-addon-pseudo-states": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/addon-themes": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/addon-vitest": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/builder-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/builder-webpack5": "0.0.0-pr-31893-sha-9eb4ec95",
  storybook: "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/angular": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/ember": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/html-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/nextjs": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/experimental-nextjs-rsc": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/nextjs-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/preact-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/react-native-web-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/react-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/react-webpack5": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/server-webpack5": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/svelte-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/sveltekit": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/vue3-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/web-components-vite": "0.0.0-pr-31893-sha-9eb4ec95",
  sb: "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/cli": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/codemod": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/core-webpack": "0.0.0-pr-31893-sha-9eb4ec95",
  "create-storybook": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/csf-plugin": "0.0.0-pr-31893-sha-9eb4ec95",
  "eslint-plugin-storybook": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/react-dom-shim": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/preset-create-react-app": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/preset-react-webpack": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/preset-server-webpack": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/html": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/preact": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/react": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/server": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/svelte": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/vue3": "0.0.0-pr-31893-sha-9eb4ec95",
  "@storybook/web-components": "0.0.0-pr-31893-sha-9eb4ec95"
};

// src/bin/index.ts
var r = process.argv.slice(2);
if (["dev", "build", "index"].includes(r[0]))
  t("storybook/internal/cli/bin");
else {
  let o;
  if (r[0] === "init") {
    let e;
    try {
      e = t.resolve("create-storybook/package.json");
    } catch {
    }
    e ? JSON.parse(a(e, "utf-8")).version === s["create-storybook"] && (o = [
      "node",
      i(p(e), "bin", "index.cjs"),
      ...r.slice(1)
    ]) : o = ["npx", "--yes", `create-storybook@${s.storybook}`, ...r.slice(1)];
  } else {
    let e;
    try {
      e = t.resolve("@storybook/cli/package.json");
    } catch {
    }
    e ? JSON.parse(a(e, "utf-8")).version === s["@storybook/cli"] && (o = ["node", i(p(e), "bin", "index.cjs"), ...r]) : o = ["npx", "--yes",
    `@storybook/cli@${s.storybook}`, ...r];
  }
  o || (console.error("Could not run storybook cli, please report this as a bug"), process.exit(1)), k(o[0], o.slice(1), { stdio: "inherit",
  shell: !0 }).on("exit", (e) => {
    e != null && process.exit(e), process.exit(1);
  });
}
