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__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, {
  get: (a, o) => (typeof require < "u" ? require : a)[o]
}) : e)(function(e) {
  if (typeof require < "u") return require.apply(this, arguments);
  throw Error('Dynamic require of "' + e + '" is not supported');
});

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

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

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