Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d6bb263

Browse files
mandariniFrozenPandaz
authored andcommittedApr 11, 2023
fix(storybook): v7 gen docs and install react deps (#16057)
(cherry picked from commit c91c365)
1 parent d6b80b3 commit d6bb263

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed
 

‎docs/generated/packages/storybook/documents/storybook-7-setup.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@ You can generate Storybook configuration for an individual project with this com
5656
nx g @nrwl/storybook:configuration project-name --storybook7Configuration --storybook7UiFramework=@storybook/react-webpack5
5757
```
5858

59+
Make sure to use the framework-specific generators if your project is using Angular, React, Next.js or React Native: [`@nrwl/angular:storybook-configuration`](/packages/angular/generators/storybook-configuration), [`@nrwl/react:storybook-configuration`](/packages/react/generators/storybook-configuration), [`@nrwl/react-native:storybook-configuration`](/packages/react-native/generators/storybook-configuration), for example:
60+
61+
```shell
62+
nx g @nrwl/angular:storybook-configuration my-angular-project --storybook7Configuration
63+
```
64+
5965
{% callout type="info" title="For Nx versions <15.9" %}
6066
The flag is called `storybook7betaConfiguration` for Nx versions <15.9.
6167
{% /callout %}
6268

63-
In the field `storybook7UiFramework` you must choose one of the following Storybook frameworks:
69+
If you are NOT using a framework-specific generator, in the field `storybook7UiFramework` you must choose one of the following Storybook frameworks:
6470

6571
- `@storybook/angular`
6672
- `@storybook/html-webpack5`
@@ -81,15 +87,15 @@ In the field `storybook7UiFramework` you must choose one of the following Storyb
8187

8288
In Storybook 7, [the `framework` field in `.storybook/main.js|ts` is mandatory](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#framework-field-mandatory). You must choose one of the above frameworks when setting up your application.
8389

84-
If you are using one of the framework-specific generators (e.g. [`@nrwl/angular:storybook-configuration`](/packages/angular/generators/storybook-configuration), or [`@nrwl/react:storybook-configuration`](/packages/react/generators/storybook-configuration) for React and Nextjs projects, or [`@nrwl/react-native:storybook-configuration`](/packages/react-native/generators/storybook-configuration), the generator will automatically choose the correct framework for you.
90+
If you are using one of the framework-specific generators, the generator will automatically choose the correct framework for you.
8591

8692
Choosing one of these frameworks will have the following effects on your workspace:
8793

8894
1. Nx will install all the required Storybook packages that go with it.
8995

9096
2. Nx will generate a root `.storybook` folder and a project-level `.storybook` folder (located under `libs/your-project/.storybook` or `apps/your-project/.storybook`) containing the essential configuration files for Storybook.
9197

92-
3. If you are working on an Angular, a React or a React Native project (and you choose `@storybook/angular`, `@storybook/react` or `@storybook/react-native`) the Nx generator will also generate stories for all the components in your project.
98+
3. If you are working on an Angular, a React or a React Native project and you use one of the framework-specific generators, Nx will also generate stories for all the components in your project.
9399

94100
4. Nx will create new `targets` in your project's `project.json`, called `storybook` and `build-storybook`, containing all the necessary configuration to serve and build Storybook.
95101

‎docs/shared/packages/storybook/storybook-7-setup.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@ You can generate Storybook configuration for an individual project with this com
5656
nx g @nrwl/storybook:configuration project-name --storybook7Configuration --storybook7UiFramework=@storybook/react-webpack5
5757
```
5858

59+
Make sure to use the framework-specific generators if your project is using Angular, React, Next.js or React Native: [`@nrwl/angular:storybook-configuration`](/packages/angular/generators/storybook-configuration), [`@nrwl/react:storybook-configuration`](/packages/react/generators/storybook-configuration), [`@nrwl/react-native:storybook-configuration`](/packages/react-native/generators/storybook-configuration), for example:
60+
61+
```shell
62+
nx g @nrwl/angular:storybook-configuration my-angular-project --storybook7Configuration
63+
```
64+
5965
{% callout type="info" title="For Nx versions <15.9" %}
6066
The flag is called `storybook7betaConfiguration` for Nx versions <15.9.
6167
{% /callout %}
6268

63-
In the field `storybook7UiFramework` you must choose one of the following Storybook frameworks:
69+
If you are NOT using a framework-specific generator, in the field `storybook7UiFramework` you must choose one of the following Storybook frameworks:
6470

6571
- `@storybook/angular`
6672
- `@storybook/html-webpack5`
@@ -81,15 +87,15 @@ In the field `storybook7UiFramework` you must choose one of the following Storyb
8187

8288
In Storybook 7, [the `framework` field in `.storybook/main.js|ts` is mandatory](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#framework-field-mandatory). You must choose one of the above frameworks when setting up your application.
8389

84-
If you are using one of the framework-specific generators (e.g. [`@nrwl/angular:storybook-configuration`](/packages/angular/generators/storybook-configuration), or [`@nrwl/react:storybook-configuration`](/packages/react/generators/storybook-configuration) for React and Nextjs projects, or [`@nrwl/react-native:storybook-configuration`](/packages/react-native/generators/storybook-configuration), the generator will automatically choose the correct framework for you.
90+
If you are using one of the framework-specific generators, the generator will automatically choose the correct framework for you.
8591

8692
Choosing one of these frameworks will have the following effects on your workspace:
8793

8894
1. Nx will install all the required Storybook packages that go with it.
8995

9096
2. Nx will generate a root `.storybook` folder and a project-level `.storybook` folder (located under `libs/your-project/.storybook` or `apps/your-project/.storybook`) containing the essential configuration files for Storybook.
9197

92-
3. If you are working on an Angular, a React or a React Native project (and you choose `@storybook/angular`, `@storybook/react` or `@storybook/react-native`) the Nx generator will also generate stories for all the components in your project.
98+
3. If you are working on an Angular, a React or a React Native project and you use one of the framework-specific generators, Nx will also generate stories for all the components in your project.
9399

94100
4. Nx will create new `targets` in your project's `project.json`, called `storybook` and `build-storybook`, containing all the necessary configuration to serve and build Storybook.
95101

‎packages/storybook/src/generators/init/init.ts

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
litVersion,
2121
nxVersion,
2222
reactNativeStorybookLoader,
23+
reactVersion,
2324
storybook7Version,
2425
storybookReactNativeVersion,
2526
storybookVersion,
@@ -42,6 +43,21 @@ function checkDependenciesInstalled(host: Tree, schema: Schema) {
4243
devDependencies['@nrwl/storybook'] = nxVersion;
4344

4445
if (schema.storybook7Configuration) {
46+
// Needed for Storybook 7
47+
// https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-peer-dependencies-required
48+
if (
49+
!packageJson.dependencies['react'] &&
50+
!packageJson.devDependencies['react']
51+
) {
52+
dependencies['react'] = reactVersion;
53+
}
54+
if (
55+
!packageJson.dependencies['react-dom'] &&
56+
!packageJson.devDependencies['react-dom']
57+
) {
58+
dependencies['react-dom'] = reactVersion;
59+
}
60+
4561
if (schema.uiFramework === '@storybook/react-native') {
4662
devDependencies['@storybook/react-native'] = storybookReactNativeVersion;
4763
} else {

‎packages/storybook/src/utils/versions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ export const litVersion = '^2.6.1';
1717
export const htmlWebpackPluginVersion = '^5.5.0';
1818
export const tsNodeVersion = '10.9.1';
1919

20-
export const storybook7Version = '^7.0.0-rc.0';
20+
export const storybook7Version = '^7.0.1';
21+
export const reactVersion = '^18.2.0';

0 commit comments

Comments
 (0)
Please sign in to comment.