|
1 |
| -# Storybook Addon Addon coverage |
2 |
| -Tools to support code coverage in Storybook |
| 1 | +# Storybook Addon Coverage |
3 | 2 |
|
| 3 | +Tools to support code coverage in Storybook and the [test runner](https://github.com/storybookjs/test-runner) |
| 4 | + |
4 | 5 | ### Development scripts
|
5 | 6 |
|
6 | 7 | - `yarn start` runs babel in watch mode and starts Storybook
|
7 | 8 | - `yarn build` build and package your addon code
|
8 |
| - |
9 |
| -### Switch from TypeScript to JavaScript |
10 |
| - |
11 |
| -Don't want to use TypeScript? We offer a handy eject command: `yarn eject-ts` |
12 |
| - |
13 |
| -This will convert all code to JS. It is a destructive process, so we recommended running this before you start writing any code. |
14 |
| - |
15 |
| -## What's included? |
16 |
| - |
17 |
| - |
18 |
| - |
19 |
| -The addon code lives in `src`. It demonstrates all core addon related concepts. The three [UI paradigms](https://storybook.js.org/docs/react/addons/addon-types#ui-based-addons) |
20 |
| - |
21 |
| -- `src/Tool.js` |
22 |
| -- `src/Panel.js` |
23 |
| -- `src/Tab.js` |
24 |
| - |
25 |
| -Which, along with the addon itself, are registered in `src/preset/manager.js`. |
26 |
| - |
27 |
| -Managing State and interacting with a story: |
28 |
| - |
29 |
| -- `src/withGlobals.js` & `src/Tool.js` demonstrates how to use `useGlobals` to manage global state and modify the contents of a Story. |
30 |
| -- `src/withRoundTrip.js` & `src/Panel.js` demonstrates two-way communication using channels. |
31 |
| -- `src/Tab.js` demonstrates how to use `useParameter` to access the current story's parameters. |
32 |
| - |
33 |
| -Your addon might use one or more of these patterns. Feel free to delete unused code. Update `src/preset/manager.js` and `src/preset/preview.js` accordingly. |
34 |
| - |
35 |
| -Lastly, configure you addon name in `src/constants.js`. |
36 |
| - |
37 |
| -### Metadata |
38 |
| - |
39 |
| -Storybook addons are listed in the [catalog](https://storybook.js.org/addons) and distributed via npm. The catalog is populated by querying npm's registry for Storybook-specific metadata in `package.json`. This project has been configured with sample data. Learn more about available options in the [Addon metadata docs](https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata). |
40 |
| - |
41 |
| -## Release Management |
42 |
| - |
43 |
| -### Setup |
44 |
| - |
45 |
| -This project is configured to use [auto](https://github.com/intuit/auto) for release management. It generates a changelog and pushes it to both GitHub and npm. Therefore, you need to configure access to both: |
46 |
| - |
47 |
| -- [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens) Create a token with both _Read and Publish_ permissions. |
48 |
| -- [`GH_TOKEN`](https://github.com/settings/tokens) Create a token with the `repo` scope. |
49 |
| - |
50 |
| -Then open your `package.json` and edit the following fields: |
51 |
| - |
52 |
| -- `name` |
53 |
| -- `author` |
54 |
| -- `repository` |
55 |
| - |
56 |
| -#### Local |
57 |
| - |
58 |
| -To use `auto` locally create a `.env` file at the root of your project and add your tokens to it: |
59 |
| - |
60 |
| -```bash |
61 |
| -GH_TOKEN=<value you just got from GitHub> |
62 |
| -NPM_TOKEN=<value you just got from npm> |
63 |
| -``` |
64 |
| - |
65 |
| -Lastly, **create labels on GitHub**. You’ll use these labels in the future when making changes to the package. |
66 |
| - |
67 |
| -```bash |
68 |
| -npx auto create-labels |
69 |
| -``` |
70 |
| - |
71 |
| -If you check on GitHub, you’ll now see a set of labels that `auto` would like you to use. Use these to tag future pull requests. |
72 |
| - |
73 |
| -#### GitHub Actions |
74 |
| - |
75 |
| -This template comes with GitHub actions already set up to publish your addon anytime someone pushes to your repository. |
76 |
| - |
77 |
| -Go to `Settings > Secrets`, click `New repository secret`, and add your `NPM_TOKEN`. |
78 |
| - |
79 |
| -### Creating a release |
80 |
| - |
81 |
| -To create a release locally you can run the following command, otherwise the GitHub action will make the release for you. |
82 |
| - |
83 |
| -```sh |
84 |
| -yarn release |
85 |
| -``` |
86 |
| - |
87 |
| -That will: |
88 |
| - |
89 |
| -- Build and package the addon code |
90 |
| -- Bump the version |
91 |
| -- Push a release to GitHub and npm |
92 |
| -- Push a changelog to GitHub |
0 commit comments