@circi/storybook 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +94 -2
- package/dist/index.d.mts +146 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/dist/main.mjs +71 -0
- package/dist/main.mjs.map +1 -0
- package/dist/preset.d.mts +6 -0
- package/dist/preset.mjs +9 -0
- package/dist/preset.mjs.map +1 -0
- package/dist/run-DJ7H-Q1Y.mjs +2174 -0
- package/dist/run-DJ7H-Q1Y.mjs.map +1 -0
- package/package.json +71 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Michael Ary Hazan
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,95 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @circi/storybook
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The [CirCI](https://circi.dev) addon for Storybook. It screenshots every story of a built Storybook with Playwright and uploads the PNGs to your CirCI server, where they are compared and reviewed. Each story's name in CirCI is its title and story name: `Components/Button` and `Primary` become `components/button/primary`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install --save-dev @circi/storybook playwright
|
|
7
|
+
npx playwright install chromium
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
List the addon in `.storybook/main.ts`, where its options live:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { circi } from '@circi/storybook'
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
addons: [circi({ name: 'storybook', browsers: ['chromium'], viewports: ['1280x720'] })],
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then, in CI, with `CIRCI_API_URL` and `CIRCI_TOKEN` set:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npx storybook build
|
|
24
|
+
npx circi-storybook upload --wait
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or let it build first with `--build`. Without the token, or without `CIRCI_API_URL`, the screenshots are written to `.circi/screenshots/storybook` and nothing is uploaded, as with `@circi/vitest`.
|
|
28
|
+
|
|
29
|
+
## What a screenshot is
|
|
30
|
+
|
|
31
|
+
Only the rendered component, never the empty canvas around it:
|
|
32
|
+
|
|
33
|
+
- By default the screenshot is cropped to the story's content: everything visible inside Storybook's root, with its box shadows, plus what the story renders into the page body outside the root (tooltips, menus and dialogs in portals). The `centered` and `padded` layouts add no whitespace.
|
|
34
|
+
- A story with `layout: 'fullscreen'` is page-like: the whole page, at the viewport's width and the content's full height.
|
|
35
|
+
- `parameters.circi.selector` captures one element instead, and `padding` adds pixels around the crop.
|
|
36
|
+
- A story that renders nothing (an empty or invisible root) is an error, not a blank image.
|
|
37
|
+
|
|
38
|
+
Before the screenshot the page has to be still: Storybook has reported the story rendered and its `play` function finished, fonts and images are loaded, the network is idle, and animations, transitions and the caret are off. A story that throws, or whose `play` function throws, fails and is reported with its message.
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
All of them are optional. In `circi({ … })` they are `circi.Options`; `circi-storybook upload` takes them as flags, which override the config.
|
|
43
|
+
|
|
44
|
+
| Option | Flag | Meaning |
|
|
45
|
+
| ----------------------------------------------------------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
46
|
+
| `apiUrl`, `token` | `--api-url`, `CIRCI_TOKEN` | CirCI address and project CI token. Default `CIRCI_API_URL` and `CIRCI_TOKEN`. Keep the token in the environment. |
|
|
47
|
+
| `name` | `--name` | Build name. Default `storybook`. |
|
|
48
|
+
| `dir` | `--dir` | Where captures are written, under `root`. Default `.circi/screenshots`; they go to its `storybook` folder, apart from `@circi/vitest`'s. |
|
|
49
|
+
| `clean` | `--clean` | Empty that folder first. |
|
|
50
|
+
| `root` | `--root` | Project root. Default: the working directory. |
|
|
51
|
+
| `wait` | `--wait` | Wait for the result; exit 1 when changes need review. |
|
|
52
|
+
| `strict` | `--strict` | Exit 2 if the upload fails. |
|
|
53
|
+
| `shard` | `--shard 2/4`, `--nonce` | Screenshot and upload every 4th story from the 2nd, as one shard of a parallel build. |
|
|
54
|
+
| `staticDir`, `build` | the `<dir>` argument, `--build` | The built Storybook (default `storybook-static`), and whether to run `storybook build` into it first. |
|
|
55
|
+
| `browsers` | `--browser` | `chromium` (default), `firefox`, `webkit`. |
|
|
56
|
+
| `viewports` | `--viewport` | `1280x720` (default) or `mobile=390x844`. |
|
|
57
|
+
| `concurrency` | `--concurrency` | Stories screenshotted at once. Default 4. |
|
|
58
|
+
| `include`, `exclude` | `--include`, `--exclude` | Globs over a story ID or `Title/Story name`. |
|
|
59
|
+
| `site` | `--site [name]` | Also upload the built Storybook as a hosted site, so reviewers can open the live story. |
|
|
60
|
+
| `padding`, `delay`, `timeout` | `--padding`, `--delay`, `--story-timeout` | Pixels around the crop, milliseconds to wait after render, seconds a story may take (30). |
|
|
61
|
+
|
|
62
|
+
`apiUrl`, `token`, `name`, `dir`, `clean`, `root`, `wait`, `strict` and `shard` are `@circi/vitest`'s options of the same names, with the same meanings (`CirciOptions.Common` in `@circi/cli`).
|
|
63
|
+
|
|
64
|
+
A screenshot's name gets `@<browser>` when more than one browser is configured and `@<viewport>` when more than one viewport applies: `components/button/primary@firefox@mobile`. Each PNG has a `.png.json` beside it with `{ "storyId", "browser", "viewport" }`.
|
|
65
|
+
|
|
66
|
+
If any story fails, the rest still run, every failure is listed, nothing is uploaded (a partial build would show the failed stories as removed screenshots) and the exit code is 2.
|
|
67
|
+
|
|
68
|
+
## Per story
|
|
69
|
+
|
|
70
|
+
`parameters.circi`, typed as `CirciParameters`:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import type { CirciParameters } from '@circi/storybook'
|
|
74
|
+
|
|
75
|
+
export const Open = {
|
|
76
|
+
parameters: {
|
|
77
|
+
circi: { viewports: ['390x844', 'wide=1440x900'], delay: 200 } satisfies CirciParameters,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`skip: true` leaves the story out, `viewports` replaces the configured ones for it, `delay`, `selector` and `padding` override the options. A viewport the story chose with Storybook's Viewport addon (`globals.viewport`, or `parameters.viewport.defaultViewport` in Storybook 8) is its screenshot's viewport, unless `parameters.circi.viewports` is set.
|
|
83
|
+
|
|
84
|
+
## Exit codes
|
|
85
|
+
|
|
86
|
+
0 done (with `--wait`: the build passed); 1 with `--wait`, changes need review and this job is the gate; 2 a story failed, bad flags or setup, or the upload failed with `--strict`.
|
|
87
|
+
|
|
88
|
+
## Notes
|
|
89
|
+
|
|
90
|
+
Playwright is a peer dependency: you pick its version and install its browsers, and CirCI doesn't ship a browser. Needs Node 22 or later (22.18 or later to read `.storybook/main.ts`). Tested with Storybook 10.6 (React and Vite) and Playwright 1.65 on Chromium; the other browsers and Storybook versions use the same code paths but haven't been run.
|
|
91
|
+
|
|
92
|
+
- [CirCI documentation](https://circi.dev)
|
|
93
|
+
- [Changelog](https://github.com/cir-ci/repo/blob/main/packages/storybook/CHANGELOG.md)
|
|
94
|
+
|
|
95
|
+
Licensed under the [MIT License](LICENSE), so you can add it to any project. The CirCI server it talks to is GPL-3.0-only.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
declare namespace CirciOptions {
|
|
2
|
+
/** One shard of a parallel build; the build is processed once all `total` shards arrive. */
|
|
3
|
+
interface Shard {
|
|
4
|
+
/** 0-based. */
|
|
5
|
+
index: number;
|
|
6
|
+
total: number;
|
|
7
|
+
/** Ties the shards together. Default: the CI run's ID. */
|
|
8
|
+
nonce?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The options every CirCI integration that writes screenshots and uploads them when it is done
|
|
12
|
+
* shares (`@circi/vitest`'s reporter, `@circi/storybook`'s addon): same names, same meanings,
|
|
13
|
+
* same defaults.
|
|
14
|
+
*/
|
|
15
|
+
interface Common {
|
|
16
|
+
/** CirCI address. Default: `CIRCI_API_URL`. */
|
|
17
|
+
apiUrl?: string;
|
|
18
|
+
/** Project CI token. Default: `CIRCI_TOKEN`. */
|
|
19
|
+
token?: string;
|
|
20
|
+
/** Build name; give each kind of build its own. Each integration has its own default. */
|
|
21
|
+
name?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The folder that holds the captures, relative to the project root. Default `.circi/screenshots`.
|
|
24
|
+
* Each tool writes, cleans and uploads only its own folder inside it: `<dir>/vitest`,
|
|
25
|
+
* `<dir>/storybook`, `<dir>/cypress`.
|
|
26
|
+
*/
|
|
27
|
+
dir?: string;
|
|
28
|
+
/** Empty this tool's folder in `dir` when the run starts, so a build holds only this run's captures. Default false. */
|
|
29
|
+
clean?: boolean;
|
|
30
|
+
/** Project root to look in. Default: the working directory (Vitest: the root of the run). */
|
|
31
|
+
root?: string;
|
|
32
|
+
/** Wait for the result and fail the run when changes need review. Default false. */
|
|
33
|
+
wait?: boolean;
|
|
34
|
+
/** Fail the run if the upload fails. Default false. */
|
|
35
|
+
strict?: boolean;
|
|
36
|
+
/** This process's shard, if not given on the command line. */
|
|
37
|
+
shard?: Shard;
|
|
38
|
+
log?: (line: string) => void;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
declare namespace circi$1 {
|
|
42
|
+
type Browser = 'chromium' | 'firefox' | 'webkit';
|
|
43
|
+
/** `1280x720`, `mobile=390x844`, or an object. The name labels the screenshot. */
|
|
44
|
+
type Viewport = string | {
|
|
45
|
+
name?: string;
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The addon's options, set in `.storybook/main.ts` (`addons: [circi({ … })]`) and
|
|
51
|
+
* overridden by `circi-storybook upload`'s flags. The shared ones (`apiUrl`, `token`, `name`,
|
|
52
|
+
* `dir`, `clean`, `root`, `wait`, `strict`, `shard`) mean what they do in `@circi/vitest`; `name`
|
|
53
|
+
* defaults to `storybook`, and captures are written to `<dir>/storybook`.
|
|
54
|
+
*/
|
|
55
|
+
interface Options extends CirciOptions.Common {
|
|
56
|
+
/** The built Storybook (`storybook build`), relative to the root. Default `storybook-static`. */
|
|
57
|
+
staticDir?: string;
|
|
58
|
+
/** Run `storybook build` into `staticDir` first. Default false. */
|
|
59
|
+
build?: boolean;
|
|
60
|
+
/** Default `['chromium']`. Playwright needs the browsers installed. */
|
|
61
|
+
browsers?: Browser[];
|
|
62
|
+
/** Default `['1280x720']`. A story's own `parameters.circi.viewports` or viewport wins. */
|
|
63
|
+
viewports?: Viewport[];
|
|
64
|
+
/** Stories screenshotted at once, per browser. Default 4. */
|
|
65
|
+
concurrency?: number;
|
|
66
|
+
/** Globs over a story's ID or `Title/Story name`; only matching stories are screenshotted. */
|
|
67
|
+
include?: string[];
|
|
68
|
+
/** Globs, same form; matching stories are left out. */
|
|
69
|
+
exclude?: string[];
|
|
70
|
+
/** Also upload the built Storybook as a hosted site (named `storybook`, or the given name). Default false. */
|
|
71
|
+
site?: boolean | {
|
|
72
|
+
name?: string;
|
|
73
|
+
};
|
|
74
|
+
/** Pixels of the page around the component to include. Default 0. */
|
|
75
|
+
padding?: number;
|
|
76
|
+
/** Milliseconds to wait after a story has rendered, before the screenshot. Default 0. */
|
|
77
|
+
delay?: number;
|
|
78
|
+
/** Seconds a story may take to render. Default 30. */
|
|
79
|
+
timeout?: number;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** A story's `parameters.circi`. */
|
|
83
|
+
interface CirciParameters {
|
|
84
|
+
/** Don't screenshot this story. */
|
|
85
|
+
skip?: boolean;
|
|
86
|
+
/** Screenshot at each of these instead of the configured viewports. */
|
|
87
|
+
viewports?: circi$1.Viewport[];
|
|
88
|
+
/** Milliseconds to wait after the story has rendered. */
|
|
89
|
+
delay?: number;
|
|
90
|
+
/** Screenshot this element (a CSS selector) instead of the whole component. */
|
|
91
|
+
selector?: string;
|
|
92
|
+
/** Pixels around the component or element to include. */
|
|
93
|
+
padding?: number;
|
|
94
|
+
}
|
|
95
|
+
export declare namespace uploadStorybook {
|
|
96
|
+
interface Options extends circi$1.Options {
|
|
97
|
+
/** Storybook's config folder, relative to the root. Default `.storybook`. */
|
|
98
|
+
configDir?: string;
|
|
99
|
+
/** How long `wait` waits for the build, in seconds. Default 600. */
|
|
100
|
+
waitTimeout?: number;
|
|
101
|
+
/** Allow `git fetch` to complete shallow history. Default true. */
|
|
102
|
+
fetch?: boolean;
|
|
103
|
+
cwd?: string;
|
|
104
|
+
env?: Record<string, string | undefined>;
|
|
105
|
+
}
|
|
106
|
+
interface Failure {
|
|
107
|
+
storyId: string;
|
|
108
|
+
browser: string;
|
|
109
|
+
reason: string;
|
|
110
|
+
}
|
|
111
|
+
interface Result {
|
|
112
|
+
/** 0 done, 1 changes need review (with `wait`), 2 a story failed or something went wrong. */
|
|
113
|
+
exitCode: 0 | 1 | 2;
|
|
114
|
+
/** Screenshots written. */
|
|
115
|
+
screenshots: number;
|
|
116
|
+
/** Stories left out by `parameters.circi.skip`, `include`, `exclude` or another shard. */
|
|
117
|
+
skipped: number;
|
|
118
|
+
failures: Failure[];
|
|
119
|
+
uploaded: boolean;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Screenshots every story of a built Storybook and uploads the PNGs to CirCI. Options come from the
|
|
124
|
+
* addon's entry in `.storybook/main`, overridden by `flags`. A story that fails is reported and the
|
|
125
|
+
* rest still run; a run with a failed story uploads nothing, since the story would show up in CirCI
|
|
126
|
+
* as a removed screenshot, and exits 2.
|
|
127
|
+
*/
|
|
128
|
+
export declare function uploadStorybook(flags?: uploadStorybook.Options): Promise<uploadStorybook.Result>;
|
|
129
|
+
/**
|
|
130
|
+
* The CirCI addon for Storybook: list it in `.storybook/main.ts`, where its options live. The
|
|
131
|
+
* `circi-storybook upload` command reads them from there; flags override them.
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* addons: [circi({ name: 'storybook', browsers: ['chromium'] })]
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function circi(options?: circi$1.Options): {
|
|
138
|
+
name: string;
|
|
139
|
+
options: circi$1.Options;
|
|
140
|
+
};
|
|
141
|
+
export declare namespace circi {
|
|
142
|
+
type Options = circi$1.Options;
|
|
143
|
+
type Browser = circi$1.Browser;
|
|
144
|
+
type Viewport = circi$1.Viewport;
|
|
145
|
+
}
|
|
146
|
+
export type { CirciParameters };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as uploadStorybook } from "./run-DJ7H-Q1Y.mjs";
|
|
2
|
+
// src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* The CirCI addon for Storybook: list it in `.storybook/main.ts`, where its options live. The
|
|
5
|
+
* `circi-storybook upload` command reads them from there; flags override them.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* addons: [circi({ name: 'storybook', browsers: ['chromium'] })]
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
function circi(options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
name: "@circi/storybook",
|
|
14
|
+
options
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export { circi, uploadStorybook };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { circi as Types } from './types.ts'\n\nexport type { CirciParameters } from './types.ts'\nexport { uploadStorybook } from './run.ts'\n\n/**\n * The CirCI addon for Storybook: list it in `.storybook/main.ts`, where its options live. The\n * `circi-storybook upload` command reads them from there; flags override them.\n *\n * ```ts\n * addons: [circi({ name: 'storybook', browsers: ['chromium'] })]\n * ```\n */\nexport function circi(options: Types.Options = {}): {\n name: string\n options: Types.Options\n} {\n return { name: '@circi/storybook', options }\n}\n\nexport namespace circi {\n export type Options = Types.Options\n export type Browser = Types.Browser\n export type Viewport = Types.Viewport\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,MAAM,UAAyB,CAAC,GAG9C;CACA,OAAO;EAAE,MAAM;EAAoB;CAAQ;AAC7C"}
|
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as reportError, i as ignoreBrokenPipe, n as UsageError, o as shardFlag, r as debugOn, t as uploadStorybook } from "./run-DJ7H-Q1Y.mjs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
// package.json
|
|
5
|
+
var version = "0.1.1";
|
|
6
|
+
// src/main.ts
|
|
7
|
+
ignoreBrokenPipe();
|
|
8
|
+
const program = new Command().name("circi-storybook").description("Screenshot every Storybook story and upload the screenshots to CirCI").version(version).option("--debug", "print the stack trace of an unexpected error (or set DEBUG=1)").showHelpAfterError();
|
|
9
|
+
function collect(value, previous = []) {
|
|
10
|
+
return [...previous, ...value.split(",").filter((part) => part !== "")];
|
|
11
|
+
}
|
|
12
|
+
function numberFlag(text, flag) {
|
|
13
|
+
if (text === void 0) return void 0;
|
|
14
|
+
const n = Number(text);
|
|
15
|
+
if (!Number.isFinite(n)) throw new UsageError(`${flag} must be a number`);
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
program.command("upload").description("screenshot the stories of a built Storybook and upload them as a build").argument("[dir]", "the built Storybook (default: staticDir of the addon, or storybook-static)").option("--build", "run `storybook build` into the folder first").option("--root <dir>", "project root (default: the working directory)").option("--config-dir <dir>", "Storybook's config folder, where the addon's options are read", ".storybook").option("--dir <dir>", "where screenshots are written, under the root (default: .circi/screenshots)").option("--name <name>", "build name (default: storybook)").option("--clean", "empty the screenshots folder first").option("--browser <name>", "chromium, firefox or webkit; repeat or comma-separate", collect).option("--viewport <size>", "such as 1280x720 or mobile=390x844; repeat or comma-separate", collect).option("--concurrency <n>", "stories screenshotted at once (default: 4)").option("--include <glob>", "only stories matching a story ID or Title/Story name; repeatable", collect).option("--exclude <glob>", "leave out matching stories; repeatable", collect).option("--site [name]", "also upload the built Storybook as a hosted site (default name: storybook)").option("--padding <px>", "pixels around the component to include (default: 0)").option("--delay <ms>", "wait after a story has rendered (default: 0)").option("--story-timeout <seconds>", "how long a story may take to render (default: 30)").option("--wait", "wait for the result and exit 1 when changes need review").option("--strict", "exit 2 if the upload fails").option("--shard <n/total>", "screenshot and upload shard n of total (e.g. 2/4) of one parallel build").option("--nonce <id>", "ties the shards of one build together (default: the CI run ID)").option("--timeout <seconds>", "how long --wait waits", "600").option("--api-url <url>", "CirCI address (default: CIRCI_API_URL)").option("--no-fetch", "don't run git fetch to complete shallow history").addHelpText("after", `
|
|
19
|
+
Options can also be set once, in .storybook/main.ts: addons: [circi({ browsers: ['chromium'] })].
|
|
20
|
+
Flags override them. A story's own settings are parameters.circi (skip, viewports, delay, selector, padding).
|
|
21
|
+
|
|
22
|
+
Environment:
|
|
23
|
+
CIRCI_TOKEN project CI token
|
|
24
|
+
CIRCI_API_URL CirCI address, e.g. https://ci.acme.io
|
|
25
|
+
Without both, the screenshots are written and not uploaded.
|
|
26
|
+
|
|
27
|
+
Exit codes:
|
|
28
|
+
0 done; with --wait also: the build passed (or the git host's check is the gate)
|
|
29
|
+
1 with --wait: visual changes need review and this job is the gate
|
|
30
|
+
2 a story couldn't be screenshotted (nothing is uploaded), bad flags or setup, or
|
|
31
|
+
the upload failed with --strict`).action(async (dir, flags) => {
|
|
32
|
+
const shard = flags.shard ? shardFlag(flags.shard, flags.nonce) : void 0;
|
|
33
|
+
const timeout = numberFlag(flags.timeout, "--timeout");
|
|
34
|
+
const options = {
|
|
35
|
+
staticDir: dir,
|
|
36
|
+
build: flags.build,
|
|
37
|
+
root: flags.root,
|
|
38
|
+
configDir: flags.configDir,
|
|
39
|
+
dir: flags.dir,
|
|
40
|
+
name: flags.name,
|
|
41
|
+
clean: flags.clean,
|
|
42
|
+
browsers: flags.browser?.map(browserFlag),
|
|
43
|
+
viewports: flags.viewport,
|
|
44
|
+
concurrency: numberFlag(flags.concurrency, "--concurrency"),
|
|
45
|
+
include: flags.include,
|
|
46
|
+
exclude: flags.exclude,
|
|
47
|
+
site: flags.site ? typeof flags.site === "string" ? { name: flags.site } : true : void 0,
|
|
48
|
+
padding: numberFlag(flags.padding, "--padding"),
|
|
49
|
+
delay: numberFlag(flags.delay, "--delay"),
|
|
50
|
+
timeout: numberFlag(flags.storyTimeout, "--story-timeout"),
|
|
51
|
+
wait: flags.wait,
|
|
52
|
+
strict: flags.strict,
|
|
53
|
+
shard,
|
|
54
|
+
apiUrl: flags.apiUrl,
|
|
55
|
+
waitTimeout: timeout,
|
|
56
|
+
fetch: flags.fetch
|
|
57
|
+
};
|
|
58
|
+
const result = await uploadStorybook(options);
|
|
59
|
+
process.exitCode = result.exitCode;
|
|
60
|
+
});
|
|
61
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
62
|
+
console.error(reportError(err, debugOn(process.argv, process.env)));
|
|
63
|
+
process.exitCode = 2;
|
|
64
|
+
});
|
|
65
|
+
function browserFlag(name) {
|
|
66
|
+
if (name === "chromium" || name === "firefox" || name === "webkit") return name;
|
|
67
|
+
throw new UsageError(`Unknown browser "${name}": use chromium, firefox or webkit`);
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=main.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.mjs","names":["pkg.version"],"sources":["../package.json","../src/main.ts"],"sourcesContent":["","#!/usr/bin/env node\nimport { debugOn, ignoreBrokenPipe, reportError, shardFlag, UsageError } from '@circi/cli'\nimport { Command } from 'commander'\n\nimport pkg from '../package.json' with { type: 'json' }\nimport { uploadStorybook } from './run.ts'\nimport type { circi } from './types.ts'\n\nignoreBrokenPipe()\n\nconst program = new Command()\n .name('circi-storybook')\n .description('Screenshot every Storybook story and upload the screenshots to CirCI')\n .version(pkg.version)\n .option('--debug', 'print the stack trace of an unexpected error (or set DEBUG=1)')\n .showHelpAfterError()\n\ninterface Flags {\n build?: boolean\n root?: string\n configDir?: string\n dir?: string\n name?: string\n clean?: boolean\n browser?: string[]\n viewport?: string[]\n concurrency?: string\n include?: string[]\n exclude?: string[]\n site?: string | boolean\n padding?: string\n delay?: string\n storyTimeout?: string\n wait?: boolean\n strict?: boolean\n shard?: string\n nonce?: string\n timeout?: string\n apiUrl?: string\n fetch: boolean\n}\n\nfunction collect(value: string, previous: string[] = []): string[] {\n return [...previous, ...value.split(',').filter((part) => part !== '')]\n}\n\nfunction numberFlag(text: string | undefined, flag: string): number | undefined {\n if (text === undefined) return undefined\n const n = Number(text)\n if (!Number.isFinite(n)) throw new UsageError(`${flag} must be a number`)\n return n\n}\n\nprogram\n .command('upload')\n .description('screenshot the stories of a built Storybook and upload them as a build')\n .argument('[dir]', 'the built Storybook (default: staticDir of the addon, or storybook-static)')\n .option('--build', 'run `storybook build` into the folder first')\n .option('--root <dir>', 'project root (default: the working directory)')\n .option(\n '--config-dir <dir>',\n \"Storybook's config folder, where the addon's options are read\",\n '.storybook',\n )\n .option(\n '--dir <dir>',\n 'where screenshots are written, under the root (default: .circi/screenshots)',\n )\n .option('--name <name>', 'build name (default: storybook)')\n .option('--clean', 'empty the screenshots folder first')\n .option('--browser <name>', 'chromium, firefox or webkit; repeat or comma-separate', collect)\n .option(\n '--viewport <size>',\n 'such as 1280x720 or mobile=390x844; repeat or comma-separate',\n collect,\n )\n .option('--concurrency <n>', 'stories screenshotted at once (default: 4)')\n .option(\n '--include <glob>',\n 'only stories matching a story ID or Title/Story name; repeatable',\n collect,\n )\n .option('--exclude <glob>', 'leave out matching stories; repeatable', collect)\n .option(\n '--site [name]',\n 'also upload the built Storybook as a hosted site (default name: storybook)',\n )\n .option('--padding <px>', 'pixels around the component to include (default: 0)')\n .option('--delay <ms>', 'wait after a story has rendered (default: 0)')\n .option('--story-timeout <seconds>', 'how long a story may take to render (default: 30)')\n .option('--wait', 'wait for the result and exit 1 when changes need review')\n .option('--strict', 'exit 2 if the upload fails')\n .option(\n '--shard <n/total>',\n 'screenshot and upload shard n of total (e.g. 2/4) of one parallel build',\n )\n .option('--nonce <id>', 'ties the shards of one build together (default: the CI run ID)')\n .option('--timeout <seconds>', 'how long --wait waits', '600')\n .option('--api-url <url>', 'CirCI address (default: CIRCI_API_URL)')\n .option('--no-fetch', \"don't run git fetch to complete shallow history\")\n .addHelpText(\n 'after',\n `\nOptions can also be set once, in .storybook/main.ts: addons: [circi({ browsers: ['chromium'] })].\nFlags override them. A story's own settings are parameters.circi (skip, viewports, delay, selector, padding).\n\nEnvironment:\n CIRCI_TOKEN project CI token\n CIRCI_API_URL CirCI address, e.g. https://ci.acme.io\n Without both, the screenshots are written and not uploaded.\n\nExit codes:\n 0 done; with --wait also: the build passed (or the git host's check is the gate)\n 1 with --wait: visual changes need review and this job is the gate\n 2 a story couldn't be screenshotted (nothing is uploaded), bad flags or setup, or\n the upload failed with --strict`,\n )\n .action(async (dir: string | undefined, flags: Flags) => {\n const shard = flags.shard ? shardFlag(flags.shard, flags.nonce) : undefined\n const timeout = numberFlag(flags.timeout, '--timeout')\n const options: uploadStorybook.Options = {\n staticDir: dir,\n build: flags.build,\n root: flags.root,\n configDir: flags.configDir,\n dir: flags.dir,\n name: flags.name,\n clean: flags.clean,\n browsers: flags.browser?.map(browserFlag),\n viewports: flags.viewport,\n concurrency: numberFlag(flags.concurrency, '--concurrency'),\n include: flags.include,\n exclude: flags.exclude,\n site: flags.site ? (typeof flags.site === 'string' ? { name: flags.site } : true) : undefined,\n padding: numberFlag(flags.padding, '--padding'),\n delay: numberFlag(flags.delay, '--delay'),\n timeout: numberFlag(flags.storyTimeout, '--story-timeout'),\n wait: flags.wait,\n strict: flags.strict,\n shard,\n apiUrl: flags.apiUrl,\n waitTimeout: timeout,\n fetch: flags.fetch,\n }\n const result = await uploadStorybook(options)\n process.exitCode = result.exitCode\n })\n\nprogram.parseAsync(process.argv).catch((err: unknown) => {\n console.error(reportError(err, debugOn(process.argv, process.env)))\n process.exitCode = 2\n})\n\nfunction browserFlag(name: string): circi.Browser {\n if (name === 'chromium' || name === 'firefox' || name === 'webkit') return name\n throw new UsageError(`Unknown browser \"${name}\": use chromium, firefox or webkit`)\n}\n"],"mappings":"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"}
|
package/dist/preset.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/preset.ts
|
|
2
|
+
/**
|
|
3
|
+
* Storybook loads this when `@circi/storybook` is listed in `addons`. The addon changes nothing in
|
|
4
|
+
* Storybook itself: its options are read from the same entry by `circi-storybook upload`.
|
|
5
|
+
*/
|
|
6
|
+
var preset_default = {};
|
|
7
|
+
export { preset_default as default };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=preset.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.mjs","names":[],"sources":["../src/preset.ts"],"sourcesContent":["/**\n * Storybook loads this when `@circi/storybook` is listed in `addons`. The addon changes nothing in\n * Storybook itself: its options are read from the same entry by `circi-storybook upload`.\n */\nexport default {}\n"],"mappings":";;;;;AAIA,IAAA,iBAAe,CAAC"}
|