Problem/Motivation
When generating stories, parameter.server.url is automatically set in each stories file based on the internal:/storybook/stories/render URI. Due to Storybook's rules of parameter inheritance this makes it impossible to set the server url to a different environment other than the one in which the stories file was generated.
By allowing the server url to be set as a global parameter, static Storybook builds can be generated for different environments without having to regenerate a specific set of stories.json files each time. This is useful when deploying a Storybook build to static server such as Pantheon's multi-dev environments.
API changes
This adds a new CLI option to the storybook:generate-stories command that will omit the server url parameter from the generated stories allowing it to be set globally in Storybook.
Usage:
drush storybook:generate-all-stories --omit-server-url
In you will then need to set the server url globally in .storybook/preview.js. For example
const preview = {
...
parameters: {
server: {
url: process.env.STORYBOOK_SERVER_URL || 'http://my-local-site.lndo.site/storybook/stories/render',
},
...
}
Requires an update to twig-storybook
Data model changes
Issue fork storybook-3424336
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
pixelwhip commentedComment #4
pixelwhip commentedComment #5
markie commentedCurious.. Why not have a `--server-url` switch instead of `--omit-url`, this way build commands could utilize the functionality. And if switch is not used, default.. Just a thought
Comment #6
pixelwhip commentedThe `--server-url` is already possible with Drush's `--uri` option. In my case, I need to omit the server url from the stories.json file completely so it can be set in the Storybook configuration.
Example:
I discovered this recently when setting Storybook up with Tugboat for the Prototype theme. If you don't have the URI configured for Drush, the URL will end up being `http://default*`
Comment #7
pixelwhip commentedComment #8
bander2 commentedLooks like this does not omit the server url, it sets it to an empty string:
Which gives me this error:
When I manually delete the parameters section above, it works. So I think url needs to be completely omitted.
Comment #9
brayn7 commented@bander2 You have to patch the vendor dependency too.
This works great for me.
Comment #10
bander2 commentedbrayn7, that works. Thanks!
Comment #13
bradwade commentedI tested the following patches on our website and they are working as expected... json stories are generated without a server URL parameter when `--omit-server-url` flag is provided .
Since it seems multiple people have successfully tested, is the next step to create a new tag for e0ipso/twig-storybook which contains the already-merged-to-main issue 10 (https://github.com/e0ipso/twig-storybook/pull/11), then bump the version requirement here in composer.json so that new tag is pulled in as a dependency... then merge this MR 6?
Sorry MR9 is showing in this thread. That was for another issue.
Comment #14
e0ipsoThank you everyone for your contribution!
Comment #15
e0ipsoI had to resolve merge conflicts on the README.md