UNPKG

15.7 kBMarkdownView Raw
1# Storybook Deployer
2
3This is a simple tool allows you to deploy your Storybook into a static hosting service. (Currently, GitHub Pages and AWS S3 beta)
4
5```sh
6$ storybook-to-ghpages --help
7$ storybook-to-aws-s3 --help
8
9Options:
10 --help, -h Show help. [boolean]
11 --version Show version number [boolean]
12 --existing-output-dir, -e If you have previously built your storybook output (through a
13 different CI step, etc) and just need to publish it [string]
14 --out, -o Configure the output directory [string]
15 --packages, -p Directory for package.jsons (monorepo support) [string]
16 --monorepo-index-generator, -m Path to file to customize the monorepo index.html. This function
17 should return the html for the page. [string]
18 --script, -s Specify the build script in your package.json [string]
19 --ci Deploy the storybook in CI mode (github only) [boolean]
20 --dry-run Run build but hold off on publishing [boolean]
21 --remote Git remote to push to [string] [default: "origin"]
22 --branch Git branch to push to [string] [default: "gh-pages"]
23 --source-branch Source branch to push from [string] [default: "master"]
24 --host-token-env-variable, -t Github token for CI publish [string] [default: "GH_TOKEN"]
25 --aws-profile AWS profile to use for publishing. Use NONE to use no profile
26 at all instead of "default". [string] [default: "default"]
27 --bucket-path AWS bucket path to use for publishing [string]
28 --s3-sync-options Additional options to pass to AWSCLI s3 sync [string]
29```
30
31## Getting Started
32
33Install Storybook Deployer with:
34
35```
36npm i @storybook/storybook-deployer --save-dev
37```
38
39Then add a NPM script like this for github page:
40
41```json
42{
43 "scripts": {
44 "deploy-storybook": "storybook-to-ghpages"
45 }
46}
47```
48
49or like this for AWS S3:
50
51```json
52{
53 "scripts": {
54 "deploy-storybook": "storybook-to-aws-s3"
55 }
56}
57```
58
59Then you can run `npm run deploy-storybook` to deploy the Storybook.
60
61Alternatively, you can execute Storybook Deployer directly using `npx`
62
63```sh
64npx -p @storybook/storybook-deployer storybook-to-ghpages
65npx -p @storybook/storybook-deployer storybook-to-aws-s3
66```
67
68### Custom Build Configuration
69
70If you customize the build configuration with some additional params (like static file directory), then you need to expose another NPM script like this:
71
72```json
73{
74 "scripts": {
75 "build-storybook": "build-storybook -s public"
76 }
77}
78```
79
80### Configure Build Directory
81
82If you need to configure the output directory you can supply the `out` flag.
83
84```sh
85npm run deploy-storybook -- --out=.out
86```
87
88### Skip Build Step
89
90If you have previously built your storybook output (through a different CI step, etc) and just need to publish it, specify the directory like this:
91
92```sh
93npm run deploy-storybook -- --existing-output-dir=.out
94```
95
96### Skip Deploy Step
97
98if you want to see how everything build without pushing to a remote, use the `--dry-run` flag.
99
100```sh
101npm run deploy-storybook -- --dry-run
102```
103
104### Deploy a Monorepo
105
106If you manage a monorepo with multiple storybooks you can pass the `packages` flag to `deploy-storybook` to scan a directory for `package.json`s.
107
108The following command will search the `packages` directory for packages. It will also generate a default `index.html` that links to all of the loaded storybooks.
109
110```sh
111npm run deploy-storybook -- --packages packages
112```
113
114### Customize Monorepo `index.html`
115
116To customize the monorepo `index.html` you can pass the `monorepo-index-generator` flag to `deploy-storybook`. This file should export a function that receive the following arguments and returns the html for the page.
117
118- an array of all the `package.json` data from the loaded storybooks as the first argument
119- the output directory
120
121```sh
122npm run deploy-storybook -- --monorepo-index-generator my-custom-generator.js
123```
124
125### Deploying Storybook as part of a CI service
126
127To deploy Storybook as part of a CI step, pass the `ci` flag to `npm run deploy-storybook`.
128
129If the `CI` environment variable is set then this mode will be assumed, therefore no need to specify the `ci` flag.
130
131Because pushing to GitHub as part of a CI step requires a [personal access token](https://github.com/blog/1509-personal-api-tokens), Storybook uses the `GH_TOKEN` environment variable, by default, to authenticate GitHub pushes.
132
133This environment variable name can be configured via the `host-token-env-variable` flag.
134
135For example, if your access token is stored in the `GH_TOKEN` environment variable
136
137```sh
138npm run deploy-storybook -- --ci
139```
140
141Or if your access token is stored in the `GITHUB_TOKEN` environment variable
142
143```sh
144npm run deploy-storybook -- --ci --host-token-env-variable=GITHUB_TOKEN
145```
146
147### Custom deploy configuration
148
149If you want to customize Git username, email or commit message, add this to `package.json`:
150
151```json
152"storybook-deployer": {
153 "gitUsername": "Custom Username",
154 "gitEmail": "custom@email.com",
155 "commitMessage": "Deploy Storybook [skip ci]"
156}
157```
158
159It will override the default configuration:
160
161```json
162"storybook-deployer": {
163 "gitUsername": "GH Pages Bot",
164 "gitEmail": "hello@ghbot.com",
165 "commitMessage": "Deploy Storybook to GitHub Pages"
166}
167```
168
169To deploy Storybook to a remote other than `origin`, pass a `--remote` flag to `npm run deploy-storybook`.
170For example, to deploy to your `upstream` remote:
171
172```sh
173npm run deploy-storybook -- --remote=upstream
174```
175
176Or, to specify a target branch and serve your storybook with rawgit instead of gh-pages:
177
178```sh
179npm run deploy-storybook -- --branch=feature-branch
180```
181
182Or, to specify a source branch other than `master`, pass a `--source-branch` flag to `npm run deploy-storybook`:
183
184```sh
185npm run deploy-storybook -- --source-branch=release
186```
187
188#### Custom deploy configuration for S3
189
190For AWS S3 deployment you must have [awscli](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) installed.
191
192You must specify a bucket path with `bucket-path` option: `my-bucket-name/path/to/destination-folder-in-bucket` and have the rights to write to this bucket.
193
194You can change the aws profile used to run the command with the `aws-profile` option.
195
196```sh
197storybook-to-aws-s3 --bucket-path=my-bucket-name/path/to/destination-folder-in-bucket --aws-profile=myprofile
198```
199
200You can exclude the aws profile by setting this flag to "NONE":
201
202```sh
203storybook-to-aws-s3 --bucket-path=my-bucket-name/path/to/destination-folder-in-bucket --aws-profile=NONE
204```
205
206You can provide arbitrary S3 sync options via the `--s3-sync-options` flag:
207
208```sh
209storybook-to-aws-s3 --bucket-path=bucket-name/bucket-path --s3-sync-options=--acl=public-read
210storybook-to-aws-s3 --bucket-path=bucket-name/bucket-path --s3-sync-options="--acl=public-read --quiet"
211```
212
213## Contributors ✨
214
215Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
216
217<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
218<!-- prettier-ignore-start -->
219<!-- markdownlint-disable -->
220<table>
221 <tr>
222 <td align="center"><a href="http://hipstersmoothie.com"><img src="https://avatars3.githubusercontent.com/u/1192452?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andrew Lisowski</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=hipstersmoothie" title="Code">💻</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=hipstersmoothie" title="Documentation">📖</a></td>
223 <td align="center"><a href="https://arunoda.me"><img src="https://avatars1.githubusercontent.com/u/50838?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Arunoda Susiripala</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=arunoda" title="Code">💻</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=arunoda" title="Documentation">📖</a></td>
224 <td align="center"><a href="https://github.com/ndelangen"><img src="https://avatars2.githubusercontent.com/u/3070389?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Norbert de Langen</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=ndelangen" title="Code">💻</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=ndelangen" title="Documentation">📖</a></td>
225 <td align="center"><a href="https://dandean.com"><img src="https://avatars3.githubusercontent.com/u/18332?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dan Dean</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=dandean" title="Code">💻</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=dandean" title="Documentation">📖</a></td>
226 <td align="center"><a href="http://www.jsonunger.com"><img src="https://avatars1.githubusercontent.com/u/16748392?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jason Unger</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=jsonunger" title="Code">💻</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=jsonunger" title="Documentation">📖</a></td>
227 <td align="center"><a href="https://github.com/nkov"><img src="https://avatars3.githubusercontent.com/u/3165749?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nkov</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=nkov" title="Code">💻</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=nkov" title="Documentation">📖</a></td>
228 <td align="center"><a href="https://github.com/tsargent"><img src="https://avatars3.githubusercontent.com/u/173215?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler Sargent</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=tsargent" title="Documentation">📖</a></td>
229 </tr>
230 <tr>
231 <td align="center"><a href="http://patrickmriley.net"><img src="https://avatars2.githubusercontent.com/u/4237045?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Patrick Riley</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=priley86" title="Code">💻</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=priley86" title="Documentation">📖</a></td>
232 <td align="center"><a href="https://github.com/jeanlucc"><img src="https://avatars0.githubusercontent.com/u/6769926?v=4?s=100" width="100px;" alt=""/><br /><sub><b>jeanlucc</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=jeanlucc" title="Code">💻</a></td>
233 <td align="center"><a href="http://travisbloom.me"><img src="https://avatars1.githubusercontent.com/u/1258114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Travis Bloom</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=travisbloom" title="Code">💻</a></td>
234 <td align="center"><a href="https://github.com/stof"><img src="https://avatars0.githubusercontent.com/u/439401?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Christophe Coevoet</b></sub></a><br /><a href="#maintenance-stof" title="Maintenance">🚧</a></td>
235 <td align="center"><a href="http://shilman.net"><img src="https://avatars2.githubusercontent.com/u/488689?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michael Shilman</b></sub></a><br /><a href="#maintenance-shilman" title="Maintenance">🚧</a></td>
236 <td align="center"><a href="https://github.com/jaebradley"><img src="https://avatars0.githubusercontent.com/u/8136030?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jae Bradley</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=jaebradley" title="Code">💻</a></td>
237 <td align="center"><a href="https://bryce.io/"><img src="https://avatars1.githubusercontent.com/u/3171252?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bryce Dorn</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/issues?q=author%3Abrycedorn" title="Bug reports">🐛</a></td>
238 </tr>
239 <tr>
240 <td align="center"><a href="https://github.com/baopham"><img src="https://avatars3.githubusercontent.com/u/783410?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bao Pham</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=baopham" title="Code">💻</a></td>
241 <td align="center"><a href="https://encoredevlabs.com"><img src="https://avatars1.githubusercontent.com/u/498669?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ankur Patel</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=ankurp" title="Code">💻</a></td>
242 <td align="center"><a href="https://github.com/ZitaNemeckova"><img src="https://avatars2.githubusercontent.com/u/9210860?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ZitaNemeckova</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=ZitaNemeckova" title="Code">💻</a></td>
243 <td align="center"><a href="http://lucasms.net"><img src="https://avatars3.githubusercontent.com/u/868687?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lucas Machado</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=luksm" title="Code">💻</a></td>
244 <td align="center"><a href="https://github.com/sojeri"><img src="https://avatars3.githubusercontent.com/u/10818509?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeri Sommers</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=sojeri" title="Code">💻</a></td>
245 <td align="center"><a href="http://jimmyandrade.com/"><img src="https://avatars.githubusercontent.com/u/2307245?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jimmy Andrade</b></sub></a><br /><a href="#infra-jimmyandrade" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=jimmyandrade" title="Documentation">📖</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=jimmyandrade" title="Code">💻</a></td>
246 <td align="center"><a href="https://nickthesick.com/"><img src="https://avatars.githubusercontent.com/u/1852538?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nick Perez</b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=nperez0111" title="Documentation">📖</a> <a href="https://github.com/storybookjs/storybook-deployer/commits?author=nperez0111" title="Code">💻</a></td>
247 </tr>
248 <tr>
249 <td align="center"><a href="https://github.com/mitchiemt11"><img src="https://avatars.githubusercontent.com/u/74592107?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mitchell </b></sub></a><br /><a href="https://github.com/storybookjs/storybook-deployer/commits?author=mitchiemt11" title="Documentation">📖</a></td>
250 </tr>
251</table>
252
253<!-- markdownlint-restore -->
254<!-- prettier-ignore-end -->
255
256<!-- ALL-CONTRIBUTORS-LIST:END -->
257
258This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!