Skip to content

Commit

Permalink
Merge pull request #26918 from fastfrwrd/fastfrwrd/25510-no-dev-for-init
Browse files Browse the repository at this point in the history
CLI: Add optional `--dev` and `--no-dev` options to `storybook init` CLI
(cherry picked from commit e60fc12)
  • Loading branch information
valentinpalkovic authored and storybook-bot committed Jun 13, 2024
1 parent f10eb79 commit 5362ff6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ command('init')
.option('-y --yes', 'Answer yes to all prompts')
.option('-b --builder <webpack5 | vite>', '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));
});
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli/src/generators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export type CommandOptions = {
disableTelemetry?: boolean;
enableCrashReports?: boolean;
debug?: boolean;
dev?: boolean;
};
2 changes: 1 addition & 1 deletion code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions docs/api/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Options include:
| `--debug` | Outputs more logs in the CLI to assist debugging<br/>`storybook init --debug` |
| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.md#how-to-opt-out)<br/>`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)<br/>`storybook init --enable-crash-reports` |
| `--no-dev` | Complete the initialization of Storybook without running the Storybook dev server<br/>`storybook init --no-dev` |

### `add`

Expand Down

0 comments on commit 5362ff6

Please sign in to comment.