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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Adds commands to the documentation #25589

Merged
merged 12 commits into from
Jan 22, 2024
82 changes: 25 additions & 57 deletions docs/addons/install-addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,79 @@
title: 'Install addons'
---

Storybook has [hundreds of reusable addons](https://storybook.js.org/addons) that are packaged as NPM modules. Let's walk through how to extend Storybook by installing and registering addons.
Storybook has [hundreds of reusable addons](https://storybook.js.org/integrations) packaged as NPM modules. Let's walk through how to extend Storybook by installing and registering addons.

### Using addons
## Automatic installation

With the exception of preset addons, all addons have the same installation process: install and register.
Storybook includes a [`storybook add`](../api/cli-options.md#add) command to automate the setup of addons. Several community-led addons can be added using this command, except for preset addons. We encourage you to read the addon's documentation to learn more about its installation process.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a feature comment/question than a documentation one.

except for preset addons

I didn't realize the add command had this limitation. How do we expect users to know the difference? Is this a short-term limitation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shilman ☝️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can’t it handle preset style addons?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are any addons where add fails, we should figure out what’s going on and fix the issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can’t it handle preset style addons?

I was just going on what was documented here. If that limitation isn't factual, that's great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we're all on the same page here, this isn't on us. Our presets are working; what I've encountered during my rounds collecting community addons is basically this, I've run into situations where preset addons failed to register. I cannot know for sure what's causing it, could be an outdated version or something of that nature. Hence why I left it as such so that we don't run into any situations where a user faces a similar question, reach out to us raising an issue/ discussion when the situation is out of our control.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please share a scenario where you had this failure? Thanks!


For example, to include accessibility testing in Storybook, run the following command to install the necessary addon:
Run the `storybook add` command using your chosen package manager, and the CLI will update your Storybook configuration to include the addon and install any necessary dependencies.

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-a11y-install.yarn.js.mdx',
'common/storybook-a11y-install.npm.js.mdx',
'common/storybook-a11y-install.pnpm.js.mdx',
'common/storybook-add-command.yarn.js.mdx',
'common/storybook-add-command.npm.js.mdx',
'common/storybook-add-command.pnpm.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

Next, update [`.storybook/main.js|ts`](../configure/index.md#configure-story-rendering) to the following:
<Callout variant="warning">

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-a11y-register.js.mdx',
'common/storybook-a11y-register.ts.mdx',
]}
/>

<!-- prettier-ignore-end -->

<Callout variant="info">

Addons may also require addon-specific configuration. Read their respective READMEs.
If you're attempting to install multiple addons at once, it will only install the first addon that was specified. This is a known limitation of the current implementation and will be addressed in a future release.
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved

</Callout>

Now when you run Storybook the accessibility testing addon will be enabled.

![Storybook addon installed and registered](./storybook-addon-installed-registered.png)

### Using preset addons
### Manual installation

Storybook preset addons are grouped collections of specific `babel`, `webpack` and `addons` configurations for distinct use cases. Each one with its own set of instructions. Preset addons have a three-step installation process: install, register and optionally configuration.
Storybook addons are always added through the [`addons`](../api/main-config-addons.md) configuration array in [`.storybook/main.js|ts`](../configure/index.md). The following example shows how to manually add the [Accessibility addon](https://storybook.js.org/addons/@storybook/addon-a11y) to Storybook.

For example, to use SCSS styling, run the following command to install the addon and the required dependencies:
Run the following command with your package manager of choice to install the addon.

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-preset-scss.webpack-4.js.mdx',
'common/storybook-preset-scss.webpack-5.js.mdx',
'common/storybook-a11y-install.yarn.js.mdx',
'common/storybook-a11y-install.npm.js.mdx',
'common/storybook-a11y-install.pnpm.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

<Callout variant="info" icon="💡" title="Tip:">

Use the Webpack 5 snippet only if your framework already includes support for this version. Otherwise, use the Webpack 4 snippet.

</Callout>

Next, update [`.storybook/main.js|ts`](../configure/index.md#configure-story-rendering) to the following:
Next, update `.storybook/main.js|ts` to the following:

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-main-preset-config.js.mdx',
'common/storybook-main-preset-config.ts.mdx',
'common/storybook-a11y-register.js.mdx',
'common/storybook-a11y-register.ts.mdx',
]}
/>

<!-- prettier-ignore-end -->

Now when you run Storybook it will configure itself to use SCSS styling. No further configuration is needed.

#### Optional configuration
When you run Storybook, the accessibility testing addon will be enabled.

Most preset addons can also take additional parameters. The most common use cases are:
![Storybook addon installed and registered](./storybook-addon-installed-registered.png)

- Addon configuration
- Webpack loader configuration
### Removing addons

Consider the following example:
To remove an addon from Storybook, you can choose to manually uninstall it and remove it from the configuration file (i.e., [`.storybook/main.js|ts`](../configure/index.md)) or opt-in to do it automatically via the CLI with the [`remove`](../api/cli-options.md#remove) command. For example, to remove the [Accessibility addon](https://storybook.js.org/addons/@storybook/addon-a11y) from Storybook with the CLI, run the following command:

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-preset-configuration.js.mdx',
'common/storybook-preset-configuration.ts.mdx',
'common/storybook-remove-command.yarn.js.mdx',
'common/storybook-remove-command.npm.js.mdx',
'common/storybook-remove-command.pnpm.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

<Callout variant="info">

Preset addons may also have addon-specific configurations. Read their respective READMEs.

</Callout>

Now, when Storybook starts up, it will update webpack's CSS loader to use modules and adjust how styling is defined.
156 changes: 152 additions & 4 deletions docs/api/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ Storybook collects completely anonymous data to help us improve user experience.

All of the following documentation is available in the CLI by running `storybook --help`.

<Callout variant="info" icon="💡">

The commands work slightly differently if you're using npm instead of Yarn to publish Storybook. For example, `npm run storybook build -- -o ./path/to/build`.

</Callout>

### `dev`

Compiles and serves a development build of your Storybook that reflects your source code changes in the browser in real time. Should be run from the root of your project.
Compiles and serves a development build of your Storybook that reflects your source code changes in the browser in real-time. It should be run from the root of your project.

```shell
storybook dev [options]
Expand Down Expand Up @@ -52,7 +58,7 @@ With the release of Storybook 8, the `-s` CLI flag was removed. We recommend usi

### `build`

Compiles your Storybook instance so it can be [deployed](../sharing/publish-storybook.md). Should be run from the root of your project.
Compiles your Storybook instance so it can be [deployed](../sharing/publish-storybook.md). It should be run from the root of your project.

```shell
storybook build [options]
Expand All @@ -74,8 +80,150 @@ Options include:
| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.md).<br/>`storybook build --disable-telemetry` |
| `--test` | Optimize Storybook's production build for performance and tests by removing unnecessary features with the `test` option. Learn more [here](../api/main-config-build.md).<br/>`storybook build --test` |

<Callout variant="info" icon="💡">
<!-- Re-read this for accuracy -->

### `init`

Installs Storybook into your project per specified version (e.g., `@latest`, `@next`). Read more in the [installation guide](../get-started/install.md).

```shell
storybook[@version] init [options]
```

Options include:

| Option | Description |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `-b`, `--builder` | Defines the [builder](../builders/index.md) to use for your Storybook instance<br/>`storybook init --builder webpack5` |
| `-f`,`--force` | Forcefully installs Storybook into your project, prompting you to overwrite existing files<br/>`storybook init --force` |
| `-s`, `--skip-install` | Skips the dependency installation step. Used only when you need to configure Storybook manually<br/>`storybook init --skip-install` |
| `-t`, `--type` | Defines the [framework](../configure/frameworks.md) to use for your Storybook instance<br/>`storybook init --type solid` |
| `-y`, `--yes` | Skips interactive prompts and automatically installs Storybook per specified version<br/>`storybook init --yes` |
| `--package-manager` | Sets the package manager to use when installing the addon.<br/> Available package managers include `npm`, `yarn`, and `pnpm`<br/>`storybook init --package-manager pnpm` |
| `--use-pnp` | Enables [Plug'n'Play](https://yarnpkg.com/features/pnp) support for Yarn. This option is only available when using Yarn as your package manager<br/>`storybook init --use-pnp` |

### `add`
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved

Installs a Storybook addon and configures your project for it. Read more in the [addon installation guide](../addons/install-addons.md).

```shell
storybook add [addon] [options]
```

Options include:

| Option | Description |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--package-manager` | Sets the package manager to use when installing the addon.<br/> Available package managers include `npm`, `yarn`, and `pnpm`<br/>`storybook add [addon] --package-manager pnpm` |
| `-s`, `--skip-postinstall` | Skips post-install configuration. Used only when you need to configure the addon yourself<br/>`storybook add [addon] --skip-postinstall` |

### `remove`

Deletes a Storybook addon from your project. Read more in the [addon installation guide](../addons/install-addons.md#removing-addons).

```shell
storybook remove [addon] [options]
```

Options include:

| Option | Description |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--package-manager` | Sets the package manager to use when removing the addon.<br/>Available package managers include `npm`, `yarn`, and `pnpm`<br/>`storybook remove [addon]--package-manager pnpm` |

### `upgrade`

Upgrades your Storybook instance to the latest version. Read more in the [upgrade guide](../configure/upgrading.md).
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved

```shell
storybook upgrade [options]
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved
```

Options include:

| Option | Description |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-c`, `--config-dir` | Directory where to load Storybook configurations from<br/>`storybook upgrade --config-dir .storybook` |
| `-n`, `--dry-run` | Checks for version upgrades without installing them<br/>`storybook upgrade --dry-run` |
| `-s`, `--skip-check` | Skips the migration check step during the upgrade process<br/> `storybook upgrade --skip-check` |
| `-y`, `--yes` | Skips interactive prompts and automatically upgrades Storybook to the latest version<br/>`storybook upgrade --yes` |
| `--package-manager` | Sets the package manager to use when installing the addon.<br/> Available package managers include `npm`, `yarn`, and `pnpm`<br/>`storybook upgrade --package-manager pnpm` |

### `doctor`

Performs a health check on your Storybook project for common issues (e.g., duplicate dependencies, incompatible addons or mismatched versions) and provides suggestions on how to fix them. Applicable when [upgrading](../configure/upgrading.md#verifying-the-upgrade) Storybook versions.

```shell
storybook doctor [options]
```

Options include:

| Option | Description |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-c`, `--config-dir` | Directory where to load Storybook configurations from<br/>`storybook doctor --config-dir .storybook` |
| `--package-manager` | Sets the package manager to use when running the health check.<br/>Available package managers include `npm`, `yarn`, and `pnpm`<br/>`storybook doctor --package-manager pnpm` |

### `info`

Reports useful debugging information about your environment. Helpful in providing information when opening an issue or a discussion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to mention Github here? or even a link to the repo?


```shell
storybook info
```

Example output:

```shell
Storybook Environment Info:

System:
OS: macOS 14.2
CPU: (8) arm64 Apple M3
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm <----- active
Browsers:
Chrome: 120.0.6099.199
npmPackages:
@storybook/addon-essentials: ^7.6.6 => 7.6.6
@storybook/addon-interactions: ^7.6.6 => 7.6.6
@storybook/addon-links: ^7.6.6 => 7.6.6
@storybook/addon-onboarding: ^1.0.10 => 1.0.10
@storybook/blocks: ^7.6.6 => 7.6.6
@storybook/preset-create-react-app: ^7.6.6 => 7.6.6
@storybook/react: ^7.6.6 => 7.6.6
@storybook/react-webpack5: ^7.6.6 => 7.6.6
@storybook/test: ^7.6.6 => 7.6.6
storybook: ^7.6.6 => 7.6.6
npmGlobalPackages:
chromatic: ^10.2.0 => 10.2.0
```

### `sandbox`

Generates a local sandbox project for testing Storybook features based on the list of supported [frameworks](../configure/frameworks.md). Useful for reproducing bugs when opening an issue or a discussion.

```shell
storybook sandbox [framework-filter] [options]
```

<Callout variant="info">

The `framework-filter` argument is optional and can filter the list of available frameworks. For example, `storybook sandbox react` will only show React-based sandboxes.
Copy link
Member

@yannbf yannbf Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `framework-filter` argument is optional and can filter the list of available frameworks. For example, `storybook sandbox react` will only show React-based sandboxes.
The `framework-filter` argument is optional and can filter the list of available frameworks. For example, `storybook sandbox` will prompt you with a list of all available sandboxes, where `storybook sandbox react` will only show React-based sandboxes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a placeholder, as the CLI options need to be accounted for the CLI versioning.


</Callout>

Options include:

| Option | Description |
| --------------------------- | ---------------------------------------------------------------------------------------------------- |
| `-o`, `--output [dir-name]` | Configures the location of the sandbox project<br/>`storybook sandbox --output /my-sandbox-project` |
| `--no-init` | Generates a sandbox project without without initializing Storybook<br/>`storybook sandbox --no-init` |

<Callout variant="info">

If you're using npm instead of yarn to publish Storybook, the commands work slightly different. For example, `npm run storybook build -- -o ./path/to/build`.
If you're looking for a hosted version of the available sandboxes, see [storybook.new](https://storybook.new).

</Callout>
24 changes: 20 additions & 4 deletions docs/configure/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ To help ease the pain of keeping Storybook up-to-date, we provide a command-line
paths={[
'common/storybook-upgrade.npm.js.mdx',
'common/storybook-upgrade.pnpm.js.mdx',
'common/storybook-upgrade.yarn.js.mdx'
'common/storybook-upgrade.yarn.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

After running the command the script will:
After running the command, the script will:

- Upgrade all Storybook packages in your project to the latest stable version
- Run the relevant [automigrations](../migration-guide.md#automatic-upgrade) factoring in the [breaking changes](../migration-guide.md#major-breaking-changes) between your current version and the latest stable version
Expand All @@ -33,17 +33,33 @@ In addition to running the command, we also recommend checking the [MIGRATION.md

</Callout>

### Verifying the upgrade

To help you verify that the upgrade was completed and that your project is still working as expected, the Storybook CLI provides the [`doctor`](../api/cli-options.md#doctor) command that allows you to do a health check on your project for common issues that might arise after an upgrade, such as duplicated dependencies, incompatible addons or mismatched versions. To perform the health check, run the following command with your package manager of choice:

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-doctor.npm.js.mdx',
'common/storybook-doctor.pnpm.js.mdx',
'common/storybook-doctor.yarn.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

## Automigrate script

Storybook upgrades are not the only thing to consider: changes in the ecosystem also present challenges. For example, lots of frameworks ([Angular 12](https://angular.io/guide/updating-to-version-12#breaking-changes-in-angular-version-12), [Create React App v5](https://github.com/facebook/create-react-app/pull/11201), [NextJS](https://nextjs.org/docs/upgrading#webpack-5)) have recently migrated from [Webpack 4 to Webpack 5](https://webpack.js.org/migrate/5/), so even if you don't upgrade your Storybook version, you might need to update your configuration accordingly. That's what Automigrate is for:
Storybook upgrades are not the only thing to consider: changes in the ecosystem also present challenges. For example well-known frontend frameworks, such as [Angular](https://update.angular.io/?l=2&v=16.0-17.0), [Next.js](https://nextjs.org/docs/pages/building-your-application/upgrading) or [Svelte](https://svelte.dev/docs/v4-migration-guide) have been rolling out significant changes to their ecosystem, so even if you don't upgrade your Storybook version, you might need to update your configuration accordingly. That's what Automigrate is for:

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-automigrate.npm.js.mdx',
'common/storybook-automigrate.pnpm.js.mdx',
'common/storybook-automigrate.yarn.js.mdx'
'common/storybook-automigrate.yarn.js.mdx',
]}
/>

Expand Down
3 changes: 3 additions & 0 deletions docs/snippets/common/storybook-add-command.npm.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```shell
npx storybook@latest add @storybook/addon-a11y
```
3 changes: 3 additions & 0 deletions docs/snippets/common/storybook-add-command.pnpm.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```shell
pnpm dlx storybook@latest add @storybook/addon-a11y
```
3 changes: 3 additions & 0 deletions docs/snippets/common/storybook-add-command.yarn.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```shell
yarn dlx storybook@latest add @storybook/addon-a11y
```
3 changes: 3 additions & 0 deletions docs/snippets/common/storybook-doctor.npm.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```shell
npx storybook@latest doctor
```
3 changes: 3 additions & 0 deletions docs/snippets/common/storybook-doctor.pnpm.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```shell
pnpm dlx storybook@latest doctor
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved
```
3 changes: 3 additions & 0 deletions docs/snippets/common/storybook-doctor.yarn.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```shell
yarn dlx storybook@latest doctor
```
Loading