@storybook/angular 0.0.0-pr-33843-sha-99db7e4e → 0.0.0-pr-33859-sha-13cfcf7c
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/.eslintrc.js +8 -0
- package/README.md +322 -1
- package/dist/builders/build-storybook/index.js +11 -16
- package/dist/builders/build-storybook/index.spec.js +63 -69
- package/dist/builders/build-storybook/schema.json +1 -16
- package/dist/builders/start-storybook/index.js +13 -16
- package/dist/builders/start-storybook/index.spec.js +68 -41
- package/dist/builders/start-storybook/schema.json +1 -16
- package/dist/builders/utils/error-handler.js +1 -1
- package/dist/builders/utils/run-compodoc.js +28 -5
- package/dist/builders/utils/run-compodoc.spec.js +47 -37
- package/dist/builders/utils/standalone-options.d.ts +1 -3
- package/dist/client/angular-beta/AbstractRenderer.d.ts +17 -39
- package/dist/client/angular-beta/AbstractRenderer.js +69 -90
- package/dist/client/angular-beta/CanvasRenderer.d.ts +2 -1
- package/dist/client/angular-beta/CanvasRenderer.js +3 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.d.ts +1 -8
- package/dist/client/angular-beta/ComputesTemplateFromComponent.js +5 -33
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.js +70 -397
- package/dist/client/angular-beta/DocsRenderer.d.ts +2 -2
- package/dist/client/angular-beta/DocsRenderer.js +13 -12
- package/dist/client/angular-beta/RendererFactory.js +3 -3
- package/dist/client/angular-beta/RendererFactory.test.js +32 -103
- package/dist/client/angular-beta/StorybookModule.js +4 -2
- package/dist/client/angular-beta/StorybookModule.test.js +41 -51
- package/dist/client/angular-beta/StorybookProvider.d.ts +1 -1
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +5 -2
- package/dist/client/angular-beta/StorybookWrapperComponent.js +25 -12
- package/dist/client/angular-beta/__testfixtures__/input.component.d.ts +0 -3
- package/dist/client/angular-beta/__testfixtures__/input.component.js +0 -9
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.d.ts +11 -4
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +10 -3
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +66 -80
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +7 -8
- package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +7 -5
- package/dist/client/angular-beta/utils/PropertyExtractor.js +44 -80
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +74 -97
- package/dist/client/argsToTemplate.d.ts +12 -13
- package/dist/client/argsToTemplate.js +9 -13
- package/dist/client/argsToTemplate.test.js +20 -27
- package/dist/client/decorateStory.d.ts +1 -1
- package/dist/client/decorateStory.js +4 -3
- package/dist/client/decorateStory.test.js +27 -28
- package/dist/client/decorators.d.ts +7 -6
- package/dist/client/decorators.js +6 -5
- package/dist/client/decorators.test.js +15 -27
- package/dist/client/docs/__testfixtures__/doc-button/input.d.ts +8 -7
- package/dist/client/docs/__testfixtures__/doc-button/input.js +11 -9
- package/dist/client/docs/angular-properties.test.d.ts +1 -1
- package/dist/client/docs/angular-properties.test.js +41 -15
- package/dist/client/docs/compodoc.d.ts +4 -4
- package/dist/client/docs/compodoc.js +1 -1
- package/dist/client/docs/compodoc.test.js +7 -8
- package/dist/client/docs/config.d.ts +1 -1
- package/dist/client/docs/config.js +1 -1
- package/dist/client/docs/sourceDecorator.d.ts +3 -4
- package/dist/client/docs/sourceDecorator.js +6 -16
- package/dist/client/globals.d.ts +23 -1
- package/dist/client/globals.js +21 -14
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +4 -2
- package/dist/client/public-api.d.ts +15 -0
- package/dist/client/public-api.js +36 -0
- package/dist/client/public-types.d.ts +16 -35
- package/dist/client/render.d.ts +2 -2
- package/dist/client/render.js +2 -2
- package/dist/client/types.d.ts +11 -7
- package/dist/preset.d.ts +4 -3
- package/dist/preset.js +3 -2
- package/dist/preset.mjs +2 -1
- package/dist/server/angular-cli-webpack.js +13 -13
- package/dist/server/framework-preset-angular-cli.js +21 -27
- package/dist/server/framework-preset-angular-docs.d.ts +2 -2
- package/dist/server/framework-preset-angular-docs.js +1 -1
- package/dist/server/framework-preset-angular-ivy.d.ts +2 -2
- package/dist/server/framework-preset-angular-ivy.js +42 -15
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.d.ts +17 -4
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +24 -31
- package/dist/server/preset-options.d.ts +7 -3
- package/dist/types.d.ts +6 -5
- package/jest.config.js +31 -0
- package/package.json +50 -66
- package/template/cli/button.component.ts +19 -11
- package/template/cli/button.stories.ts +6 -3
- package/template/cli/header.component.ts +50 -47
- package/template/cli/header.stories.ts +0 -6
- package/template/cli/page.component.ts +54 -54
- package/template/cli/page.stories.ts +2 -2
- package/template/components/index.js +1 -1
- package/dist/client/angular-beta/utils/BootstrapQueue.d.ts +0 -12
- package/dist/client/angular-beta/utils/BootstrapQueue.js +0 -86
- package/dist/client/angular-beta/utils/BootstrapQueue.test.d.ts +0 -1
- package/dist/client/angular-beta/utils/BootstrapQueue.test.js +0 -164
- package/dist/client/angular-beta/utils/StoryUID.d.ts +0 -22
- package/dist/client/angular-beta/utils/StoryUID.js +0 -43
- package/dist/client/portable-stories.d.ts +0 -23
- package/dist/client/portable-stories.js +0 -62
- package/dist/node/index.d.ts +0 -2
- package/dist/node/index.js +0 -6
- package/dist/test-setup.d.ts +0 -1
- package/dist/test-setup.js +0 -6
- package/dist/test-setup.mjs +0 -4
- package/scripts/postbuild.js +0 -17
package/.eslintrc.js
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,324 @@
|
|
|
1
1
|
# Storybook for Angular
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
- [moduleMetadata decorator](#modulemetadata-decorator)
|
|
11
|
+
- [applicationConfig decorator](#applicationconfig-decorator)
|
|
12
|
+
- [FAQ](#faq)
|
|
13
|
+
- [How do I migrate to an Angular Storybook builder?](#how-do-i-migrate-to-an-angular-storybook-builder)
|
|
14
|
+
- [Do you have only one Angular project in your workspace?](#do-you-have-only-one-angular-project-in-your-workspace)
|
|
15
|
+
- [Adjust your `package.json`](#adjust-your-packagejson)
|
|
16
|
+
- [I have multiple projects in my Angular workspace](#i-have-multiple-projects-in-my-angular-workspace)
|
|
17
|
+
|
|
18
|
+
Storybook for Angular is a UI development environment for your Angular components.
|
|
19
|
+
With it, you can visualize different states of your UI components and develop them interactively.
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
Storybook runs outside of your app.
|
|
24
|
+
So you can develop UI components in isolation without worrying about app specific dependencies and requirements.
|
|
25
|
+
|
|
26
|
+
## Getting Started
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
cd my-angular-app
|
|
30
|
+
npx storybook@latest init
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Setup Storybook for your Angular projects
|
|
34
|
+
|
|
35
|
+
Storybook supports Angular multi-project workspace. You can setup Storybook for each project in the workspace. When running `npx storybook@latest 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:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
// angular.json
|
|
39
|
+
{
|
|
40
|
+
...
|
|
41
|
+
"projects": {
|
|
42
|
+
...
|
|
43
|
+
"your-project": {
|
|
44
|
+
...
|
|
45
|
+
"architect": {
|
|
46
|
+
...
|
|
47
|
+
"storybook": {
|
|
48
|
+
"builder": "@storybook/angular:start-storybook",
|
|
49
|
+
"options": {
|
|
50
|
+
// the path to the storybook config directory
|
|
51
|
+
"configDir": ".storybook",
|
|
52
|
+
// the build target of your project
|
|
53
|
+
"browserTarget": "your-project:build",
|
|
54
|
+
// the port you want to start Storybook on
|
|
55
|
+
"port": 6006
|
|
56
|
+
// further options are available and can be found in
|
|
57
|
+
// https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/start-storybook/schema.json
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"build-storybook": {
|
|
61
|
+
"builder": "@storybook/angular:build-storybook",
|
|
62
|
+
"options": {
|
|
63
|
+
"configDir": ".storybook",
|
|
64
|
+
"browserTarget": "your-project:build",
|
|
65
|
+
"outputDir": "dist/storybook/your-project"
|
|
66
|
+
// further options are available and can be found in
|
|
67
|
+
// https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/build-storybook/schema.json
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Run Storybook
|
|
77
|
+
|
|
78
|
+
To run Storybook for a particular project, please run:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
ng run <your-project>:storybook
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
To build Storybook, run:
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
ng run <your-project>:build-storybook
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You will find the output in `dist/storybook/your-project`.
|
|
91
|
+
|
|
92
|
+
For more information visit: [storybook.js.org](https://storybook.js.org)
|
|
93
|
+
|
|
94
|
+
## Setup Compodoc
|
|
95
|
+
|
|
96
|
+
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.
|
|
97
|
+
|
|
98
|
+
### Automatic setup
|
|
99
|
+
|
|
100
|
+
When installing Storybook via `sb init`, you will be given the option to set up Compodoc automatically.
|
|
101
|
+
|
|
102
|
+
### Manual setup
|
|
103
|
+
|
|
104
|
+
If you have already installed Storybook, you can set up Compodoc manually.
|
|
105
|
+
|
|
106
|
+
Install the following dependencies:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
npm i -D @compodoc/compodoc
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Add the following option to your to the Storybook Builder:
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
...
|
|
117
|
+
"projects": {
|
|
118
|
+
...
|
|
119
|
+
"your-project": {
|
|
120
|
+
...
|
|
121
|
+
"architect": {
|
|
122
|
+
...
|
|
123
|
+
"storybook": {
|
|
124
|
+
"builder": "@storybook/angular:start-storybook",
|
|
125
|
+
"options": {
|
|
126
|
+
...
|
|
127
|
+
"compodoc": true,
|
|
128
|
+
"compodocArgs": [
|
|
129
|
+
"-e",
|
|
130
|
+
"json",
|
|
131
|
+
"-d",
|
|
132
|
+
// 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!
|
|
133
|
+
"."
|
|
134
|
+
],
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"build-storybook": {
|
|
138
|
+
"builder": "@storybook/angular:build-storybook",
|
|
139
|
+
"options": {
|
|
140
|
+
...
|
|
141
|
+
"compodoc": true,
|
|
142
|
+
"compodocArgs": [
|
|
143
|
+
"-e",
|
|
144
|
+
"json",
|
|
145
|
+
"-d",
|
|
146
|
+
"."
|
|
147
|
+
],
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Go to your `.storybook/preview.js` and add the following:
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
import { setCompodocJson } from '@storybook/addon-docs/angular';
|
|
160
|
+
import docJson from '../documentation.json';
|
|
161
|
+
setCompodocJson(docJson);
|
|
162
|
+
|
|
163
|
+
const preview: Preview = {
|
|
164
|
+
...
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export default preview;
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## moduleMetadata decorator
|
|
171
|
+
|
|
172
|
+
If your component has dependencies on other Angular directives and modules, these can be supplied using the moduleMetadata decorator either for all stories or for individual stories.
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import { StoryFn, Meta, moduleMetadata } from '@storybook/angular';
|
|
176
|
+
import { SomeComponent } from './some.component';
|
|
177
|
+
|
|
178
|
+
export default {
|
|
179
|
+
component: SomeComponent,
|
|
180
|
+
decorators: [
|
|
181
|
+
// Apply metadata to all stories
|
|
182
|
+
moduleMetadata({
|
|
183
|
+
// import necessary ngModules or standalone components
|
|
184
|
+
imports: [...],
|
|
185
|
+
// declare components that are used in the template
|
|
186
|
+
declarations: [...],
|
|
187
|
+
// List of providers that should be available to the root component and all its children.
|
|
188
|
+
providers: [...],
|
|
189
|
+
}),
|
|
190
|
+
],
|
|
191
|
+
} as Meta;
|
|
192
|
+
|
|
193
|
+
const Template = (): StoryFn => (args) => ({
|
|
194
|
+
props: args,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
export const Base = Template();
|
|
198
|
+
|
|
199
|
+
export const WithCustomProvider = Template();
|
|
200
|
+
WithCustomProvider.decorators = [
|
|
201
|
+
// Apply metadata to a specific story
|
|
202
|
+
moduleMetadata({
|
|
203
|
+
imports: [...],
|
|
204
|
+
declarations: [...],
|
|
205
|
+
providers: [...]
|
|
206
|
+
}),
|
|
207
|
+
];
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## applicationConfig decorator
|
|
211
|
+
|
|
212
|
+
If your component relies on application-wide providers, like the ones defined by BrowserAnimationsModule or any other modules which use the forRoot pattern to provide a ModuleWithProviders, you can use the applicationConfig decorator on the meta default export to provide them to the [bootstrapApplication function](https://angular.io/guide/standalone-components#configuring-dependency-injection), which we use to bootstrap the component in Storybook.
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
|
|
216
|
+
import { StoryObj, Meta, applicationConfig } from '@storybook/angular';
|
|
217
|
+
import { BrowserAnimationsModule, provideAnimations } from '@angular/platform-browser/animations';
|
|
218
|
+
import { importProvidersFrom } from '@angular/core';
|
|
219
|
+
import { ChipsModule } from './angular-src/chips.module';
|
|
220
|
+
|
|
221
|
+
const meta: Meta = {
|
|
222
|
+
component: ChipsGroupComponent,
|
|
223
|
+
decorators: [
|
|
224
|
+
// Apply application config to all stories
|
|
225
|
+
applicationConfig({
|
|
226
|
+
// List of providers and environment providers that should be available to the root component and all its children.
|
|
227
|
+
providers: [
|
|
228
|
+
...
|
|
229
|
+
// Import application-wide providers from a module
|
|
230
|
+
importProvidersFrom(BrowserAnimationsModule)
|
|
231
|
+
// Or use provide-style functions if available instead, e.g.
|
|
232
|
+
provideAnimations()
|
|
233
|
+
],
|
|
234
|
+
}),
|
|
235
|
+
],
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export default meta;
|
|
239
|
+
|
|
240
|
+
type Story = StoryObj<typeof ChipsGroupComponent>;
|
|
241
|
+
|
|
242
|
+
export const WithCustomApplicationProvider: Story = {
|
|
243
|
+
render: () => ({
|
|
244
|
+
// Apply application config to a specific story
|
|
245
|
+
applicationConfig: {
|
|
246
|
+
// The providers will be merged with the ones defined in the applicationConfig decorators providers array of the global meta object
|
|
247
|
+
providers: [...]
|
|
248
|
+
}
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## FAQ
|
|
254
|
+
|
|
255
|
+
### How do I migrate to an Angular Storybook builder?
|
|
256
|
+
|
|
257
|
+
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.
|
|
258
|
+
|
|
259
|
+
You can run `npx storybook@next automigrate` to try let Storybook detect and automatically fix your configuration. Otherwise, you can follow the next steps to manually adjust your configuration.
|
|
260
|
+
|
|
261
|
+
#### Do you have only one Angular project in your workspace?
|
|
262
|
+
|
|
263
|
+
In this case go to your `angular.json` and add `storybook` and `build-storybook` entries in `architect` section of your project like shown above.
|
|
264
|
+
|
|
265
|
+
##### Adjust your `package.json`
|
|
266
|
+
|
|
267
|
+
Go to your `package.json` and adjust your script section. Usually, it will look like this:
|
|
268
|
+
|
|
269
|
+
```json
|
|
270
|
+
{
|
|
271
|
+
"scripts": {
|
|
272
|
+
"storybook": "start-storybook -p 6006", // or `storybook dev -p 6006`
|
|
273
|
+
"build-storybook": "build-storybook" // or `storybook build`
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
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.
|
|
279
|
+
|
|
280
|
+
```json
|
|
281
|
+
{
|
|
282
|
+
"scripts": {
|
|
283
|
+
"storybook": "ng run <project-name>:storybook", // or `storybook dev -p 6006`
|
|
284
|
+
"build-storybook": "ng run <project-name>:build-storybook" // or `storybook build`
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Also remove the compodoc part in your script section if you have set it up previously.
|
|
290
|
+
It is now built-in in `@storybook/angular` and you don't have to call it explicitly:
|
|
291
|
+
|
|
292
|
+
```json
|
|
293
|
+
{
|
|
294
|
+
"scripts": {
|
|
295
|
+
"docs:json": "compodoc -p tsconfig.json -e json -d ./documentation",
|
|
296
|
+
"storybook": "npm run docs:json && start-storybook -p 6006",
|
|
297
|
+
"build-storybook": "npm run docs:json && build-storybook"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Change it to:
|
|
303
|
+
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"scripts": {
|
|
307
|
+
"storybook": "ng run <project-name>:storybook",
|
|
308
|
+
"build-storybook": "ng run <project-name>:build-storybook"
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### I have multiple projects in my Angular workspace
|
|
314
|
+
|
|
315
|
+
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.
|
|
316
|
+
|
|
317
|
+
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`.
|
|
318
|
+
|
|
319
|
+
You can then use [Storybook composition](https://storybook.js.org/docs/angular/sharing/storybook-composition) to composite multiple Storybooks into one.
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish.
|
|
324
|
+
You can also build a [static version](https://storybook.js.org/docs/angular/sharing/publish-storybook) of your Storybook and deploy it anywhere you want.
|
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("storybook/internal/common");
|
|
4
|
-
const core_server_1 = require("storybook/internal/core-server");
|
|
5
|
-
const telemetry_1 = require("storybook/internal/telemetry");
|
|
6
3
|
const architect_1 = require("@angular-devkit/architect");
|
|
7
|
-
const fd_package_json_1 = require("fd-package-json");
|
|
8
|
-
const find_up_1 = require("find-up");
|
|
9
4
|
const rxjs_1 = require("rxjs");
|
|
10
5
|
const operators_1 = require("rxjs/operators");
|
|
11
|
-
const
|
|
6
|
+
const find_up_1 = require("find-up");
|
|
7
|
+
const read_pkg_up_1 = require("read-pkg-up");
|
|
8
|
+
const cli_1 = require("@storybook/cli");
|
|
9
|
+
const telemetry_1 = require("@storybook/telemetry");
|
|
10
|
+
const core_server_1 = require("@storybook/core-server");
|
|
12
11
|
const run_compodoc_1 = require("../utils/run-compodoc");
|
|
13
|
-
|
|
12
|
+
const error_handler_1 = require("../utils/error-handler");
|
|
13
|
+
(0, telemetry_1.addToGlobalContext)('cliVersion', cli_1.versions.storybook);
|
|
14
14
|
const commandBuilder = (options, context) => {
|
|
15
15
|
const builder = (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
|
|
16
|
-
const docTSConfig = (0, find_up_1.sync)('tsconfig.doc.json', { cwd: options.configDir });
|
|
17
16
|
const runCompodoc$ = options.compodoc
|
|
18
|
-
? (0, run_compodoc_1.runCompodoc)({ compodocArgs: options.compodocArgs, tsconfig:
|
|
17
|
+
? (0, run_compodoc_1.runCompodoc)({ compodocArgs: options.compodocArgs, tsconfig: tsConfig }, context).pipe((0, operators_1.mapTo)({ tsConfig }))
|
|
19
18
|
: (0, rxjs_1.of)({});
|
|
20
19
|
return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
|
|
21
20
|
}), (0, operators_1.map)(({ tsConfig }) => {
|
|
22
|
-
(0,
|
|
21
|
+
(0, cli_1.getEnvConfig)(options, {
|
|
23
22
|
staticDir: 'SBCONFIG_STATIC_DIR',
|
|
24
23
|
outputDir: 'SBCONFIG_OUTPUT_DIR',
|
|
25
24
|
configDir: 'SBCONFIG_CONFIG_DIR',
|
|
26
25
|
});
|
|
27
|
-
const { browserTarget, stylePreprocessorOptions, styles, configDir, docs, loglevel,
|
|
26
|
+
const { browserTarget, stylePreprocessorOptions, styles, configDir, docs, loglevel, outputDir, quiet, enableProdMode = true, webpackStatsJson, debugWebpack, disableTelemetry, assets, previewUrl, sourceMap = false, } = options;
|
|
28
27
|
const standaloneOptions = {
|
|
29
|
-
packageJson: (0,
|
|
28
|
+
packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
|
|
30
29
|
configDir,
|
|
31
30
|
...(docs ? { docs } : {}),
|
|
32
31
|
loglevel,
|
|
33
32
|
outputDir,
|
|
34
|
-
test,
|
|
35
33
|
quiet,
|
|
36
34
|
enableProdMode,
|
|
37
35
|
disableTelemetry,
|
|
@@ -42,12 +40,9 @@ const commandBuilder = (options, context) => {
|
|
|
42
40
|
...(styles ? { styles } : {}),
|
|
43
41
|
...(assets ? { assets } : {}),
|
|
44
42
|
sourceMap,
|
|
45
|
-
preserveSymlinks,
|
|
46
|
-
experimentalZoneless,
|
|
47
43
|
},
|
|
48
44
|
tsConfig,
|
|
49
45
|
webpackStatsJson,
|
|
50
|
-
statsJson,
|
|
51
46
|
debugWebpack,
|
|
52
47
|
previewUrl,
|
|
53
48
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @jest-environment node
|
|
4
|
+
*/
|
|
2
5
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
6
|
if (k2 === undefined) k2 = k;
|
|
4
7
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -15,38 +18,27 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
18
|
}) : function(o, v) {
|
|
16
19
|
o["default"] = v;
|
|
17
20
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
35
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
29
|
const architect_1 = require("@angular-devkit/architect");
|
|
37
30
|
const testing_1 = require("@angular-devkit/architect/testing");
|
|
38
31
|
const core_1 = require("@angular-devkit/core");
|
|
39
|
-
const path = __importStar(require("
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const buildStaticStandaloneMock = vitest_1.vi.fn();
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const buildDevStandaloneMock = jest.fn();
|
|
34
|
+
const buildStaticStandaloneMock = jest.fn();
|
|
43
35
|
const buildMock = {
|
|
44
36
|
buildDevStandalone: buildDevStandaloneMock,
|
|
45
37
|
buildStaticStandalone: buildStaticStandaloneMock,
|
|
46
38
|
withTelemetry: (name, options, fn) => fn(),
|
|
47
39
|
};
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
jest.doMock('@storybook/core-server', () => buildMock);
|
|
41
|
+
jest.doMock('@storybook/cli', () => ({
|
|
50
42
|
JsPackageManagerFactory: {
|
|
51
43
|
getPackageManager: () => ({
|
|
52
44
|
runPackageCommand: mockRunScript,
|
|
@@ -57,13 +49,14 @@ vitest_1.vi.doMock('storybook/internal/common', () => ({
|
|
|
57
49
|
storybook: 'x.x.x',
|
|
58
50
|
},
|
|
59
51
|
}));
|
|
60
|
-
|
|
61
|
-
const mockRunScript =
|
|
52
|
+
jest.doMock('find-up', () => ({ sync: () => './storybook/tsconfig.ts' }));
|
|
53
|
+
const mockRunScript = jest.fn();
|
|
62
54
|
// Randomly fails on CI. TODO: investigate why
|
|
63
|
-
|
|
55
|
+
// eslint-disable-next-line jest/no-disabled-tests
|
|
56
|
+
describe.skip('Build Storybook Builder', () => {
|
|
64
57
|
let architect;
|
|
65
58
|
let architectHost;
|
|
66
|
-
|
|
59
|
+
beforeEach(async () => {
|
|
67
60
|
const registry = new core_1.schema.CoreSchemaRegistry();
|
|
68
61
|
registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
|
|
69
62
|
architectHost = new testing_1.TestingArchitectHost();
|
|
@@ -85,82 +78,82 @@ vitest_1.describe.skip('Build Storybook Builder', () => {
|
|
|
85
78
|
// for the package.json file.
|
|
86
79
|
await architectHost.addBuilderFromPackage(path.join(__dirname, '../../..'));
|
|
87
80
|
});
|
|
88
|
-
|
|
81
|
+
beforeEach(() => {
|
|
89
82
|
buildStaticStandaloneMock.mockImplementation((_options) => Promise.resolve(_options));
|
|
90
83
|
});
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
afterEach(() => {
|
|
85
|
+
jest.clearAllMocks();
|
|
93
86
|
});
|
|
94
|
-
|
|
87
|
+
it('should start storybook with angularBrowserTarget', async () => {
|
|
95
88
|
const run = await architect.scheduleBuilder('@storybook/angular:build-storybook', {
|
|
96
89
|
browserTarget: 'angular-cli:build-2',
|
|
97
90
|
compodoc: false,
|
|
98
91
|
});
|
|
99
92
|
const output = await run.result;
|
|
100
93
|
await run.stop();
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
expect(output.success).toBeTruthy();
|
|
95
|
+
expect(mockRunScript).not.toHaveBeenCalledWith();
|
|
96
|
+
expect(buildStaticStandaloneMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
104
97
|
angularBrowserTarget: 'angular-cli:build-2',
|
|
105
|
-
angularBuilderContext:
|
|
98
|
+
angularBuilderContext: expect.any(Object),
|
|
106
99
|
configDir: '.storybook',
|
|
107
100
|
loglevel: undefined,
|
|
108
101
|
quiet: false,
|
|
109
102
|
disableTelemetry: undefined,
|
|
110
103
|
outputDir: 'storybook-static',
|
|
111
|
-
packageJson:
|
|
104
|
+
packageJson: expect.any(Object),
|
|
112
105
|
mode: 'static',
|
|
113
106
|
tsConfig: './storybook/tsconfig.ts',
|
|
114
|
-
|
|
107
|
+
webpackStatsJson: false,
|
|
115
108
|
}));
|
|
116
109
|
});
|
|
117
|
-
|
|
110
|
+
it('should start storybook with tsConfig', async () => {
|
|
118
111
|
const run = await architect.scheduleBuilder('@storybook/angular:build-storybook', {
|
|
119
112
|
tsConfig: 'path/to/tsConfig.json',
|
|
120
113
|
compodoc: false,
|
|
121
114
|
});
|
|
122
115
|
const output = await run.result;
|
|
123
116
|
await run.stop();
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
expect(output.success).toBeTruthy();
|
|
118
|
+
expect(mockRunScript).not.toHaveBeenCalledWith();
|
|
119
|
+
expect(buildStaticStandaloneMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
127
120
|
angularBrowserTarget: null,
|
|
128
|
-
angularBuilderContext:
|
|
121
|
+
angularBuilderContext: expect.any(Object),
|
|
129
122
|
configDir: '.storybook',
|
|
130
123
|
loglevel: undefined,
|
|
131
124
|
quiet: false,
|
|
132
125
|
disableTelemetry: undefined,
|
|
133
126
|
outputDir: 'storybook-static',
|
|
134
|
-
packageJson:
|
|
127
|
+
packageJson: expect.any(Object),
|
|
135
128
|
mode: 'static',
|
|
136
129
|
tsConfig: 'path/to/tsConfig.json',
|
|
137
|
-
|
|
130
|
+
webpackStatsJson: false,
|
|
138
131
|
}));
|
|
139
132
|
});
|
|
140
|
-
|
|
133
|
+
it('should build storybook with webpack stats.json', async () => {
|
|
141
134
|
const run = await architect.scheduleBuilder('@storybook/angular:build-storybook', {
|
|
142
135
|
tsConfig: 'path/to/tsConfig.json',
|
|
143
136
|
compodoc: false,
|
|
144
|
-
|
|
137
|
+
webpackStatsJson: true,
|
|
145
138
|
});
|
|
146
139
|
const output = await run.result;
|
|
147
140
|
await run.stop();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
expect(output.success).toBeTruthy();
|
|
142
|
+
expect(mockRunScript).not.toHaveBeenCalledWith();
|
|
143
|
+
expect(buildStaticStandaloneMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
151
144
|
angularBrowserTarget: null,
|
|
152
|
-
angularBuilderContext:
|
|
145
|
+
angularBuilderContext: expect.any(Object),
|
|
153
146
|
configDir: '.storybook',
|
|
154
147
|
loglevel: undefined,
|
|
155
148
|
quiet: false,
|
|
156
149
|
outputDir: 'storybook-static',
|
|
157
|
-
packageJson:
|
|
150
|
+
packageJson: expect.any(Object),
|
|
158
151
|
mode: 'static',
|
|
159
152
|
tsConfig: 'path/to/tsConfig.json',
|
|
160
|
-
|
|
153
|
+
webpackStatsJson: true,
|
|
161
154
|
}));
|
|
162
155
|
});
|
|
163
|
-
|
|
156
|
+
it('should throw error', async () => {
|
|
164
157
|
buildStaticStandaloneMock.mockRejectedValue(true);
|
|
165
158
|
const run = await architect.scheduleBuilder('@storybook/angular:build-storybook', {
|
|
166
159
|
browserTarget: 'angular-cli:build-2',
|
|
@@ -168,34 +161,35 @@ vitest_1.describe.skip('Build Storybook Builder', () => {
|
|
|
168
161
|
});
|
|
169
162
|
try {
|
|
170
163
|
await run.result;
|
|
171
|
-
|
|
164
|
+
expect(false).toEqual('Throw expected');
|
|
172
165
|
}
|
|
173
166
|
catch (error) {
|
|
174
|
-
|
|
167
|
+
// eslint-disable-next-line jest/no-try-expect, jest/no-conditional-expect
|
|
168
|
+
expect(error).toEqual('Broken build, fix the error above.\nYou may need to refresh the browser.');
|
|
175
169
|
}
|
|
176
170
|
});
|
|
177
|
-
|
|
171
|
+
it('should run compodoc', async () => {
|
|
178
172
|
const run = await architect.scheduleBuilder('@storybook/angular:build-storybook', {
|
|
179
173
|
browserTarget: 'angular-cli:build-2',
|
|
180
174
|
});
|
|
181
175
|
const output = await run.result;
|
|
182
176
|
await run.stop();
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
177
|
+
expect(output.success).toBeTruthy();
|
|
178
|
+
expect(mockRunScript).toHaveBeenCalledWith('compodoc', ['-p', './storybook/tsconfig.ts', '-d', '.', '-e', 'json'], '');
|
|
179
|
+
expect(buildStaticStandaloneMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
186
180
|
angularBrowserTarget: 'angular-cli:build-2',
|
|
187
|
-
angularBuilderContext:
|
|
181
|
+
angularBuilderContext: expect.any(Object),
|
|
188
182
|
configDir: '.storybook',
|
|
189
183
|
loglevel: undefined,
|
|
190
184
|
quiet: false,
|
|
191
185
|
outputDir: 'storybook-static',
|
|
192
|
-
packageJson:
|
|
186
|
+
packageJson: expect.any(Object),
|
|
193
187
|
mode: 'static',
|
|
194
188
|
tsConfig: './storybook/tsconfig.ts',
|
|
195
|
-
|
|
189
|
+
webpackStatsJson: false,
|
|
196
190
|
}));
|
|
197
191
|
});
|
|
198
|
-
|
|
192
|
+
it('should start storybook with styles options', async () => {
|
|
199
193
|
const run = await architect.scheduleBuilder('@storybook/angular:build-storybook', {
|
|
200
194
|
tsConfig: 'path/to/tsConfig.json',
|
|
201
195
|
compodoc: false,
|
|
@@ -203,20 +197,20 @@ vitest_1.describe.skip('Build Storybook Builder', () => {
|
|
|
203
197
|
});
|
|
204
198
|
const output = await run.result;
|
|
205
199
|
await run.stop();
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
expect(output.success).toBeTruthy();
|
|
201
|
+
expect(mockRunScript).not.toHaveBeenCalledWith();
|
|
202
|
+
expect(buildStaticStandaloneMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
209
203
|
angularBrowserTarget: null,
|
|
210
|
-
angularBuilderContext:
|
|
204
|
+
angularBuilderContext: expect.any(Object),
|
|
211
205
|
angularBuilderOptions: { assets: [], styles: ['style.scss'] },
|
|
212
206
|
configDir: '.storybook',
|
|
213
207
|
loglevel: undefined,
|
|
214
208
|
quiet: false,
|
|
215
209
|
outputDir: 'storybook-static',
|
|
216
|
-
packageJson:
|
|
210
|
+
packageJson: expect.any(Object),
|
|
217
211
|
mode: 'static',
|
|
218
212
|
tsConfig: 'path/to/tsConfig.json',
|
|
219
|
-
|
|
213
|
+
webpackStatsJson: false,
|
|
220
214
|
}));
|
|
221
215
|
});
|
|
222
216
|
});
|