@storybook/angular 7.0.0-beta.8 → 7.0.0-rc.0
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 +214 -0
- package/dist/builders/build-storybook/index.d.ts +5 -3
- package/dist/builders/build-storybook/index.js +9 -4
- package/dist/builders/build-storybook/schema.json +14 -6
- package/dist/builders/start-storybook/index.d.ts +5 -3
- package/dist/builders/start-storybook/index.js +15 -6
- package/dist/builders/start-storybook/schema.json +10 -5
- package/dist/builders/utils/error-handler.d.ts +2 -0
- package/dist/builders/utils/{build-standalone-errors-handler.js → error-handler.js} +6 -3
- package/dist/builders/utils/run-compodoc.js +11 -27
- package/dist/builders/utils/run-compodoc.spec.js +42 -0
- package/dist/builders/utils/standalone-options.d.ts +2 -2
- package/dist/client/angular-beta/AbstractRenderer.d.ts +3 -3
- package/dist/client/angular-beta/AbstractRenderer.js +31 -31
- package/dist/client/angular-beta/CanvasRenderer.js +1 -1
- package/dist/client/angular-beta/DocsRenderer.js +5 -3
- package/dist/client/angular-beta/RendererFactory.js +5 -4
- package/dist/client/angular-beta/StorybookModule.d.ts +3 -6
- package/dist/client/angular-beta/StorybookModule.js +4 -45
- package/dist/client/angular-beta/StorybookModule.test.js +51 -36
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +3 -2
- package/dist/client/angular-beta/StorybookWrapperComponent.js +30 -2
- package/dist/client/angular-beta/__testfixtures__/test.module.d.ts +2 -0
- package/dist/client/angular-beta/__testfixtures__/test.module.js +20 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +1 -1
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +43 -5
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.d.ts +1 -1
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.js +4 -4
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +3 -3
- package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +32 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.js +136 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +141 -0
- package/dist/client/config.d.ts +1 -1
- package/dist/client/config.js +1 -1
- package/dist/client/decorateStory.js +1 -1
- package/dist/client/docs/compodoc.js +5 -7
- package/dist/client/docs/config.js +1 -2
- package/dist/client/docs/sourceDecorator.js +2 -1
- package/dist/client/globals.d.ts +0 -8
- package/dist/client/globals.js +2 -29
- package/dist/client/public-api.js +3 -3
- package/dist/client/public-types.d.ts +2 -1
- package/dist/client/render.d.ts +1 -0
- package/dist/client/render.js +1 -5
- package/dist/client/types.d.ts +1 -2
- package/dist/index.mjs +13 -0
- package/dist/preset.js +3 -5
- package/dist/preset.mjs +27 -0
- package/dist/renderer.d.ts +2 -1
- package/dist/renderer.js +4 -2
- package/dist/renderer.mjs +5 -0
- package/dist/server/framework-preset-angular-cli.d.ts +2 -1
- package/dist/server/framework-preset-angular-cli.js +21 -92
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +15 -13
- package/dist/server/preset-options.d.ts +3 -2
- package/dist/types.mjs +1 -0
- package/jest.config.js +19 -0
- package/package.json +46 -45
- package/template/cli/Button.stories.ts +1 -1
- package/template/cli/Header.stories.ts +2 -2
- package/template/cli/button.component.ts +2 -0
- package/template/components/index.js +2 -2
- package/template/stories/angular-mdx.stories.mdx +1 -1
- package/template/stories/argTypes/doc-button/doc-button.component.ts +1 -2
- package/template/stories/basics/component-without-selector/without-selector-ng-component-outlet.stories.ts +1 -1
- package/template/stories/basics/component-without-selector/without-selector-ng-factory-resolver.stories.ts +1 -1
- package/template/stories/basics/component-without-selector/without-selector.stories.ts +1 -1
- package/template/stories/basics/ng-module/import-module-chip.stories.ts +23 -0
- package/template/stories/basics/ng-module/import-module.stories.ts +2 -13
- package/template/stories/core/decorators/componentWrapperDecorator/decorators.stories.ts +0 -18
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.css +13 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.html +7 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.ts +39 -0
- package/template/stories/core/moduleMetadata/with-browser-animations.stories.ts +30 -0
- package/template/stories/core/moduleMetadata/with-noop-browser-animations.stories.ts +27 -0
- package/template/stories/core/parameters/bootstrap-options.stories.ts +1 -5
- package/template/stories/others/app-initializer-use-factory/app-initializer-use-factory.stories.ts +34 -0
- package/dist/builders/utils/build-standalone-errors-handler.d.ts +0 -1
- package/dist/client/angular/helpers.d.ts +0 -8
- package/dist/client/angular/helpers.js +0 -150
- package/dist/server/angular-read-workspace.d.ts +0 -13
- package/dist/server/angular-read-workspace.js +0 -78
- package/dist/server/utils/normalize-asset-patterns.d.ts +0 -7
- package/dist/server/utils/normalize-asset-patterns.js +0 -64
- package/dist/server/utils/normalize-optimization.d.ts +0 -3
- package/dist/server/utils/normalize-optimization.js +0 -21
package/README.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Storybook for Angular
|
|
2
2
|
|
|
3
|
+
- [Storybook for Angular](#storybook-for-angular)
|
|
4
|
+
- [Getting Started](#getting-started)
|
|
5
|
+
- [Setup Storybook for your Angular projects](#setup-storybook-for-your-angular-projects)
|
|
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)
|
|
15
|
+
|
|
3
16
|
Storybook for Angular is a UI development environment for your Angular components.
|
|
4
17
|
With it, you can visualize different states of your UI components and develop them interactively.
|
|
5
18
|
|
|
@@ -15,8 +28,209 @@ cd my-angular-app
|
|
|
15
28
|
npx storybook init
|
|
16
29
|
```
|
|
17
30
|
|
|
31
|
+
## Setup Storybook for your Angular projects
|
|
32
|
+
|
|
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:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
// angular.json
|
|
37
|
+
{
|
|
38
|
+
...
|
|
39
|
+
"projects": {
|
|
40
|
+
...
|
|
41
|
+
"your-project": {
|
|
42
|
+
...
|
|
43
|
+
"architect": {
|
|
44
|
+
...
|
|
45
|
+
"storybook": {
|
|
46
|
+
"builder": "@storybook/angular:start-storybook",
|
|
47
|
+
"options": {
|
|
48
|
+
// the path to the storybook config directory
|
|
49
|
+
"configDir": ".storybook",
|
|
50
|
+
// the build target of your project
|
|
51
|
+
"browserTarget": "your-project:build",
|
|
52
|
+
// the port you want to start Storybook on
|
|
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
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"build-storybook": {
|
|
59
|
+
"builder": "@storybook/angular:build-storybook",
|
|
60
|
+
"options": {
|
|
61
|
+
"configDir": ".storybook",
|
|
62
|
+
"browserTarget": "your-project:build",
|
|
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
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Run Storybook
|
|
75
|
+
|
|
76
|
+
To run Storybook for a particular project, please run:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
ng run <your-project>:storybook
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
To build Storybook, run:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
ng run <your-project>:build-storybook
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You will find the output in `dist/storybook/your-project`.
|
|
89
|
+
|
|
18
90
|
For more information visit: [storybook.js.org](https://storybook.js.org)
|
|
19
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
|
+
|
|
20
234
|
---
|
|
21
235
|
|
|
22
236
|
Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish.
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { BuilderOutput } from '@angular-devkit/architect';
|
|
2
2
|
import { JsonObject } from '@angular-devkit/core';
|
|
3
3
|
import { CLIOptions } from '@storybook/types';
|
|
4
|
-
import {
|
|
4
|
+
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
|
|
5
|
+
import { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
5
6
|
export type StorybookBuilderOptions = JsonObject & {
|
|
6
7
|
browserTarget?: string | null;
|
|
7
8
|
tsConfig?: string;
|
|
9
|
+
docs: boolean;
|
|
8
10
|
compodoc: boolean;
|
|
9
11
|
compodocArgs: string[];
|
|
10
|
-
styles?:
|
|
12
|
+
styles?: StyleElement[];
|
|
11
13
|
stylePreprocessorOptions?: StylePreprocessorOptions;
|
|
12
|
-
} & Pick<CLIOptions, 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | '
|
|
14
|
+
} & Pick<CLIOptions, 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | 'webpackStatsJson' | 'disableTelemetry'>;
|
|
13
15
|
export type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
|
|
14
16
|
declare const _default: import("@angular-devkit/architect/src/internal").Builder<any>;
|
|
15
17
|
export default _default;
|
|
@@ -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
|
|
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 }) => {
|
|
@@ -16,14 +16,15 @@ function commandBuilder(options, context) {
|
|
|
16
16
|
: (0, rxjs_1.of)({});
|
|
17
17
|
return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
|
|
18
18
|
}), (0, operators_1.map)(({ tsConfig }) => {
|
|
19
|
-
const { browserTarget, stylePreprocessorOptions, styles, configDir, docs, loglevel, outputDir, quiet, webpackStatsJson, } = options;
|
|
19
|
+
const { browserTarget, stylePreprocessorOptions, styles, configDir, docs, loglevel, outputDir, quiet, webpackStatsJson, disableTelemetry, } = options;
|
|
20
20
|
const standaloneOptions = {
|
|
21
21
|
packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
|
|
22
22
|
configDir,
|
|
23
|
-
docs,
|
|
23
|
+
...(docs ? { docs } : {}),
|
|
24
24
|
loglevel,
|
|
25
25
|
outputDir,
|
|
26
26
|
quiet,
|
|
27
|
+
disableTelemetry,
|
|
27
28
|
angularBrowserTarget: browserTarget,
|
|
28
29
|
angularBuilderContext: context,
|
|
29
30
|
angularBuilderOptions: {
|
|
@@ -52,5 +53,9 @@ async function setup(options, context) {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
function runInstance(options) {
|
|
55
|
-
return (0, rxjs_1.from)((0, core_server_1.
|
|
56
|
+
return (0, rxjs_1.from)((0, core_server_1.withTelemetry)('build', {
|
|
57
|
+
cliOptions: options,
|
|
58
|
+
presetOptions: { ...options, corePresets: [], overridePresets: [] },
|
|
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))));
|
|
56
61
|
}
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"description": "Suppress verbose build output.",
|
|
35
35
|
"default": false
|
|
36
36
|
},
|
|
37
|
-
"
|
|
37
|
+
"docs": {
|
|
38
38
|
"type": "boolean",
|
|
39
39
|
"description": "Starts Storybook in documentation mode. Learn more about it : https://storybook.js.org/docs/react/writing-docs/build-documentation#preview-storybooks-documentation.",
|
|
40
40
|
"default": false
|
|
@@ -47,13 +47,19 @@
|
|
|
47
47
|
"compodocArgs": {
|
|
48
48
|
"type": "array",
|
|
49
49
|
"description": "Compodoc options : https://compodoc.app/guides/options.html. Options `-p` with tsconfig path and `-d` with workspace root is always given.",
|
|
50
|
-
"default": [
|
|
50
|
+
"default": [
|
|
51
|
+
"-e",
|
|
52
|
+
"json"
|
|
53
|
+
],
|
|
51
54
|
"items": {
|
|
52
55
|
"type": "string"
|
|
53
56
|
}
|
|
54
57
|
},
|
|
55
58
|
"webpackStatsJson": {
|
|
56
|
-
"type":
|
|
59
|
+
"type": [
|
|
60
|
+
"boolean",
|
|
61
|
+
"string"
|
|
62
|
+
],
|
|
57
63
|
"description": "Write Webpack Stats JSON to disk",
|
|
58
64
|
"default": false
|
|
59
65
|
},
|
|
@@ -61,7 +67,7 @@
|
|
|
61
67
|
"type": "array",
|
|
62
68
|
"description": "Global styles to be included in the build.",
|
|
63
69
|
"items": {
|
|
64
|
-
"$ref": "#/definitions/
|
|
70
|
+
"$ref": "#/definitions/styleElement"
|
|
65
71
|
},
|
|
66
72
|
"default": ""
|
|
67
73
|
},
|
|
@@ -83,7 +89,7 @@
|
|
|
83
89
|
},
|
|
84
90
|
"additionalProperties": false,
|
|
85
91
|
"definitions": {
|
|
86
|
-
"
|
|
92
|
+
"styleElement": {
|
|
87
93
|
"oneOf": [
|
|
88
94
|
{
|
|
89
95
|
"type": "object",
|
|
@@ -104,7 +110,9 @@
|
|
|
104
110
|
}
|
|
105
111
|
},
|
|
106
112
|
"additionalProperties": false,
|
|
107
|
-
"required": [
|
|
113
|
+
"required": [
|
|
114
|
+
"input"
|
|
115
|
+
]
|
|
108
116
|
},
|
|
109
117
|
{
|
|
110
118
|
"type": "string",
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { BuilderOutput } from '@angular-devkit/architect';
|
|
2
2
|
import { JsonObject } from '@angular-devkit/core';
|
|
3
|
-
import {
|
|
3
|
+
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
|
|
4
4
|
import { CLIOptions } from '@storybook/types';
|
|
5
|
+
import { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
5
6
|
export type StorybookBuilderOptions = JsonObject & {
|
|
6
7
|
browserTarget?: string | null;
|
|
7
8
|
tsConfig?: string;
|
|
9
|
+
docs: boolean;
|
|
8
10
|
compodoc: boolean;
|
|
9
11
|
compodocArgs: string[];
|
|
10
|
-
styles?:
|
|
12
|
+
styles?: StyleElement[];
|
|
11
13
|
stylePreprocessorOptions?: StylePreprocessorOptions;
|
|
12
|
-
} & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | '
|
|
14
|
+
} & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'disableTelemetry'>;
|
|
13
15
|
export type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
|
|
14
16
|
declare const _default: import("@angular-devkit/architect/src/internal").Builder<any>;
|
|
15
17
|
export default _default;
|
|
@@ -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
|
|
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 }) => {
|
|
@@ -16,12 +16,12 @@ function commandBuilder(options, context) {
|
|
|
16
16
|
: (0, rxjs_1.of)({});
|
|
17
17
|
return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
|
|
18
18
|
}), (0, operators_1.map)(({ tsConfig }) => {
|
|
19
|
-
const { browserTarget, stylePreprocessorOptions, styles, ci, configDir, docs, host, https, port, quiet, smokeTest, sslCa, sslCert, sslKey, } = options;
|
|
19
|
+
const { browserTarget, stylePreprocessorOptions, styles, ci, configDir, docs, host, https, port, quiet, smokeTest, sslCa, sslCert, sslKey, disableTelemetry, } = options;
|
|
20
20
|
const standaloneOptions = {
|
|
21
21
|
packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
|
|
22
22
|
ci,
|
|
23
23
|
configDir,
|
|
24
|
-
docs,
|
|
24
|
+
...(docs ? { docs } : {}),
|
|
25
25
|
host,
|
|
26
26
|
https,
|
|
27
27
|
port,
|
|
@@ -30,6 +30,7 @@ function commandBuilder(options, context) {
|
|
|
30
30
|
sslCa,
|
|
31
31
|
sslCert,
|
|
32
32
|
sslKey,
|
|
33
|
+
disableTelemetry,
|
|
33
34
|
angularBrowserTarget: browserTarget,
|
|
34
35
|
angularBuilderContext: context,
|
|
35
36
|
angularBuilderOptions: {
|
|
@@ -39,8 +40,8 @@ function commandBuilder(options, context) {
|
|
|
39
40
|
tsConfig,
|
|
40
41
|
};
|
|
41
42
|
return standaloneOptions;
|
|
42
|
-
}), (0, operators_1.switchMap)((standaloneOptions) => runInstance(standaloneOptions)), (0, operators_1.map)(() => {
|
|
43
|
-
return { success: true };
|
|
43
|
+
}), (0, operators_1.switchMap)((standaloneOptions) => runInstance(standaloneOptions)), (0, operators_1.map)((port) => {
|
|
44
|
+
return { success: true, info: { port } };
|
|
44
45
|
}));
|
|
45
46
|
}
|
|
46
47
|
async function setup(options, context) {
|
|
@@ -59,6 +60,14 @@ async function setup(options, context) {
|
|
|
59
60
|
function runInstance(options) {
|
|
60
61
|
return new rxjs_1.Observable((observer) => {
|
|
61
62
|
// This Observable intentionally never complete, leaving the process running ;)
|
|
62
|
-
(0, core_server_1.
|
|
63
|
+
(0, core_server_1.withTelemetry)('dev', {
|
|
64
|
+
cliOptions: options,
|
|
65
|
+
presetOptions: { ...options, corePresets: [], overridePresets: [] },
|
|
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
|
+
});
|
|
63
72
|
});
|
|
64
73
|
}
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"description": "Suppress verbose build output.",
|
|
62
62
|
"default": false
|
|
63
63
|
},
|
|
64
|
-
"
|
|
64
|
+
"docs": {
|
|
65
65
|
"type": "boolean",
|
|
66
66
|
"description": "Starts Storybook in documentation mode. Learn more about it : https://storybook.js.org/docs/react/writing-docs/build-documentation#preview-storybooks-documentation.",
|
|
67
67
|
"default": false
|
|
@@ -74,7 +74,10 @@
|
|
|
74
74
|
"compodocArgs": {
|
|
75
75
|
"type": "array",
|
|
76
76
|
"description": "Compodoc options : https://compodoc.app/guides/options.html. Options `-p` with tsconfig path and `-d` with workspace root is always given.",
|
|
77
|
-
"default": [
|
|
77
|
+
"default": [
|
|
78
|
+
"-e",
|
|
79
|
+
"json"
|
|
80
|
+
],
|
|
78
81
|
"items": {
|
|
79
82
|
"type": "string"
|
|
80
83
|
}
|
|
@@ -83,7 +86,7 @@
|
|
|
83
86
|
"type": "array",
|
|
84
87
|
"description": "Global styles to be included in the build.",
|
|
85
88
|
"items": {
|
|
86
|
-
"$ref": "#/definitions/
|
|
89
|
+
"$ref": "#/definitions/styleElement"
|
|
87
90
|
},
|
|
88
91
|
"default": ""
|
|
89
92
|
},
|
|
@@ -105,7 +108,7 @@
|
|
|
105
108
|
},
|
|
106
109
|
"additionalProperties": false,
|
|
107
110
|
"definitions": {
|
|
108
|
-
"
|
|
111
|
+
"styleElement": {
|
|
109
112
|
"oneOf": [
|
|
110
113
|
{
|
|
111
114
|
"type": "object",
|
|
@@ -126,7 +129,9 @@
|
|
|
126
129
|
}
|
|
127
130
|
},
|
|
128
131
|
"additionalProperties": false,
|
|
129
|
-
"required": [
|
|
132
|
+
"required": [
|
|
133
|
+
"input"
|
|
134
|
+
]
|
|
130
135
|
},
|
|
131
136
|
{
|
|
132
137
|
"type": "string",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
|
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.
|
|
38
|
+
exports.errorSummary = errorSummary;
|
|
@@ -24,10 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.runCompodoc = void 0;
|
|
27
|
-
const child_process_1 = require("child_process");
|
|
28
27
|
const rxjs_1 = require("rxjs");
|
|
29
28
|
const path = __importStar(require("path"));
|
|
29
|
+
const cli_1 = require("@storybook/cli");
|
|
30
30
|
const hasTsConfigArg = (args) => args.indexOf('-p') !== -1;
|
|
31
|
+
const hasOutputArg = (args) => args.indexOf('-d') !== -1 || args.indexOf('--output') !== -1;
|
|
31
32
|
// path.relative is necessary to workaround a compodoc issue with
|
|
32
33
|
// absolute paths on windows machines
|
|
33
34
|
const toRelativePath = (pathToTsConfig) => {
|
|
@@ -37,37 +38,20 @@ const runCompodoc = ({ compodocArgs, tsconfig }, context) => {
|
|
|
37
38
|
return new rxjs_1.Observable((observer) => {
|
|
38
39
|
const tsConfigPath = toRelativePath(tsconfig);
|
|
39
40
|
const finalCompodocArgs = [
|
|
40
|
-
'compodoc',
|
|
41
|
-
// Default options
|
|
42
41
|
...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]),
|
|
43
|
-
'-d',
|
|
44
|
-
`${context.workspaceRoot}`,
|
|
42
|
+
...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot || '.'}`]),
|
|
45
43
|
...compodocArgs,
|
|
46
44
|
];
|
|
45
|
+
const packageManager = cli_1.JsPackageManagerFactory.getPackageManager();
|
|
47
46
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
child.stdout.on('data', (data) => {
|
|
54
|
-
context.logger.info(data.toString());
|
|
55
|
-
});
|
|
56
|
-
child.stderr.on('data', (data) => {
|
|
57
|
-
context.logger.error(data.toString());
|
|
58
|
-
});
|
|
59
|
-
child.on('close', (code) => {
|
|
60
|
-
if (code === 0) {
|
|
61
|
-
observer.next();
|
|
62
|
-
observer.complete();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
observer.error();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
47
|
+
const stdout = packageManager.runPackageCommand('compodoc', finalCompodocArgs, context.workspaceRoot);
|
|
48
|
+
context.logger.info(stdout);
|
|
49
|
+
observer.next();
|
|
50
|
+
observer.complete();
|
|
68
51
|
}
|
|
69
|
-
catch (
|
|
70
|
-
|
|
52
|
+
catch (e) {
|
|
53
|
+
context.logger.error(e);
|
|
54
|
+
observer.error();
|
|
71
55
|
}
|
|
72
56
|
});
|
|
73
57
|
};
|
|
@@ -56,4 +56,46 @@ describe('runCompodoc', () => {
|
|
|
56
56
|
shell: true,
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
|
+
it('should run compodoc with default output folder.', async () => {
|
|
60
|
+
runCompodoc({
|
|
61
|
+
compodocArgs: [],
|
|
62
|
+
tsconfig: 'path/to/tsconfig.json',
|
|
63
|
+
}, {
|
|
64
|
+
workspaceRoot: 'path/to/project',
|
|
65
|
+
logger: builderContextLoggerMock,
|
|
66
|
+
})
|
|
67
|
+
.pipe((0, operators_1.take)(1))
|
|
68
|
+
.subscribe();
|
|
69
|
+
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('npx', ['compodoc', '-p', 'path/to/tsconfig.json', '-d', 'path/to/project'], {
|
|
70
|
+
cwd: 'path/to/project',
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it('should run with custom output folder specified with --output compodocArgs', async () => {
|
|
74
|
+
runCompodoc({
|
|
75
|
+
compodocArgs: ['--output', 'path/to/customFolder'],
|
|
76
|
+
tsconfig: 'path/to/tsconfig.json',
|
|
77
|
+
}, {
|
|
78
|
+
workspaceRoot: 'path/to/project',
|
|
79
|
+
logger: builderContextLoggerMock,
|
|
80
|
+
})
|
|
81
|
+
.pipe((0, operators_1.take)(1))
|
|
82
|
+
.subscribe();
|
|
83
|
+
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('npx', ['compodoc', '-p', 'path/to/tsconfig.json', '--output', 'path/to/customFolder'], {
|
|
84
|
+
cwd: 'path/to/project',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should run with custom output folder specified with -d compodocArgs', async () => {
|
|
88
|
+
runCompodoc({
|
|
89
|
+
compodocArgs: ['-d', 'path/to/customFolder'],
|
|
90
|
+
tsconfig: 'path/to/tsconfig.json',
|
|
91
|
+
}, {
|
|
92
|
+
workspaceRoot: 'path/to/project',
|
|
93
|
+
logger: builderContextLoggerMock,
|
|
94
|
+
})
|
|
95
|
+
.pipe((0, operators_1.take)(1))
|
|
96
|
+
.subscribe();
|
|
97
|
+
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('npx', ['compodoc', '-p', 'path/to/tsconfig.json', '-d', 'path/to/customFolder'], {
|
|
98
|
+
cwd: 'path/to/project',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
59
101
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BuilderContext } from '@angular-devkit/architect';
|
|
2
2
|
import { LoadOptions, CLIOptions, BuilderOptions } from '@storybook/types';
|
|
3
|
-
export type StandaloneOptions =
|
|
3
|
+
export type StandaloneOptions = CLIOptions & LoadOptions & BuilderOptions & {
|
|
4
4
|
mode?: 'static' | 'dev';
|
|
5
5
|
angularBrowserTarget?: string | null;
|
|
6
6
|
angularBuilderOptions?: Record<string, any> & {
|
|
@@ -9,4 +9,4 @@ export type StandaloneOptions = Partial<CLIOptions & LoadOptions & BuilderOption
|
|
|
9
9
|
};
|
|
10
10
|
angularBuilderContext?: BuilderContext | null;
|
|
11
11
|
tsConfig?: string;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Subject } from 'rxjs';
|
|
2
|
-
import { ICollection,
|
|
2
|
+
import { ICollection, Parameters, StoryFnAngularReturnType } from '../types';
|
|
3
3
|
type StoryRenderInfo = {
|
|
4
4
|
storyFnAngular: StoryFnAngularReturnType;
|
|
5
5
|
moduleMetadataSnapshot: string;
|
|
@@ -9,7 +9,7 @@ export declare abstract class AbstractRenderer {
|
|
|
9
9
|
/**
|
|
10
10
|
* Wait and destroy the platform
|
|
11
11
|
*/
|
|
12
|
-
static
|
|
12
|
+
static resetApplications(): void;
|
|
13
13
|
/**
|
|
14
14
|
* Reset compiled components because we often want to compile the same component with
|
|
15
15
|
* more than one NgModule.
|
|
@@ -49,7 +49,7 @@ export declare abstract class AbstractRenderer {
|
|
|
49
49
|
* @protected
|
|
50
50
|
* @memberof AbstractRenderer
|
|
51
51
|
*/
|
|
52
|
-
protected generateTargetSelectorFromStoryId(): string;
|
|
52
|
+
protected generateTargetSelectorFromStoryId(id: string): string;
|
|
53
53
|
protected initAngularRootElement(targetDOMNode: HTMLElement, targetSelector: string): void;
|
|
54
54
|
private fullRendererRequired;
|
|
55
55
|
}
|