diff --git a/code/lib/cli/src/generate.ts b/code/lib/cli/src/generate.ts index b5aa64f7f77d..a1a3d83ddfbb 100644 --- a/code/lib/cli/src/generate.ts +++ b/code/lib/cli/src/generate.ts @@ -58,6 +58,17 @@ command('init') .option('-y --yes', 'Answer yes to all prompts') .option('-b --builder ', 'Builder library') .option('-l --linkable', 'Prepare installation for link (contributor helper)') + // due to how Commander handles default values and negated options, we have to elevate the default into Commander, and we have to specify `--dev` + // alongside `--no-dev` even if we are unlikely to directly use `--dev`. https://github.com/tj/commander.js/issues/2068#issuecomment-1804524585 + .option( + '--dev', + 'Launch the development server after completing initialization. Enabled by default', + process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANDBOX !== 'true' + ) + .option( + '--no-dev', + 'Complete the initialization of Storybook without launching the Storybook development server' + ) .action((options: CommandOptions) => { initiate(options).catch(() => process.exit(1)); }); diff --git a/code/lib/cli/src/generators/types.ts b/code/lib/cli/src/generators/types.ts index 763df2c4d1a6..5a8f7350f9bf 100644 --- a/code/lib/cli/src/generators/types.ts +++ b/code/lib/cli/src/generators/types.ts @@ -53,4 +53,5 @@ export type CommandOptions = { disableTelemetry?: boolean; enableCrashReports?: boolean; debug?: boolean; + dev?: boolean; }; diff --git a/code/lib/cli/src/initiate.ts b/code/lib/cli/src/initiate.ts index 4d83666780b2..9d54c099f19b 100644 --- a/code/lib/cli/src/initiate.ts +++ b/code/lib/cli/src/initiate.ts @@ -405,7 +405,7 @@ export async function doInitiate(options: CommandOptions): Promise< ); return { - shouldRunDev: process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANDBOX !== 'true', + shouldRunDev: !!options.dev, projectType, packageManager, storybookCommand, diff --git a/code/lib/cli/src/sandbox.ts b/code/lib/cli/src/sandbox.ts index d06c633c1a4d..621d62976c10 100644 --- a/code/lib/cli/src/sandbox.ts +++ b/code/lib/cli/src/sandbox.ts @@ -225,6 +225,7 @@ export const sandbox = async ({ process.chdir(templateDestination); // we run doInitiate, instead of initiate, to avoid sending this init event to telemetry, because it's not a real world project await doInitiate({ + dev: process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANBOX !== 'true', ...options, }); process.chdir(before); diff --git a/docs/api/cli-options.md b/docs/api/cli-options.md index 7177cce8caef..ae2cb3d779f1 100644 --- a/docs/api/cli-options.md +++ b/docs/api/cli-options.md @@ -119,6 +119,7 @@ Options include: | `--debug` | Outputs more logs in the CLI to assist debugging
`storybook init --debug` | | `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.md#how-to-opt-out)
`storybook init --disable-telemetry` | | `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.md#crash-reports-disabled-by-default)
`storybook init --enable-crash-reports` | +| `--no-dev` | Complete the initialization of Storybook without running the Storybook dev server
`storybook init --no-dev` | ### `add`