-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Storybook schematics #1582
Conversation
function addStorybookTask(projectName: string): Rule { | ||
return <any>updateWorkspace(workspace => { | ||
workspace.projects.get(projectName).targets.add({ | ||
name: 'storybook', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if we want multiple projects to have storybook? Won't we have a conflict here with the name? Btw. Should we have multiple storybooks per project or maybe only one for the whole workspace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should have included more information on the goal of this PR. This schematic is set up to create an isolated storybook instance for a specific ui-lib. For large monorepos, having a single storybook instance would be un-manageable.
This line doesn't cause a conflict - it creates a storybook
target for the individual lib (just like each lib has its own lint
target). The run-command
is set to point at the specific .storybook
folder inside the lib (which only searches that lib for *.stories.ts
files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that does explain a lot. But using storybook only for tests is a bit of waste I think. It would be great to have option of adding different addons, like np storysource etc from some cli prompt when crating story.
I just integrated storybook in our company repo but went with one storybook per monorepo approach, but I see some benefits from usage per lib.
Have You tried how it works if u try to use affected? Does it run only required storybooks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nx affected doesn't work well for the storybook target, because it runs the first one and the process never finishes to run the next one. It would make sense for a storybook-build target though. I haven't written that, but it would be pretty straight forward to add.
nx affected works great for the cypress e2e tests though. For each affected ui-lib, the storybook is launched, the cypress tests run, then all the processes end and the next e2e test target runs.
I would like to include more options for addons, that just hasn't made in this first pass. You'll always be able to go into each .storybook
folder and make whatever customizations you want.
Here's a bit more information on what these schematics are intended to generate. Storybook portion:
Cypress integration:
|
The overall goal is to make it quick and easy to run isolated ui tests on individual components using Cypress. And as a side benefit, you get a storybook instance that you can use for other purposes. |
packages/storybook/src/schematics/storybook-configure/storybook-configure.ts
Outdated
Show resolved
Hide resolved
}; | ||
} | ||
|
||
function updateAngularJsonBuilder( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm.... I wonder if it would make sense to make devServerTarget
and prodDevServerTarget
options for @nrwl/cypress:cypress-project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in this PR
{}, | ||
{ | ||
'@storybook/angular': storybookAngularVersion, | ||
'@storybook/addon-knobs': storybookAddonKnobsVersion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like some plugin... Should we let users add this for themselves if they want to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using this plugin for the core functionality of creating isolated cypress ui tests. Eventually, I'd like to give people the choice to include other plugins automatically.
So excited for Storybook integration! 🎉 |
4448ff5
to
9c7ccba
Compare
@isaacplmann @FrozenPandaz hey folks, any update on this? |
@vsavkin The PR is almost there. I have a e2e test set up, but it keeps silently failing. When I try to manually recreate what the e2e test is doing, everything works as expected. |
@@ -1,4 +1,4 @@ | |||
export const storybookAngularVersion = '5.1.9'; | |||
export const storybookAddonKnobsVersion = '5.1.9'; | |||
export const storybookAddonKnobsVersion = '5.0.3'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use the same version as storybookAngularVersion?
As well, can we update to 5.10.1?
@isaacplmann - earlier you described the intent of these schematics: Storybook portion: .storybook folder inside of a ui lib A [ui-lib-name]-e2e app that runs cypress against the storybook for that lib I feel there is another important scenario: The ability to generate a 1...n storybook apps which import storybook Modules for 1...n ui (or feature UI libraries). Having distinct Storybook apps would allow designers to quickly validate UI library components and feature UX. |
I've been using Storybook for NX for a bit now. Just never got around to writing the schematics. Personally, i feel this PR is too early to be considered complete and the requirements should be scoped out better before rushing into adding new features. Rather than having multiple .storybook folders which you are required to configure each time. Would it not be better to add a root level folder which contains the global storybook and extend each UI library from the base config. I don't know about you but I also configure storybook with the same plugins root => .storybook => config.js
root => .storybook => plugins.js ui-lib => .storybook => plugin.js ui-lib => .storybook => config.js
|
@ThomasBurleson @Jordan-Hall Thanks to both of you for giving some feedback. I'll put in some more work on this PR tomorrow. |
I have such config in one of my playgrounds. Maybe I will try and make
schematic. That would be a great lesson for me as well.
W dniu czw., 15.08.2019 o 16:14 Isaac Mann <[email protected]>
napisał(a):
… @ThomasBurleson <https://github.com/ThomasBurleson>
That's a great feature. I think I'll add that as a separate schematic in a
future PR.
@Jordan-Hall <https://github.com/Jordan-Hall>
I really like that idea. That would make the storybook config more inline
with the way cypress, jest, karma, etc are handled.
Thanks to both of you for giving some feedback. I'll put in some more work
on this PR tomorrow.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1582?email_source=notifications&email_token=AFKBQQKOEFYN5KDSCI2V443QEVQF3A5CNFSM4ICQ6YG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4L5QRA#issuecomment-521656388>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFKBQQNWT4TSE3FNOBGHF3TQEVQF3ANCNFSM4ICQ6YGQ>
.
|
@isaacplmann I've just noticed we don't have a build option, this PR only has a serve option. It would be good to add support to build the storybook in case we want to deploy it. At least for @ThomasBurleson suggestion of a global storybook. Maybe only offer support to build each lib where a pacakge.json exists. |
1372b3b
to
9893fc1
Compare
r = r.filter(rule => rule.test != '/\\.css$/'); | ||
|
||
// Make whatever fine-grained changes you need | ||
r.push({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think storybook should match every stylesheet nx supports. Also, do we require custom scss support? Under the hood, it uses angular cli which already has it supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some conflict between the angular cli and storybook's webpack config that throws displays an error instead of your storybook content unless we do this custom webpack config workaround. See: storybookjs/storybook#3593
I haven't tried stylesheets other than css and scss.
@@ -1,4 +1,5 @@ | |||
export const storybookAngularVersion = '5.1.11'; | |||
export const storybookAddonKnobsVersion = '5.1.11'; | |||
export const storybookAddonKnobsTypesVersion = '5.0.3'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are default addons required? It's not needed to set it up manually so shouldn't be required to do it programmatically using schematics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using the knobs addon in the auto-generated stories. That's probably the first addon most people will include.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realistically, are there any usages that don't use knobs? I don't think it's a bad default.
Just out of curiosity, and i cant wait to see this brought in. Are we not limiting ourselves with this approach to only angular. We also need to look at support react and I think something else needs to be done to get this to work |
Yes, we definitely want to add React support. I haven't started thinking about how to do that though. Any ideas? |
I've got a few ideas. It appears the only major difference is how you load/configure stories. Maybe for now just adding it as a required field for which framework to support. along with two extra npm packages react & react-dom I've currently got your repository checked out looking at a builder for this. I was thinking we could clean up the .storybook folder as long as we pass in the project path. |
Nice. I do want to have a builder in place. Right now I'm working on extending a root configuration like you suggested. |
Which is fine because you may need project-specific configuration which would then require it's own .storybook like your working on now |
@@ -0,0 +1,5 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work. It's better not to have this base tsconfig. Your better off enforcing this into each individual app, otherwise, all stories will be included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for running a global storybook that will pick up all stories in the monorepo
@@ -2,10 +2,12 @@ import { configure, addDecorator } from '@storybook/angular'; | |||
import { withKnobs } from '@storybook/addon-knobs'; | |||
|
|||
function loadStories() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for the global storybook? or is this for each individual to extend, If the answer is for individuals you should have this functionality in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for running a global storybook that will pick up all stories in the monorepo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about extending the base config for the individual one? Wouldn't a better option to add a new application in angular.json for the global storybook to run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a separate app would work, but the benefit of this .storybook
folder configuration is that people who are used to running start-storybook
from the command line will get the global storybook
import { configure } from '<%= offsetFromRoot %>../.storybook/config'; | ||
|
||
function loadStories() { | ||
const req = require.context('../src/lib', true, /\.stories\.ts$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const req = require.context('../src/', true, /\.stories\.ts$/);
Think this would be better incase someone has an app level storybook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's a good idea.
858ba16
to
ae623f6
Compare
@isaacplmann I think I can get a builder sorted for tomorrow night which should work depending on the framework you've selected. Would it be better to wait until after this is merged or should storybook come in as one? |
@isaacplmann How much longer until this will be ready to be merged in? I've got the basic builder working. Just adding all the other customization to allow more flexibility and then update the schematics and write the unit tests. Shouldn't take too much longer, but should add this is the first time working with the angular devkit. angular.json
|
My PR won't be merged before Monday certainly. And if you have a mostly
working builder, it would be better to include that with this PR. Do you
want to open a PR against my branch?
…On Sun, Aug 18, 2019, 6:36 AM Jordan Hall ***@***.***> wrote:
@isaacplmann <https://github.com/isaacplmann> How much longer until this
will be ready to be merged in? I've got the basic builder working. Just
adding all the other customization to allow more flexibility and then
update the schematics and write the unit tests. Shouldn't take too much
longer, but should add this is the first time working with the angular
devkit.
angular.json
"storybook": {
"builder": ***@***.***/storybook:storybook",
"options": {
"uiFramework": ***@***.***/angular",
"config": {
"configFolder": "apps/rina-eas/.storybook"
}
}
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1582?email_source=notifications&email_token=AAGSKQD66462B3MIQZJSCSDQFEQ2HA5CNFSM4ICQ6YG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4Q5C7Y#issuecomment-522310015>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGSKQHGE6ORHTHZOKZ2VILQFEQ2HANCNFSM4ICQ6YGQ>
.
|
Hey, So I builder has run into an issue when using storybook/angular. storybookjs/storybook#7207 We need to wait until version 5.2 come out. I'll work with 5.2 for now so it's ready on release |
3569a53
to
54d5826
Compare
@Jordan-Hall , can you share your in progress code? I have more time this week and can help work around the issue you ran into. |
926327b
to
69e4534
Compare
test: Add tests test: remove test chore: Move some schematics into @nrwl/angular test: fix tests chore: Add e2e test chore: Bump storybook versions chore: createTestUiLib takes a libName argument chore: configs extend root config fix: Remove custom scss loader feat: add storybook builder fix: generate documentation and fix linting chore: Builder tests passing
69e4534
to
6908d9b
Compare
Any idea when this PR will merged and released? I'm looking forward on using this functionality in my projects. |
@kristofdegrave, @vsavkin is planning to review it soon, but he just got back from a conference so it might take him a bit. |
runCLI( | ||
`generate @nrwl/storybook:configuration ${mylib2} --configureCypress --generateStories --generateCypressSpecs --no-interactive` | ||
); | ||
runYarnInstall(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove it and instead add storybook dependences to the list of dependencies we copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See copyMissingPackages
runCLI(`generate @nrwl/angular:app ${myapp} --no-interactive`); | ||
|
||
const mylib = uniq('test-ui-lib'); | ||
createTestUILib(mylib); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you don't use this library anywhere else, can you move from utils to tihs spec file?
@@ -2,6 +2,7 @@ | |||
"fileServerFolder": ".", | |||
"fixturesFolder": "./src/fixtures", | |||
"integrationFolder": "./src/integration", | |||
"modifyObstructiveCode": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
Did you add schematics for react as the builder supports it |
Working on that next
…On Sat, Oct 26, 2019, 2:06 PM Jordan Hall ***@***.***> wrote:
Did you add schematics for react as the builder supports it
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1582?email_source=notifications&email_token=AAGSKQBR3LSGO7COS4SRCHTQQSBLDA5CNFSM4ICQ6YG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECKNVIQ#issuecomment-546626210>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGSKQD42NJDEDPBU5S5B3DQQSBLDANCNFSM4ICQ6YGQ>
.
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Please make sure you have read the submission guidelines before posting an PR
Current Behavior (This is the behavior we have today, before the PR is merged)
No way to add storybook to a workspace.
Expected Behavior (This is the new behavior we can expect after the PR is merged)
@nrwl/storybook
is a set of schematics to programmatically scaffold storybook stories and cypress tests to a ui lib.TODO: Add tests for all the schematics.