UNPKG

5.7 kBMarkdownView Raw
1# Chromatic CLI
2
3Publishes your Storybook to Chromatic and kicks off tests if they're enabled.
4
5<img width="100%" src="https://user-images.githubusercontent.com/3070389/63930825-5abe5f00-ca54-11e9-8320-7ee949823458.gif" alt="">
6
7## Install
8
9```sh
10yarn add chromatic
11```
12
13## Usage
14
15You can use this package normally, which means installing it and adding a script called `chromatic` to your `package.json`
16
17```
18 "chromatic": "chromatic",
19```
20
21But alternatively (and this is useful for testing) you can use npx:
22
23**Use a git branch**:
24```sh
25npx -p chromaui/chromatic-cli#master chromatic --dev
26```
27
28**Use a debug version on npm**:
29```sh
30npx -p chromatic chromatic
31```
32
33Using npx has pros and cons:
34
35- đź‘Ť You'll never be out of date, you'll use the latest version every time, never have to worry about upgrading this.
36- đź‘Ť You don't need this package as a dependency, and don't need to install it during local development
37- đź‘Ž This will add a delay when you actually do want to run this, like in your CI, delaying feedback.
38
39### Usage in a github action
40
41There are examples here: [/.github/workflows](/.github/workflows).
42
43Do not run this based on a github pull_request event. If you do, the commit and branch will get reported wrong, use [https://github.com/chromaui/action](https://github.com/chromaui/action) instead.
44
45### Main options
46
47```
48--project-token="<your token>"
49```
50
51You can also use the environment variable: `CHROMATIC_PROJECT_TOKEN`
52
53### Storybook options
54
55```
56--build-script-name [name], -b The npm script that builds your Storybook [build-storybook]
57--storybook-build-dir, -d <dirname> Provide a directory with your built storybook; use if you've already built your storybook
58```
59
60Deprecated options (for tunneled builds):
61```
62--script-name [name], -s The npm script that starts your Storybook [storybook]
63--exec <command>, -e Alternatively, a full command to run to start your storybook
64--do-not-start, -S Don't attempt to start or build; use if your Storybook is already running
65
66--storybook-port <port>, -p What port is your Storybook running on (auto detected from -s, if set)
67--storybook-url <url>, -u Storybook is already running at (external) url (implies -S)'
68--storybook-https Use if Storybook is running on https (auto detected from -s, if set)
69--storybook-cert <path> Use if Storybook is running on https (auto detected from -s, if set)
70--storybook-key <path> Use if Storybook is running on https (auto detected from -s, if set)
71--storybook-ca <ca> Use if Storybook is running on https (auto detected from -s, if set)
72```
73
74These options are not required, this CLI is 0-config if you have a `build-storybook` script in your `package.json`.
75
76### Chromatic options
77
78```
79--allow-console-errors Continue running chromatic even if some stories throw an error
80--auto-accept-changes [branch] Accept any (non-error) changes or new stories for this build [only for <branch> if specified]'
81--exit-zero-on-changes [branch] Use a 0 exit code if changes are detected (i.e. don't stop the build) [only for <branch> if specified]
82--exit-once-uploaded [branch] Exit with 0 once the built version has been sent to chromatic [only for <branch> if specified]
83--ignore-last-build-on-branch [branch] Do not use the last build on this branch as a baseline if it is no longer in history (i.e. branch was rebased) [only for <branch> if specified]'
84--preserve-missing Treat missing stories as unchanged (as opposed to deleted) when comparing to the baseline'
85--no-interactive Do not prompt for package.json changes
86--only <component:story> Only run a single story or a glob-style subset of stories (for debugging purposes
87```
88
89### Debug options
90
91```
92--skip Skip chromatic tests (mark as passing)
93--list List available stories (for debugging purposes)
94--ci This build is running on CI, non-interactively (alternatively, pass CI=true)
95--debug Output more debugging information
96```
97
98### Environment variables
99
100This package will load any variables from a `.env` file if present
101
102## Issues
103
104If you encounter issues with the CLI please report them via the in-app chat (Intercom widget) or at https://github.com/chromaui/chromatic-cli/issues. Thanks!
105
106## Contributing
107
108Because of the nature of this package: it being a connector between Storybook and a web service, you may need a project token to test this locally. Just send us a message at `opensource@hichroma.com` or sign up for an account!
109
110All contributions are welcome!
111
112## Future plans:
113
114- We'd like to unify this so there's just a single package on npm.
115- Migrate to Typescript
116- Deprecate all the Storybook options in favor of a sane `--config` flag
117
118## Publishing to npm
119
120We publish with a script:
121
122```sh
123./scripts/publish.js
124```
125
126You can pass any flags to this you'd normally be able to pass to `npm publish`, such as `--dry-run` or `--tag="alpha"`.
127
128Before publishing we check if the current user has permissions and if the version isn't already on npm
129
130## Compatibility & versioning
131
132Compatibility is guaranteed between this package and Chromatic like so:
133
134- Production Chromatic ensures it’s compatible with what’s on npm
135- What's on the master branch is equal to what's published on npm
136- This package ensures it’s compatible with production Chromatic
137
138To facilitate upgrading in the future, removing and adding features, this is the process:
139
140- Any new features will have to be on Chromatic production before they could be used in this package
141- We can add feature flags to be able to test new functionality
142- Chromatic production can not remove any features this package depends on until after the usage has been removed from this package in addition to a grace period to allow users to upgrade