@storybook/angular 7.0.0-beta.61 → 7.0.0-beta.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,9 +2,16 @@
2
2
 
3
3
  - [Storybook for Angular](#storybook-for-angular)
4
4
  - [Getting Started](#getting-started)
5
- - [Setup Compodoc](#setup-compodoc)
6
- - [Support for multi-project workspace](#support-for-multi-project-workspace)
5
+ - [Setup Storybook for your Angular projects](#setup-storybook-for-your-angular-projects)
7
6
  - [Run Storybook](#run-storybook)
7
+ - [Setup Compodoc](#setup-compodoc)
8
+ - [Automatic setup](#automatic-setup)
9
+ - [Manual setup](#manual-setup)
10
+ - [FAQ](#faq)
11
+ - [How do I migrate to a Angular Storybook builder?](#how-do-i-migrate-to-a-angular-storybook-builder)
12
+ - [Do you have only one Angular project in your workspace?](#do-you-have-only-one-angular-project-in-your-workspace)
13
+ - [Adjust your `package.json`](#adjust-your-packagejson)
14
+ - [I have multiple projects in my Angular workspace](#i-have-multiple-projects-in-my-angular-workspace)
8
15
 
9
16
  Storybook for Angular is a UI development environment for your Angular components.
10
17
  With it, you can visualize different states of your UI components and develop them interactively.
@@ -21,15 +28,9 @@ cd my-angular-app
21
28
  npx storybook init
22
29
  ```
23
30
 
24
- ### Setup Compodoc
31
+ ## Setup Storybook for your Angular projects
25
32
 
26
- When installing, you will be given the option to set up Compodoc, which is a tool for creating documentation for Angular projects.
27
-
28
- You can include JSDoc comments above components, directives, and other parts of your Angular code to include documentation for those elements. Compodoc uses these comments to generate documentation for your application. In Storybook, it is useful to add explanatory comments above @Inputs and @Outputs, since these are the main elements that Storybook displays in its user interface. The @Inputs and @Outputs are the elements that you can interact with in Storybook, such as controls.
29
-
30
- ## Support for multi-project workspace
31
-
32
- Storybook supports Angular multi-project workspace. You can setup Storybook for each project in the workspace. When running `npx storybook init` you will be asked for which project Storybook should be set up. Essentially, during initialization, the `angular.json` will be edited to add the Storybook configuration for the selected project. The configuration looks approximately like this:
33
+ Storybook supports Angular multi-project workspace. You can setup Storybook for each project in the workspace. When running `npx storybook init` you will be asked for which project Storybook should be set up. Essentially, during initialization, the `.storybook` folder will be created and the `angular.json` will be edited to add the Storybook configuration for the selected project. The configuration looks approximately like this:
33
34
 
34
35
  ```json
35
36
  // angular.json
@@ -44,10 +45,14 @@ Storybook supports Angular multi-project workspace. You can setup Storybook for
44
45
  "storybook": {
45
46
  "builder": "@storybook/angular:start-storybook",
46
47
  "options": {
48
+ // the path to the storybook config directory
47
49
  "configDir": ".storybook",
50
+ // the build target of your project
48
51
  "browserTarget": "your-project:build",
49
- "compodoc": false,
52
+ // the port you want to start Storybook on
50
53
  "port": 6006
54
+ // further options are available and can be found in
55
+ // https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/start-storybook/schema.json
51
56
  }
52
57
  },
53
58
  "build-storybook": {
@@ -55,8 +60,9 @@ Storybook supports Angular multi-project workspace. You can setup Storybook for
55
60
  "options": {
56
61
  "configDir": ".storybook",
57
62
  "browserTarget": "your-project:build",
58
- "compodoc": false,
59
63
  "outputDir": "dist/storybook/your-project"
64
+ // further options are available and can be found in
65
+ // https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/build-storybook/schema.json
60
66
  }
61
67
  }
62
68
  }
@@ -70,19 +76,161 @@ Storybook supports Angular multi-project workspace. You can setup Storybook for
70
76
  To run Storybook for a particular project, please run:
71
77
 
72
78
  ```sh
73
- ng run your-project:storybook
79
+ ng run <your-project>:storybook
74
80
  ```
75
81
 
76
82
  To build Storybook, run:
77
83
 
78
84
  ```sh
79
- ng run your-project:build-storybook
85
+ ng run <your-project>:build-storybook
80
86
  ```
81
87
 
82
88
  You will find the output in `dist/storybook/your-project`.
83
89
 
84
90
  For more information visit: [storybook.js.org](https://storybook.js.org)
85
91
 
92
+ ## Setup Compodoc
93
+
94
+ You can include JSDoc comments above components, directives, and other parts of your Angular code to include documentation for those elements. Compodoc uses these comments to generate documentation for your application. In Storybook, it is useful to add explanatory comments above @Inputs and @Outputs, since these are the main elements that Storybook displays in its user interface. The @Inputs and @Outputs are the elements that you can interact with in Storybook, such as controls.
95
+
96
+ ### Automatic setup
97
+
98
+ When installing Storybook via `sb init`, you will be given the option to set up Compodoc automatically.
99
+
100
+ ### Manual setup
101
+
102
+ If you have already installed Storybook, you can set up Compodoc manually.
103
+
104
+ Install the following dependencies:
105
+
106
+ ```sh
107
+ npm i -D @compodoc/compodoc
108
+ ```
109
+
110
+ Add the following option to your to the Storybook Builder:
111
+
112
+ ```json
113
+ {
114
+ ...
115
+ "projects": {
116
+ ...
117
+ "your-project": {
118
+ ...
119
+ "architect": {
120
+ ...
121
+ "storybook": {
122
+ "builder": "@storybook/angular:start-storybook",
123
+ "options": {
124
+ ...
125
+ "compodoc": true,
126
+ "compodocArgs": [
127
+ "-e",
128
+ "json",
129
+ "-d",
130
+ // Where to store the generated documentation. It's usually the root of your Angular project. It's not necessarily the root of your Angular Workspace!
131
+ "."
132
+ ],
133
+ }
134
+ },
135
+ "build-storybook": {
136
+ "builder": "@storybook/angular:build-storybook",
137
+ "options": {
138
+ ...
139
+ "compodoc": true,
140
+ "compodocArgs": [
141
+ "-e",
142
+ "json",
143
+ "-d",
144
+ "."
145
+ ],
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+ Go to your `.storybook/preview.js` and add the following:
155
+
156
+ ```js
157
+ import { setCompodocJson } from '@storybook/addon-docs/angular';
158
+ import docJson from '../documentation.json';
159
+ setCompodocJson(docJson);
160
+
161
+ const preview: Preview = {
162
+ ...
163
+ };
164
+
165
+ export default preview;
166
+ ```
167
+
168
+ ## FAQ
169
+
170
+ ### How do I migrate to a Angular Storybook builder?
171
+
172
+ The Storybook [Angular builder](https://angular.io/guide/glossary#builder) is a new way to run Storybook in an Angular workspace. It is a drop-in replacement for running `storybook dev` and `storybook build` directly.
173
+
174
+ #### Do you have only one Angular project in your workspace?
175
+
176
+ In this case go to your `angular.json` and add `storybook` and `build-storybook` entries in `architect` section of your project like shown above.
177
+
178
+ ##### Adjust your `package.json`
179
+
180
+ Go to your `package.json` and adjust your script section. Usually, it will look like this:
181
+
182
+ ```json
183
+ {
184
+ "scripts": {
185
+ "storybook": "start-storybook -p 6006", // or `storybook dev -p 6006`
186
+ "build-storybook": "build-storybook" // or `storybook build`
187
+ }
188
+ }
189
+ ```
190
+
191
+ Now, you can run Storybook with `ng run <your-project>:storybook` and build it with `ng run <your-project>:build-storybook`. Adjust the scripts in your `package.json` accordingly.
192
+
193
+ ```json
194
+ {
195
+ "scripts": {
196
+ "storybook": "ng run <project-name>:storybook", // or `storybook dev -p 6006`
197
+ "build-storybook": "ng run <project-name>:build-storybook" // or `storybook build`
198
+ }
199
+ }
200
+ ```
201
+
202
+ Also remove the compodoc part in your script section if you have set it up previously.
203
+ It is now built-in in `@storybook/angular` and you don't have to call it explicitly:
204
+
205
+ ```json
206
+ {
207
+ "scripts": {
208
+ "docs:json": "compodoc -p tsconfig.json -e json -d ./documentation",
209
+ "storybook": "npm run docs:json && start-storybook -p 6006",
210
+ "build-storybook": "npm run docs:json && build-storybook"
211
+ }
212
+ }
213
+ ```
214
+
215
+ Change it to:
216
+
217
+ ```json
218
+ {
219
+ "scripts": {
220
+ "storybook": "ng run <project-name>:storybook",
221
+ "build-storybook": "ng run <project-name>:build-storybook"
222
+ }
223
+ }
224
+ ```
225
+
226
+ #### I have multiple projects in my Angular workspace
227
+
228
+ In this case you have to adjust your `angular.json` and `package.json` as described above for each project in which you want to use Storybook. Please note, that each project should have a dedicated `.storybook` folder, which should be placed in the root of the project.
229
+
230
+ You can run `npx sb init` sequentially for each project to setup Storybook for each of them to automatically create the `.storybook` folder and create the necessary configuration in your `angular.json`.
231
+
232
+ You can then use [Storybook composition](https://storybook.js.org/docs/angular/sharing/storybook-composition) to composite multiple Storybooks into one.
233
+
86
234
  ---
87
235
 
88
236
  Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish.
@@ -7,7 +7,7 @@ const find_up_1 = require("find-up");
7
7
  const read_pkg_up_1 = require("read-pkg-up");
8
8
  const core_server_1 = require("@storybook/core-server");
9
9
  const run_compodoc_1 = require("../utils/run-compodoc");
10
- const build_standalone_errors_handler_1 = require("../utils/build-standalone-errors-handler");
10
+ const error_handler_1 = require("../utils/error-handler");
11
11
  exports.default = (0, architect_1.createBuilder)(commandBuilder);
12
12
  function commandBuilder(options, context) {
13
13
  return (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
@@ -56,5 +56,6 @@ function runInstance(options) {
56
56
  return (0, rxjs_1.from)((0, core_server_1.withTelemetry)('build', {
57
57
  cliOptions: options,
58
58
  presetOptions: { ...options, corePresets: [], overridePresets: [] },
59
- }, () => (0, core_server_1.buildStaticStandalone)(options))).pipe((0, operators_1.catchError)((error) => (0, rxjs_1.throwError)((0, build_standalone_errors_handler_1.buildStandaloneErrorHandler)(error))));
59
+ printError: error_handler_1.printErrorDetails,
60
+ }, () => (0, core_server_1.buildStaticStandalone)(options))).pipe((0, operators_1.catchError)((error) => (0, rxjs_1.throwError)((0, error_handler_1.errorSummary)(error))));
60
61
  }
@@ -7,7 +7,7 @@ const find_up_1 = require("find-up");
7
7
  const read_pkg_up_1 = require("read-pkg-up");
8
8
  const core_server_1 = require("@storybook/core-server");
9
9
  const run_compodoc_1 = require("../utils/run-compodoc");
10
- const build_standalone_errors_handler_1 = require("../utils/build-standalone-errors-handler");
10
+ const error_handler_1 = require("../utils/error-handler");
11
11
  exports.default = (0, architect_1.createBuilder)(commandBuilder);
12
12
  function commandBuilder(options, context) {
13
13
  return (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
@@ -63,6 +63,11 @@ function runInstance(options) {
63
63
  (0, core_server_1.withTelemetry)('dev', {
64
64
  cliOptions: options,
65
65
  presetOptions: { ...options, corePresets: [], overridePresets: [] },
66
- }, () => (0, core_server_1.buildDevStandalone)(options).then(({ port }) => observer.next(port), (error) => observer.error((0, build_standalone_errors_handler_1.buildStandaloneErrorHandler)(error))));
66
+ printError: error_handler_1.printErrorDetails,
67
+ }, () => (0, core_server_1.buildDevStandalone)(options))
68
+ .then(({ port }) => observer.next(port))
69
+ .catch((error) => {
70
+ observer.error((0, error_handler_1.errorSummary)(error));
71
+ });
67
72
  });
68
73
  }
@@ -0,0 +1,2 @@
1
+ export declare const printErrorDetails: (error: any) => void;
2
+ export declare const errorSummary: (error: any) => string;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildStandaloneErrorHandler = void 0;
3
+ exports.errorSummary = exports.printErrorDetails = void 0;
4
4
  const node_logger_1 = require("@storybook/node-logger");
5
5
  const ts_dedent_1 = require("ts-dedent");
6
- const buildStandaloneErrorHandler = (error) => {
6
+ const printErrorDetails = (error) => {
7
7
  // Duplicate code for Standalone error handling
8
8
  // Source: https://github.com/storybookjs/storybook/blob/39c7ba09ad84fbd466f9c25d5b92791a5450b9f6/lib/core-server/src/build-dev.ts#L136
9
9
  node_logger_1.instance.heading = '';
@@ -22,6 +22,9 @@ const buildStandaloneErrorHandler = (error) => {
22
22
  error.compilation.errors.forEach((e) => node_logger_1.logger.plain(e));
23
23
  }
24
24
  node_logger_1.logger.line();
25
+ };
26
+ exports.printErrorDetails = printErrorDetails;
27
+ const errorSummary = (error) => {
25
28
  return error.close
26
29
  ? (0, ts_dedent_1.dedent) `
27
30
  FATAL broken build!, will close the process,
@@ -32,4 +35,4 @@ const buildStandaloneErrorHandler = (error) => {
32
35
  You may need to refresh the browser.
33
36
  `;
34
37
  };
35
- exports.buildStandaloneErrorHandler = buildStandaloneErrorHandler;
38
+ exports.errorSummary = errorSummary;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular",
3
- "version": "7.0.0-beta.61",
3
+ "version": "7.0.0-beta.62",
4
4
  "description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -36,20 +36,20 @@
36
36
  "prep": "../../../scripts/prepare/tsc.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@storybook/builder-webpack5": "7.0.0-beta.61",
40
- "@storybook/cli": "7.0.0-beta.61",
41
- "@storybook/client-logger": "7.0.0-beta.61",
42
- "@storybook/core-client": "7.0.0-beta.61",
43
- "@storybook/core-common": "7.0.0-beta.61",
44
- "@storybook/core-events": "7.0.0-beta.61",
45
- "@storybook/core-server": "7.0.0-beta.61",
46
- "@storybook/core-webpack": "7.0.0-beta.61",
47
- "@storybook/docs-tools": "7.0.0-beta.61",
39
+ "@storybook/builder-webpack5": "7.0.0-beta.62",
40
+ "@storybook/cli": "7.0.0-beta.62",
41
+ "@storybook/client-logger": "7.0.0-beta.62",
42
+ "@storybook/core-client": "7.0.0-beta.62",
43
+ "@storybook/core-common": "7.0.0-beta.62",
44
+ "@storybook/core-events": "7.0.0-beta.62",
45
+ "@storybook/core-server": "7.0.0-beta.62",
46
+ "@storybook/core-webpack": "7.0.0-beta.62",
47
+ "@storybook/docs-tools": "7.0.0-beta.62",
48
48
  "@storybook/global": "^5.0.0",
49
- "@storybook/manager-api": "7.0.0-beta.61",
50
- "@storybook/node-logger": "7.0.0-beta.61",
51
- "@storybook/preview-api": "7.0.0-beta.61",
52
- "@storybook/types": "7.0.0-beta.61",
49
+ "@storybook/manager-api": "7.0.0-beta.62",
50
+ "@storybook/node-logger": "7.0.0-beta.62",
51
+ "@storybook/preview-api": "7.0.0-beta.62",
52
+ "@storybook/types": "7.0.0-beta.62",
53
53
  "@types/node": "^16.0.0",
54
54
  "@types/react": "^16.14.34",
55
55
  "@types/react-dom": "^16.9.14",
@@ -123,5 +123,5 @@
123
123
  "bundler": {
124
124
  "tsConfig": "tsconfig.build.json"
125
125
  },
126
- "gitHead": "c4707c66fa1b173da15d232f35e03dd647aa6a42"
126
+ "gitHead": "f70dcdb599363bfd6e6d2b63f8fadd02e9cbe00a"
127
127
  }
@@ -1 +0,0 @@
1
- export declare const buildStandaloneErrorHandler: (error: any) => any;