Skip to content

Commit e599738

Browse files
authored
Initialize upgrade-packages
0 parents  commit e599738

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+18466
-0
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release
2+
3+
on: [push]
4+
5+
jobs:
6+
release:
7+
runs-on: ubuntu-latest
8+
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Prepare repository
13+
run: git fetch --unshallow --tags
14+
15+
- name: Use Node.js 16.x
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 16.x
19+
20+
- name: Install dependencies
21+
run: npm install --ignore-scripts
22+
23+
- name: Create Release
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27+
run: |
28+
npm run release

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dist/
2+
node_modules/
3+
storybook-static/
4+
build-storybook.log
5+
.DS_Store
6+
.env

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.storybook/local-preset.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* to load the built addon in this test Storybook
3+
*/
4+
function previewAnnotations(entry = []) {
5+
return [...entry, require.resolve("../dist/preview.mjs")];
6+
}
7+
8+
function managerEntries(entry = []) {
9+
return [...entry, require.resolve("../dist/manager.mjs")];
10+
}
11+
12+
module.exports = {
13+
managerEntries,
14+
previewAnnotations,
15+
};

.storybook/main.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { StorybookConfig } from "@storybook/react-vite";
2+
const config: StorybookConfig = {
3+
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
4+
addons: [
5+
"@storybook/addon-links",
6+
"@storybook/addon-essentials",
7+
"@storybook/addon-interactions",
8+
"./local-preset.js",
9+
],
10+
framework: {
11+
name: "@storybook/react-vite",
12+
options: {},
13+
},
14+
docs: {
15+
autodocs: "tag",
16+
},
17+
};
18+
export default config;

.storybook/preview-head.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
window.global = window;
3+
</script>

.storybook/preview.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Preview } from "@storybook/react";
2+
3+
const preview: Preview = {
4+
parameters: {
5+
backgrounds: {
6+
default: "light",
7+
},
8+
actions: { argTypesRegex: "^on[A-Z].*" },
9+
controls: {
10+
matchers: {
11+
color: /(background|color)$/i,
12+
date: /Date$/,
13+
},
14+
},
15+
},
16+
};
17+
18+
export default preview;

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Storybook contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<!-- README START -->
2+
3+
# Storybook Addon Kit ([demo](https://main--601ada52c3d4040021afdc30.chromatic.com))
4+
5+
Simplify the creation of Storybook addons
6+
7+
- 📝 Live-editing in development
8+
- ⚛️ React/JSX support
9+
- 📦 Transpiling and bundling with [tsup](https://tsup.egoist.dev/)
10+
- 🏷 Plugin metadata
11+
- 🚢 Release management with [Auto](https://github.com/intuit/auto)
12+
- 🧺 Boilerplate and sample code
13+
- 🛄 ESM support
14+
- 🛂 TypeScript by default with option to eject to JS
15+
16+
### Migrating from Storybook 6.x to 7
17+
18+
Note, if you're looking to upgrade your addon from Storybook 6.x to 7, please refer to the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#70-addon-authors-changes). The major changes are:
19+
20+
- `register.js` was removed
21+
- No more default export from `@storybook/addons`
22+
- `@storybook/api` has been split into `@storybook/preview-api` and `@storybook/manager-api`
23+
24+
Skip this section if you're bootstrapping a new addon.
25+
26+
## Getting Started
27+
28+
Click the **Use this template** button to get started.
29+
30+
![](https://user-images.githubusercontent.com/321738/125058439-8d9ef880-e0aa-11eb-9211-e6d7be812959.gif)
31+
32+
Clone your repository and install dependencies.
33+
34+
```sh
35+
npm install
36+
```
37+
38+
<!-- README END -->
39+
40+
### Development scripts
41+
42+
- `npm run start` runs babel in watch mode and starts Storybook
43+
- `npm run build` build and package your addon code
44+
45+
### Switch from TypeScript to JavaScript
46+
47+
Don't want to use TypeScript? We offer a handy eject command: `npm run eject-ts`
48+
49+
This will convert all code to JS. It is a destructive process, so we recommended running this before you start writing any code.
50+
51+
## What's included?
52+
53+
![Demo](https://user-images.githubusercontent.com/42671/107857205-e7044380-6dfa-11eb-8718-ad02e3ba1a3f.gif)
54+
55+
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)
56+
57+
- `src/Tool.tsx`
58+
- `src/Panel.tsx`
59+
- `src/Tab.tsx`
60+
61+
Which, along with the addon itself, are registered in `src/manager.ts`.
62+
63+
Managing State and interacting with a story:
64+
65+
- `src/withGlobals.ts` & `src/Tool.tsx` demonstrates how to use `useGlobals` to manage global state and modify the contents of a Story.
66+
- `src/withRoundTrip.ts` & `src/Panel.tsx` demonstrates two-way communication using channels.
67+
- `src/Tab.tsx` demonstrates how to use `useParameter` to access the current story's parameters.
68+
69+
Your addon might use one or more of these patterns. Feel free to delete unused code. Update `src/manager.ts` and `src/preview.ts` accordingly.
70+
71+
Lastly, configure you addon name in `src/constants.ts`.
72+
73+
### Bundling
74+
75+
Addons can interact with a Storybook project in multiple ways. It is recommended to familiarize yourself with [the basics](https://storybook.js.org/docs/react/addons/introduction) before getting started.
76+
77+
- Manager entries are used to add UI or behavior to the Storybook manager UI.
78+
- Preview entries are used to add UI or behavior to the preview iframe where stories are rendered.
79+
- Presets are used to modify the Storybook configuration, similar to how [users can configure their `main.ts` configurations](https://storybook.js.org/docs/react/api/main-config).
80+
81+
Since each of these places represents a different environment with different features and modules, it is also recommended to split and build your modules accordingly. This addon-kit comes with a preconfigured [bundling configuration](./tsup.config.ts) that supports this split, and you are free to modify and extend it as needed.
82+
83+
You can define which modules match which environments in the [`package.json#bundler`](./package.json) property:
84+
85+
- `exportEntries` is a list of module entries that users can manually import from anywhere they need to. For example, you could have decorators that users need to import into their `preview.ts` file or utility functions that can be used in their `main.ts` files.
86+
- `managerEntries` is a list of module entries meant only for the manager UI. These modules will be bundled to ESM and won't include types since they are mostly loaded by Storybook directly.
87+
- `previewEntries` is a list of module entries meant only for the preview UI. These modules will be bundled to ESM and won't include types since they are mostly loaded by Storybook directly.
88+
89+
Manager and preview entries are only used in the browser so they only output ESM modules. Export entries could be used both in the browser and in Node depending on their use case, so they both output ESM and CJS modules.
90+
91+
#### Globalized packages
92+
93+
Storybook provides a predefined set of packages that are available in the manager UI and the preview UI. In the final bundle of your addon, these packages should not be included. Instead, the imports should stay in place, allowing Storybook to replace those imports with the actual packages during the Storybook build process.
94+
95+
The list of packages differs between the manager and the preview, which is why there is a slight difference between `managerEntries` and `previewEntries`. Most notably, `react` and `react-dom` are prebundled in the manager but not in the preview. This means that your manager entries can use React to build UI without bundling it or having a direct reference to it. Therefore, it is safe to have React as a `devDependency` even though you are using it in production. _Requiring React as a peer dependency would unnecessarily force your users to install React._
96+
97+
An exception to this rule is if you are using React to inject UI into the preview, which does not come prebundled with React. In such cases, you need to move `react` and `react-dom` to a peer dependency. However, we generally advise against this pattern since it would limit the usage of your addon to React-based Storybooks.
98+
99+
### Metadata
100+
101+
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).
102+
103+
## Release Management
104+
105+
### Setup
106+
107+
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:
108+
109+
- [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens) Create a token with both _Read and Publish_ permissions.
110+
- [`GH_TOKEN`](https://github.com/settings/tokens) Create a token with the `repo` scope.
111+
112+
Then open your `package.json` and edit the following fields:
113+
114+
- `name`
115+
- `author`
116+
- `repository`
117+
118+
#### Local
119+
120+
To use `auto` locally create a `.env` file at the root of your project and add your tokens to it:
121+
122+
```bash
123+
GH_TOKEN=<value you just got from GitHub>
124+
NPM_TOKEN=<value you just got from npm>
125+
```
126+
127+
Lastly, **create labels on GitHub**. You’ll use these labels in the future when making changes to the package.
128+
129+
```bash
130+
npx auto create-labels
131+
```
132+
133+
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.
134+
135+
#### GitHub Actions
136+
137+
This template comes with GitHub actions already set up to publish your addon anytime someone pushes to your repository.
138+
139+
Go to `Settings > Secrets`, click `New repository secret`, and add your `NPM_TOKEN`.
140+
141+
### Creating a release
142+
143+
To create a release locally you can run the following command, otherwise the GitHub action will make the release for you.
144+
145+
```sh
146+
npm run release
147+
```
148+
149+
That will:
150+
151+
- Build and package the addon code
152+
- Bump the version
153+
- Push a release to GitHub and npm
154+
- Push a changelog to GitHub

0 commit comments

Comments
 (0)