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

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

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

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