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 a = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, {
  get: (c, o) => (typeof require < "u" ? require : c)[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 y } from "node:child_process";
import { readFileSync as p } from "node:fs";
import { dirname as b, join as k } from "node:path";

// src/common/versions.ts
var s = {
  "@storybook/addon-a11y": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-actions": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-backgrounds": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-controls": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-docs": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-essentials": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-mdx-gfm": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-highlight": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-interactions": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-jest": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-links": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-measure": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-onboarding": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-outline": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-storysource": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-test": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-themes": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-toolbars": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/addon-viewport": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/builder-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/builder-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  storybook: "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/angular": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/ember": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/experimental-nextjs-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/html-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/html-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/nextjs": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preact-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preact-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/react-native-web-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/react-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/react-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/server-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/svelte-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/svelte-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/sveltekit": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/vue3-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/vue3-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/web-components-vite": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/web-components-webpack5": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/blocks": "0.0.0-pr-30761-sha-c5072ae0",
  sb: "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/cli": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/codemod": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/core-webpack": "0.0.0-pr-30761-sha-c5072ae0",
  "create-storybook": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/csf-plugin": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/react-dom-shim": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/source-loader": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preset-create-react-app": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preset-html-webpack": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preset-preact-webpack": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preset-react-webpack": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preset-server-webpack": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preset-svelte-webpack": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preset-vue3-webpack": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/html": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/preact": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/react": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/server": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/svelte": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/vue3": "0.0.0-pr-30761-sha-c5072ae0",
  "@storybook/web-components": "0.0.0-pr-30761-sha-c5072ae0"
};

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