Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Add optional --dev and --no-dev options to storybook init CLI #26918

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions code/lib/cli/src/generate.ts
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
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
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
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
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