From c3e3ab9ee446a98f84b5f39ff789e141d336cc43 Mon Sep 17 00:00:00 2001 From: paul-marbach_jpmc Date: Mon, 22 Apr 2024 16:33:29 -0400 Subject: [PATCH 1/3] feat: #25510 add optional --no-dev option to storybook init CLI --- code/lib/cli/src/generate.ts | 11 +++++++++++ code/lib/cli/src/generators/types.ts | 1 + code/lib/cli/src/initiate.ts | 2 +- docs/api/cli-options.md | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) 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..bce9a401214d 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..f982af8e4459 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/docs/api/cli-options.md b/docs/api/cli-options.md index a1f8c4369fff..13d0a72889b5 100644 --- a/docs/api/cli-options.md +++ b/docs/api/cli-options.md @@ -118,6 +118,8 @@ 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` | +| `--dev` | Launch the development server after completing initialization. Enabled by default
`storybook init --dev` | +| `--no-dev` | Complete the initialization of Storybook without running the Storybook dev server
`storybook init --no-dev` | ### `add` From b300ae3a78fe39ff14c4598aaba92f6670f70c37 Mon Sep 17 00:00:00 2001 From: paul-marbach_jpmc Date: Tue, 23 Apr 2024 09:29:20 -0400 Subject: [PATCH 2/3] chore: clean up the usage of doInitiate in sandbox task --- code/lib/cli/src/generators/types.ts | 2 +- code/lib/cli/src/initiate.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code/lib/cli/src/generators/types.ts b/code/lib/cli/src/generators/types.ts index bce9a401214d..5a8f7350f9bf 100644 --- a/code/lib/cli/src/generators/types.ts +++ b/code/lib/cli/src/generators/types.ts @@ -53,5 +53,5 @@ export type CommandOptions = { disableTelemetry?: boolean; enableCrashReports?: boolean; debug?: boolean; - dev: boolean; + dev?: boolean; }; diff --git a/code/lib/cli/src/initiate.ts b/code/lib/cli/src/initiate.ts index f982af8e4459..9a901d103947 100644 --- a/code/lib/cli/src/initiate.ts +++ b/code/lib/cli/src/initiate.ts @@ -405,7 +405,8 @@ export async function doInitiate(options: CommandOptions): Promise< ); return { - shouldRunDev: options.dev, + shouldRunDev: + options.dev ?? (process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANBOX !== 'true'), projectType, packageManager, storybookCommand, From c0ca9edc4f080b73985040ebc38340cd86b5f949 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 14 May 2024 11:22:16 +0200 Subject: [PATCH 3/3] Small refactor --- code/lib/cli/src/initiate.ts | 3 +-- code/lib/cli/src/sandbox.ts | 1 + docs/api/cli-options.md | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/code/lib/cli/src/initiate.ts b/code/lib/cli/src/initiate.ts index 9a901d103947..9d54c099f19b 100644 --- a/code/lib/cli/src/initiate.ts +++ b/code/lib/cli/src/initiate.ts @@ -405,8 +405,7 @@ export async function doInitiate(options: CommandOptions): Promise< ); return { - shouldRunDev: - options.dev ?? (process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANBOX !== '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 13d0a72889b5..0b586198703b 100644 --- a/docs/api/cli-options.md +++ b/docs/api/cli-options.md @@ -118,7 +118,6 @@ 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` | -| `--dev` | Launch the development server after completing initialization. Enabled by default
`storybook init --dev` | | `--no-dev` | Complete the initialization of Storybook without running the Storybook dev server
`storybook init --no-dev` | ### `add`