@cappa/plugin-storybook 0.2.5 → 0.3.0
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/.turbo/turbo-build.log +43 -39
- package/CHANGELOG.md +14 -0
- package/dist/{index.mjs → index.cjs} +65 -19
- package/dist/{index.d.mts → index.esm.d.ts} +29 -1
- package/dist/index.js +33 -51
- package/package.json +23 -13
- package/src/cappa/plugin.test.ts +380 -0
- package/src/cappa/plugin.ts +69 -11
- package/src/{index.ts → index.cjs.ts} +2 -3
- package/src/index.esm.ts +7 -0
- package/tsup.config.ts +12 -4
- package/dist/index.d.ts +0 -53
- /package/dist/{browser.mjs → browser.js} +0 -0
- /package/dist/{preview.mjs → preview.js} +0 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m
|
|
7
|
-
[34mCLI[39m
|
|
8
|
-
[34mCLI[39m
|
|
9
|
-
[34mCLI[39m
|
|
10
|
-
[34mCLI[39m
|
|
11
|
-
[34mCLI[39m
|
|
12
|
-
[34mCLI[39m tsup
|
|
13
|
-
[34mCLI[39m
|
|
14
|
-
[34mCLI[39m
|
|
15
|
-
[34mCLI[39m
|
|
16
|
-
[34mCLI[39m tsup
|
|
17
|
-
[34mCLI[39m
|
|
18
|
-
[34mCLI[39m
|
|
19
|
-
[34mCLI[39m
|
|
20
|
-
[34mCLI[39m
|
|
21
|
-
[34mCLI[39m
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[34mCLI[39m
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[32mESM[39m
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
|
|
2
|
+
> @cappa/plugin-storybook@0.3.0 build /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: {"index":"src/index.esm.ts"}
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m Building entry: {"index":"src/index.cjs.ts"}
|
|
8
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
9
|
+
[34mCLI[39m tsup v8.5.0
|
|
10
|
+
[34mCLI[39m Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
11
|
+
[34mCLI[39m tsup v8.5.0
|
|
12
|
+
[34mCLI[39m Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
13
|
+
[34mCLI[39m Building entry: src/storybook/addon/preview.ts
|
|
14
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
15
|
+
[34mCLI[39m tsup v8.5.0
|
|
16
|
+
[34mCLI[39m Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
17
|
+
[34mCLI[39m Building entry: src/storybook/addon/browser.ts
|
|
18
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
19
|
+
[34mCLI[39m tsup v8.5.0
|
|
20
|
+
[34mCLI[39m Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
21
|
+
[34mCLI[39m Target: esnext
|
|
22
|
+
[34mCLI[39m Target: esnext
|
|
23
|
+
[34mCLI[39m Target: node16
|
|
24
|
+
[34mCLI[39m Target: es2015
|
|
25
|
+
[34mCLI[39m Cleaning output folder
|
|
26
|
+
[34mESM[39m Build start
|
|
27
|
+
[34mCLI[39m Cleaning output folder
|
|
28
|
+
[34mCJS[39m Build start
|
|
29
|
+
[34mCLI[39m Cleaning output folder
|
|
30
|
+
[34mESM[39m Build start
|
|
31
|
+
[34mCLI[39m Cleaning output folder
|
|
32
|
+
[34mESM[39m Build start
|
|
33
|
+
[32mESM[39m [1mdist/browser.js [22m[32m138.00 B[39m
|
|
34
|
+
[32mESM[39m ⚡️ Build success in 52ms
|
|
35
|
+
[32mESM[39m [1mdist/preview.js [22m[32m1.41 KB[39m
|
|
36
|
+
[32mESM[39m ⚡️ Build success in 55ms
|
|
37
|
+
[32mESM[39m [1mdist/index.js [22m[32m12.25 KB[39m
|
|
38
|
+
[32mESM[39m ⚡️ Build success in 72ms
|
|
39
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m13.98 KB[39m
|
|
40
|
+
[32mCJS[39m ⚡️ Build success in 74ms
|
|
41
|
+
[34mDTS[39m Build start
|
|
42
|
+
[32mDTS[39m ⚡️ Build success in 3817ms
|
|
43
|
+
[32mDTS[39m [1mdist/index.esm.d.ts [22m[32m2.63 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @cappa/plugin-storybook
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 78c4e4c: feat: support storybook 10
|
|
8
|
+
|
|
9
|
+
## 0.2.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 80b44af: feat: add glob pattern for storybook include/exclude options
|
|
14
|
+
- Updated dependencies [e0f7f08]
|
|
15
|
+
- @cappa/core@0.3.0
|
|
16
|
+
|
|
3
17
|
## 0.2.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,12 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.cjs.ts
|
|
31
|
+
var index_cjs_exports = {};
|
|
32
|
+
__export(index_cjs_exports, {
|
|
33
|
+
cappaPluginStorybook: () => cappaPluginStorybook,
|
|
34
|
+
previewAnnotations: () => previewAnnotations
|
|
6
35
|
});
|
|
36
|
+
module.exports = __toCommonJS(index_cjs_exports);
|
|
7
37
|
|
|
8
38
|
// src/cappa/plugin.ts
|
|
9
|
-
|
|
39
|
+
var import_logger = require("@cappa/logger");
|
|
40
|
+
var import_minimatch = require("minimatch");
|
|
10
41
|
|
|
11
42
|
// src/cappa/storybook-url.ts
|
|
12
43
|
function encodePairs(obj) {
|
|
@@ -120,7 +151,7 @@ var buildFilename = (story) => {
|
|
|
120
151
|
|
|
121
152
|
// src/cappa/plugin.ts
|
|
122
153
|
async function waitForPlayFunctionCompletion(page, storyName) {
|
|
123
|
-
const logger = getLogger();
|
|
154
|
+
const logger = (0, import_logger.getLogger)();
|
|
124
155
|
try {
|
|
125
156
|
const hasPlayFunction = await page.evaluate(
|
|
126
157
|
() => window.__cappa_has_play_function === true
|
|
@@ -146,6 +177,24 @@ async function waitForPlayFunctionCompletion(page, storyName) {
|
|
|
146
177
|
});
|
|
147
178
|
}
|
|
148
179
|
}
|
|
180
|
+
function matchesGlobPatterns(story, patterns) {
|
|
181
|
+
return patterns.some((pattern) => {
|
|
182
|
+
if ((0, import_minimatch.minimatch)(story.id, pattern)) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if ((0, import_minimatch.minimatch)(story.title, pattern)) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
if ((0, import_minimatch.minimatch)(story.name, pattern)) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
const fullPath = `${story.title}/${story.name}`;
|
|
192
|
+
if ((0, import_minimatch.minimatch)(fullPath, pattern)) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
149
198
|
function createLatch() {
|
|
150
199
|
let resolve;
|
|
151
200
|
const p = new Promise((r) => resolve = r);
|
|
@@ -162,7 +211,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
162
211
|
if (!options.storybookUrl) {
|
|
163
212
|
throw new Error("storybookUrl is required");
|
|
164
213
|
}
|
|
165
|
-
const logger = getLogger();
|
|
214
|
+
const logger = (0, import_logger.getLogger)();
|
|
166
215
|
const {
|
|
167
216
|
storybookUrl,
|
|
168
217
|
includeStories = [],
|
|
@@ -182,16 +231,12 @@ var cappaPluginStorybook = (options) => {
|
|
|
182
231
|
let filteredStories = stories;
|
|
183
232
|
if (includeStories.length > 0) {
|
|
184
233
|
filteredStories = filteredStories.filter(
|
|
185
|
-
(story) => includeStories
|
|
186
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
187
|
-
)
|
|
234
|
+
(story) => matchesGlobPatterns(story, includeStories)
|
|
188
235
|
);
|
|
189
236
|
}
|
|
190
237
|
if (excludeStories.length > 0) {
|
|
191
238
|
filteredStories = filteredStories.filter(
|
|
192
|
-
(story) => !excludeStories
|
|
193
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
194
|
-
)
|
|
239
|
+
(story) => !matchesGlobPatterns(story, excludeStories)
|
|
195
240
|
);
|
|
196
241
|
}
|
|
197
242
|
filteredStories = filteredStories.filter(
|
|
@@ -224,7 +269,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
224
269
|
execute: async (task, page, screenshotTool, context) => {
|
|
225
270
|
const { url, data } = task;
|
|
226
271
|
const { story } = data;
|
|
227
|
-
const logger = getLogger();
|
|
272
|
+
const logger = (0, import_logger.getLogger)();
|
|
228
273
|
const { storybook: defaultStorybookOptions } = options || {};
|
|
229
274
|
try {
|
|
230
275
|
const currentLatch = createLatch();
|
|
@@ -360,9 +405,10 @@ var cappaPluginStorybook = (options) => {
|
|
|
360
405
|
};
|
|
361
406
|
};
|
|
362
407
|
|
|
363
|
-
// src/index.ts
|
|
364
|
-
var previewAnnotations = [
|
|
365
|
-
export
|
|
408
|
+
// src/index.cjs.ts
|
|
409
|
+
var previewAnnotations = [require.resolve("./preview.js")];
|
|
410
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
411
|
+
0 && (module.exports = {
|
|
366
412
|
cappaPluginStorybook,
|
|
367
413
|
previewAnnotations
|
|
368
|
-
};
|
|
414
|
+
});
|
|
@@ -32,7 +32,34 @@ interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook
|
|
|
32
32
|
|
|
33
33
|
interface StorybookPluginOptions {
|
|
34
34
|
storybookUrl: string;
|
|
35
|
+
/**
|
|
36
|
+
* Array of glob patterns to include stories. Stories matching any of these patterns will be included.
|
|
37
|
+
* Patterns can match against:
|
|
38
|
+
* - Story ID (e.g., "button--primary")
|
|
39
|
+
* - Story title (e.g., "Button")
|
|
40
|
+
* - Story name (e.g., "Primary")
|
|
41
|
+
* - Full story path (e.g., "Button/Primary")
|
|
42
|
+
*
|
|
43
|
+
* Examples:
|
|
44
|
+
* - ["button--*"] - Include all button stories
|
|
45
|
+
* - ["*--primary"] - Include all primary stories
|
|
46
|
+
* - ["Button/*"] - Include all stories under Button title
|
|
47
|
+
* - ["*--*"] - Include all stories
|
|
48
|
+
*/
|
|
35
49
|
includeStories?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
|
|
52
|
+
* Patterns can match against:
|
|
53
|
+
* - Story ID (e.g., "button--primary")
|
|
54
|
+
* - Story title (e.g., "Button")
|
|
55
|
+
* - Story name (e.g., "Primary")
|
|
56
|
+
* - Full story path (e.g., "Button/Primary")
|
|
57
|
+
*
|
|
58
|
+
* Examples:
|
|
59
|
+
* - ["button--*"] - Exclude all button stories
|
|
60
|
+
* - ["*--secondary"] - Exclude all secondary stories
|
|
61
|
+
* - ["Input/*"] - Exclude all stories under Input title
|
|
62
|
+
*/
|
|
36
63
|
excludeStories?: string[];
|
|
37
64
|
defaultViewport?: {
|
|
38
65
|
width: number;
|
|
@@ -44,7 +71,8 @@ interface StorybookPluginOptions {
|
|
|
44
71
|
}
|
|
45
72
|
/**
|
|
46
73
|
* Storybook Plugin for Cappa
|
|
47
|
-
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
74
|
+
* Fetches stories from a running Storybook server and takes screenshots of each story.
|
|
75
|
+
* Supports glob pattern matching for includeStories and excludeStories options.
|
|
48
76
|
*/
|
|
49
77
|
declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
50
78
|
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
cappaPluginStorybook: () => cappaPluginStorybook,
|
|
34
|
-
previewAnnotations: () => previewAnnotations
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
// src/index.esm.ts
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
37
3
|
|
|
38
4
|
// src/cappa/plugin.ts
|
|
39
|
-
|
|
5
|
+
import { getLogger } from "@cappa/logger";
|
|
6
|
+
import { minimatch } from "minimatch";
|
|
40
7
|
|
|
41
8
|
// src/cappa/storybook-url.ts
|
|
42
9
|
function encodePairs(obj) {
|
|
@@ -150,7 +117,7 @@ var buildFilename = (story) => {
|
|
|
150
117
|
|
|
151
118
|
// src/cappa/plugin.ts
|
|
152
119
|
async function waitForPlayFunctionCompletion(page, storyName) {
|
|
153
|
-
const logger =
|
|
120
|
+
const logger = getLogger();
|
|
154
121
|
try {
|
|
155
122
|
const hasPlayFunction = await page.evaluate(
|
|
156
123
|
() => window.__cappa_has_play_function === true
|
|
@@ -176,6 +143,24 @@ async function waitForPlayFunctionCompletion(page, storyName) {
|
|
|
176
143
|
});
|
|
177
144
|
}
|
|
178
145
|
}
|
|
146
|
+
function matchesGlobPatterns(story, patterns) {
|
|
147
|
+
return patterns.some((pattern) => {
|
|
148
|
+
if (minimatch(story.id, pattern)) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if (minimatch(story.title, pattern)) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
if (minimatch(story.name, pattern)) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
const fullPath = `${story.title}/${story.name}`;
|
|
158
|
+
if (minimatch(fullPath, pattern)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
179
164
|
function createLatch() {
|
|
180
165
|
let resolve;
|
|
181
166
|
const p = new Promise((r) => resolve = r);
|
|
@@ -192,7 +177,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
192
177
|
if (!options.storybookUrl) {
|
|
193
178
|
throw new Error("storybookUrl is required");
|
|
194
179
|
}
|
|
195
|
-
const logger =
|
|
180
|
+
const logger = getLogger();
|
|
196
181
|
const {
|
|
197
182
|
storybookUrl,
|
|
198
183
|
includeStories = [],
|
|
@@ -212,16 +197,12 @@ var cappaPluginStorybook = (options) => {
|
|
|
212
197
|
let filteredStories = stories;
|
|
213
198
|
if (includeStories.length > 0) {
|
|
214
199
|
filteredStories = filteredStories.filter(
|
|
215
|
-
(story) => includeStories
|
|
216
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
217
|
-
)
|
|
200
|
+
(story) => matchesGlobPatterns(story, includeStories)
|
|
218
201
|
);
|
|
219
202
|
}
|
|
220
203
|
if (excludeStories.length > 0) {
|
|
221
204
|
filteredStories = filteredStories.filter(
|
|
222
|
-
(story) => !excludeStories
|
|
223
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
224
|
-
)
|
|
205
|
+
(story) => !matchesGlobPatterns(story, excludeStories)
|
|
225
206
|
);
|
|
226
207
|
}
|
|
227
208
|
filteredStories = filteredStories.filter(
|
|
@@ -254,7 +235,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
254
235
|
execute: async (task, page, screenshotTool, context) => {
|
|
255
236
|
const { url, data } = task;
|
|
256
237
|
const { story } = data;
|
|
257
|
-
const logger =
|
|
238
|
+
const logger = getLogger();
|
|
258
239
|
const { storybook: defaultStorybookOptions } = options || {};
|
|
259
240
|
try {
|
|
260
241
|
const currentLatch = createLatch();
|
|
@@ -390,10 +371,11 @@ var cappaPluginStorybook = (options) => {
|
|
|
390
371
|
};
|
|
391
372
|
};
|
|
392
373
|
|
|
393
|
-
// src/index.ts
|
|
394
|
-
var previewAnnotations = [
|
|
395
|
-
|
|
396
|
-
|
|
374
|
+
// src/index.esm.ts
|
|
375
|
+
var previewAnnotations = [
|
|
376
|
+
fileURLToPath(new URL("./preview.js", import.meta.url))
|
|
377
|
+
];
|
|
378
|
+
export {
|
|
397
379
|
cappaPluginStorybook,
|
|
398
380
|
previewAnnotations
|
|
399
|
-
}
|
|
381
|
+
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"module": "CommonJS",
|
|
11
8
|
"license": "MIT",
|
|
12
9
|
"author": "Tim Richter",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
15
|
-
"
|
|
16
|
-
"require": "./dist/index.
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"require": "./dist/index.cjs",
|
|
18
|
+
"import": "./dist/index.js"
|
|
17
19
|
},
|
|
18
20
|
"./browser": {
|
|
19
|
-
"
|
|
20
|
-
"require": "./dist/browser.mjs"
|
|
21
|
+
"default": "./dist/browser.js"
|
|
21
22
|
},
|
|
22
23
|
"./package.json": "./package.json"
|
|
23
24
|
},
|
|
@@ -27,20 +28,29 @@
|
|
|
27
28
|
"storybook",
|
|
28
29
|
"visual-testing"
|
|
29
30
|
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"storybook": "^9 || ^10"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"storybook": {
|
|
36
|
+
"optional": false
|
|
37
|
+
}
|
|
38
|
+
},
|
|
30
39
|
"dependencies": {
|
|
31
|
-
"@swc/core": "^1.
|
|
40
|
+
"@swc/core": "^1.14.0",
|
|
32
41
|
"chalk": "^5.6.2",
|
|
33
|
-
"
|
|
34
|
-
"@cappa/core": "0.
|
|
42
|
+
"minimatch": "^10.1.1",
|
|
43
|
+
"@cappa/core": "0.3.0",
|
|
35
44
|
"@cappa/logger": "0.0.4"
|
|
36
45
|
},
|
|
37
46
|
"devDependencies": {
|
|
38
47
|
"@vitest/coverage-v8": "3.2.4",
|
|
39
48
|
"@vitest/ui": "3.2.4",
|
|
40
|
-
"playwright-core": "^1.56.
|
|
49
|
+
"playwright-core": "^1.56.1",
|
|
41
50
|
"tsup": "8.5.0",
|
|
42
51
|
"typescript": "5.9.3",
|
|
43
|
-
"vitest": "3.2.4"
|
|
52
|
+
"vitest": "3.2.4",
|
|
53
|
+
"storybook": "^10.0.2"
|
|
44
54
|
},
|
|
45
55
|
"scripts": {
|
|
46
56
|
"test": "vitest",
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { cappaPluginStorybook, type StorybookStory } from "./plugin";
|
|
3
|
+
|
|
4
|
+
// Mock the logger
|
|
5
|
+
vi.mock("@cappa/logger", () => ({
|
|
6
|
+
getLogger: () => ({
|
|
7
|
+
debug: vi.fn(),
|
|
8
|
+
start: vi.fn(),
|
|
9
|
+
warn: vi.fn(),
|
|
10
|
+
error: vi.fn(),
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
// Mock fetch
|
|
15
|
+
global.fetch = vi.fn();
|
|
16
|
+
|
|
17
|
+
describe("cappaPluginStorybook - Glob Pattern Matching", () => {
|
|
18
|
+
const mockStories: StorybookStory[] = [
|
|
19
|
+
{
|
|
20
|
+
id: "button--primary",
|
|
21
|
+
name: "Primary",
|
|
22
|
+
title: "Button",
|
|
23
|
+
kind: "Button",
|
|
24
|
+
story: "Primary",
|
|
25
|
+
type: "story",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "button--secondary",
|
|
29
|
+
name: "Secondary",
|
|
30
|
+
title: "Button",
|
|
31
|
+
kind: "Button",
|
|
32
|
+
story: "Secondary",
|
|
33
|
+
type: "story",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "input--default",
|
|
37
|
+
name: "Default",
|
|
38
|
+
title: "Input",
|
|
39
|
+
kind: "Input",
|
|
40
|
+
story: "Default",
|
|
41
|
+
type: "story",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "input--with-label",
|
|
45
|
+
name: "With Label",
|
|
46
|
+
title: "Input",
|
|
47
|
+
kind: "Input",
|
|
48
|
+
story: "With Label",
|
|
49
|
+
type: "story",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "card--basic",
|
|
53
|
+
name: "Basic",
|
|
54
|
+
title: "Card",
|
|
55
|
+
kind: "Card",
|
|
56
|
+
story: "Basic",
|
|
57
|
+
type: "story",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "card--advanced",
|
|
61
|
+
name: "Advanced",
|
|
62
|
+
title: "Card",
|
|
63
|
+
kind: "Card",
|
|
64
|
+
story: "Advanced",
|
|
65
|
+
type: "story",
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const mockStorybookResponse = {
|
|
70
|
+
entries: mockStories.reduce(
|
|
71
|
+
(acc, story) => {
|
|
72
|
+
acc[story.id] = story;
|
|
73
|
+
return acc;
|
|
74
|
+
},
|
|
75
|
+
{} as Record<string, StorybookStory>,
|
|
76
|
+
),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
vi.clearAllMocks();
|
|
81
|
+
(global.fetch as any).mockResolvedValue({
|
|
82
|
+
ok: true,
|
|
83
|
+
json: () => Promise.resolve(mockStorybookResponse),
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("includeStories glob patterns", () => {
|
|
88
|
+
it("should include stories matching exact story id", async () => {
|
|
89
|
+
const plugin = cappaPluginStorybook({
|
|
90
|
+
storybookUrl: "http://localhost:6006",
|
|
91
|
+
includeStories: ["button--primary"],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const result = await plugin.discover();
|
|
95
|
+
expect(result).toHaveLength(1);
|
|
96
|
+
expect(result[0].data.story.id).toBe("button--primary");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should include stories matching wildcard patterns", async () => {
|
|
100
|
+
const plugin = cappaPluginStorybook({
|
|
101
|
+
storybookUrl: "http://localhost:6006",
|
|
102
|
+
includeStories: ["button--*"],
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const result = await plugin.discover();
|
|
106
|
+
expect(result).toHaveLength(2);
|
|
107
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
108
|
+
"button--primary",
|
|
109
|
+
"button--secondary",
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should include stories matching title patterns", async () => {
|
|
114
|
+
const plugin = cappaPluginStorybook({
|
|
115
|
+
storybookUrl: "http://localhost:6006",
|
|
116
|
+
includeStories: ["Button"],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const result = await plugin.discover();
|
|
120
|
+
expect(result).toHaveLength(2);
|
|
121
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
122
|
+
"button--primary",
|
|
123
|
+
"button--secondary",
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should include stories matching name patterns", async () => {
|
|
128
|
+
const plugin = cappaPluginStorybook({
|
|
129
|
+
storybookUrl: "http://localhost:6006",
|
|
130
|
+
includeStories: ["Primary"],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const result = await plugin.discover();
|
|
134
|
+
expect(result).toHaveLength(1);
|
|
135
|
+
expect(result[0].data.story.id).toBe("button--primary");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should include stories matching full path patterns", async () => {
|
|
139
|
+
const plugin = cappaPluginStorybook({
|
|
140
|
+
storybookUrl: "http://localhost:6006",
|
|
141
|
+
includeStories: ["Button/*"],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const result = await plugin.discover();
|
|
145
|
+
expect(result).toHaveLength(2);
|
|
146
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
147
|
+
"button--primary",
|
|
148
|
+
"button--secondary",
|
|
149
|
+
]);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("should include stories matching multiple patterns", async () => {
|
|
153
|
+
const plugin = cappaPluginStorybook({
|
|
154
|
+
storybookUrl: "http://localhost:6006",
|
|
155
|
+
includeStories: ["button--*", "input--*"],
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const result = await plugin.discover();
|
|
159
|
+
expect(result).toHaveLength(4);
|
|
160
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
161
|
+
"button--primary",
|
|
162
|
+
"button--secondary",
|
|
163
|
+
"input--default",
|
|
164
|
+
"input--with-label",
|
|
165
|
+
]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("should include stories matching complex glob patterns", async () => {
|
|
169
|
+
const plugin = cappaPluginStorybook({
|
|
170
|
+
storybookUrl: "http://localhost:6006",
|
|
171
|
+
includeStories: ["*--primary", "*--default"],
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const result = await plugin.discover();
|
|
175
|
+
expect(result).toHaveLength(2);
|
|
176
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
177
|
+
"button--primary",
|
|
178
|
+
"input--default",
|
|
179
|
+
]);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe("excludeStories glob patterns", () => {
|
|
184
|
+
it("should exclude stories matching exact story id", async () => {
|
|
185
|
+
const plugin = cappaPluginStorybook({
|
|
186
|
+
storybookUrl: "http://localhost:6006",
|
|
187
|
+
excludeStories: ["button--primary"],
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const result = await plugin.discover();
|
|
191
|
+
expect(result).toHaveLength(5);
|
|
192
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
193
|
+
"button--primary",
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("should exclude stories matching wildcard patterns", async () => {
|
|
198
|
+
const plugin = cappaPluginStorybook({
|
|
199
|
+
storybookUrl: "http://localhost:6006",
|
|
200
|
+
excludeStories: ["button--*"],
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const result = await plugin.discover();
|
|
204
|
+
expect(result).toHaveLength(4);
|
|
205
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
206
|
+
"button--primary",
|
|
207
|
+
);
|
|
208
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
209
|
+
"button--secondary",
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("should exclude stories matching title patterns", async () => {
|
|
214
|
+
const plugin = cappaPluginStorybook({
|
|
215
|
+
storybookUrl: "http://localhost:6006",
|
|
216
|
+
excludeStories: ["Button"],
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const result = await plugin.discover();
|
|
220
|
+
expect(result).toHaveLength(4);
|
|
221
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
222
|
+
"button--primary",
|
|
223
|
+
);
|
|
224
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
225
|
+
"button--secondary",
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should exclude stories matching name patterns", async () => {
|
|
230
|
+
const plugin = cappaPluginStorybook({
|
|
231
|
+
storybookUrl: "http://localhost:6006",
|
|
232
|
+
excludeStories: ["Primary"],
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const result = await plugin.discover();
|
|
236
|
+
expect(result).toHaveLength(5);
|
|
237
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
238
|
+
"button--primary",
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("should exclude stories matching full path patterns", async () => {
|
|
243
|
+
const plugin = cappaPluginStorybook({
|
|
244
|
+
storybookUrl: "http://localhost:6006",
|
|
245
|
+
excludeStories: ["Button/*"],
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const result = await plugin.discover();
|
|
249
|
+
expect(result).toHaveLength(4);
|
|
250
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
251
|
+
"button--primary",
|
|
252
|
+
);
|
|
253
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
254
|
+
"button--secondary",
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("should exclude stories matching multiple patterns", async () => {
|
|
259
|
+
const plugin = cappaPluginStorybook({
|
|
260
|
+
storybookUrl: "http://localhost:6006",
|
|
261
|
+
excludeStories: ["button--*", "input--*"],
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const result = await plugin.discover();
|
|
265
|
+
expect(result).toHaveLength(2);
|
|
266
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
267
|
+
"card--basic",
|
|
268
|
+
"card--advanced",
|
|
269
|
+
]);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe("combined includeStories and excludeStories", () => {
|
|
274
|
+
it("should apply include patterns first, then exclude patterns", async () => {
|
|
275
|
+
const plugin = cappaPluginStorybook({
|
|
276
|
+
storybookUrl: "http://localhost:6006",
|
|
277
|
+
includeStories: ["*--*"], // Include all stories
|
|
278
|
+
excludeStories: ["button--*"], // Then exclude button stories
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const result = await plugin.discover();
|
|
282
|
+
expect(result).toHaveLength(4);
|
|
283
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
284
|
+
"button--primary",
|
|
285
|
+
);
|
|
286
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
287
|
+
"button--secondary",
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("should work with overlapping patterns", async () => {
|
|
292
|
+
const plugin = cappaPluginStorybook({
|
|
293
|
+
storybookUrl: "http://localhost:6006",
|
|
294
|
+
includeStories: ["*--primary", "*--default"], // Include primary and default stories
|
|
295
|
+
excludeStories: ["button--*"], // Exclude all button stories
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const result = await plugin.discover();
|
|
299
|
+
expect(result).toHaveLength(1);
|
|
300
|
+
expect(result[0].data.story.id).toBe("input--default");
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
describe("edge cases", () => {
|
|
305
|
+
it("should handle empty includeStories array", async () => {
|
|
306
|
+
const plugin = cappaPluginStorybook({
|
|
307
|
+
storybookUrl: "http://localhost:6006",
|
|
308
|
+
includeStories: [],
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const result = await plugin.discover();
|
|
312
|
+
expect(result).toHaveLength(6); // All stories included
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should handle empty excludeStories array", async () => {
|
|
316
|
+
const plugin = cappaPluginStorybook({
|
|
317
|
+
storybookUrl: "http://localhost:6006",
|
|
318
|
+
excludeStories: [],
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const result = await plugin.discover();
|
|
322
|
+
expect(result).toHaveLength(6); // All stories included
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("should handle patterns that match no stories", async () => {
|
|
326
|
+
const plugin = cappaPluginStorybook({
|
|
327
|
+
storybookUrl: "http://localhost:6006",
|
|
328
|
+
includeStories: ["nonexistent--*"],
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const result = await plugin.discover();
|
|
332
|
+
expect(result).toHaveLength(0);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("should handle case-sensitive matching", async () => {
|
|
336
|
+
const plugin = cappaPluginStorybook({
|
|
337
|
+
storybookUrl: "http://localhost:6006",
|
|
338
|
+
includeStories: ["button"], // lowercase
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const result = await plugin.discover();
|
|
342
|
+
expect(result).toHaveLength(0); // No matches because "Button" is capitalized
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("should handle special glob characters in story names", async () => {
|
|
346
|
+
// Add a story with special characters
|
|
347
|
+
const specialStory: StorybookStory = {
|
|
348
|
+
id: "special--with-dots.and-brackets[test]",
|
|
349
|
+
name: "With Dots.And Brackets[Test]",
|
|
350
|
+
title: "Special",
|
|
351
|
+
kind: "Special",
|
|
352
|
+
story: "With Dots.And Brackets[Test]",
|
|
353
|
+
type: "story",
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const specialResponse = {
|
|
357
|
+
entries: {
|
|
358
|
+
...mockStorybookResponse.entries,
|
|
359
|
+
[specialStory.id]: specialStory,
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
(global.fetch as any).mockResolvedValue({
|
|
364
|
+
ok: true,
|
|
365
|
+
json: () => Promise.resolve(specialResponse),
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const plugin = cappaPluginStorybook({
|
|
369
|
+
storybookUrl: "http://localhost:6006",
|
|
370
|
+
includeStories: ["special--*"],
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const result = await plugin.discover();
|
|
374
|
+
expect(result).toHaveLength(1);
|
|
375
|
+
expect(result[0].data.story.id).toBe(
|
|
376
|
+
"special--with-dots.and-brackets[test]",
|
|
377
|
+
);
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
package/src/cappa/plugin.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ScreenshotVariantWithUrl,
|
|
5
5
|
} from "@cappa/core";
|
|
6
6
|
import { getLogger } from "@cappa/logger";
|
|
7
|
+
import { minimatch } from "minimatch";
|
|
7
8
|
import type { Page } from "playwright-core";
|
|
8
9
|
import type {
|
|
9
10
|
ScreenshotOptionsStorybook,
|
|
@@ -63,13 +64,76 @@ export interface StorybookStory {
|
|
|
63
64
|
type: "story" | "docs";
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Matches a story against glob patterns
|
|
69
|
+
* @param story - The story to match
|
|
70
|
+
* @param patterns - Array of glob patterns to match against
|
|
71
|
+
* @returns true if the story matches any of the patterns
|
|
72
|
+
*/
|
|
73
|
+
function matchesGlobPatterns(
|
|
74
|
+
story: StorybookStory,
|
|
75
|
+
patterns: string[],
|
|
76
|
+
): boolean {
|
|
77
|
+
return patterns.some((pattern) => {
|
|
78
|
+
// Match against story id (e.g., "button--primary")
|
|
79
|
+
if (minimatch(story.id, pattern)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Match against story title (e.g., "Button")
|
|
84
|
+
if (minimatch(story.title, pattern)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Match against story name (e.g., "Primary")
|
|
89
|
+
if (minimatch(story.name, pattern)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Match against full story path (e.g., "Button/Primary")
|
|
94
|
+
const fullPath = `${story.title}/${story.name}`;
|
|
95
|
+
if (minimatch(fullPath, pattern)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return false;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
66
103
|
interface StorybookStoriesResponse {
|
|
67
104
|
entries: Record<string, StorybookStory>;
|
|
68
105
|
}
|
|
69
106
|
|
|
70
107
|
interface StorybookPluginOptions {
|
|
71
108
|
storybookUrl: string;
|
|
109
|
+
/**
|
|
110
|
+
* Array of glob patterns to include stories. Stories matching any of these patterns will be included.
|
|
111
|
+
* Patterns can match against:
|
|
112
|
+
* - Story ID (e.g., "button--primary")
|
|
113
|
+
* - Story title (e.g., "Button")
|
|
114
|
+
* - Story name (e.g., "Primary")
|
|
115
|
+
* - Full story path (e.g., "Button/Primary")
|
|
116
|
+
*
|
|
117
|
+
* Examples:
|
|
118
|
+
* - ["button--*"] - Include all button stories
|
|
119
|
+
* - ["*--primary"] - Include all primary stories
|
|
120
|
+
* - ["Button/*"] - Include all stories under Button title
|
|
121
|
+
* - ["*--*"] - Include all stories
|
|
122
|
+
*/
|
|
72
123
|
includeStories?: string[];
|
|
124
|
+
/**
|
|
125
|
+
* Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
|
|
126
|
+
* Patterns can match against:
|
|
127
|
+
* - Story ID (e.g., "button--primary")
|
|
128
|
+
* - Story title (e.g., "Button")
|
|
129
|
+
* - Story name (e.g., "Primary")
|
|
130
|
+
* - Full story path (e.g., "Button/Primary")
|
|
131
|
+
*
|
|
132
|
+
* Examples:
|
|
133
|
+
* - ["button--*"] - Exclude all button stories
|
|
134
|
+
* - ["*--secondary"] - Exclude all secondary stories
|
|
135
|
+
* - ["Input/*"] - Exclude all stories under Input title
|
|
136
|
+
*/
|
|
73
137
|
excludeStories?: string[];
|
|
74
138
|
defaultViewport?: { width: number; height: number };
|
|
75
139
|
waitForSelector?: string;
|
|
@@ -91,7 +155,8 @@ function createLatch<T>() {
|
|
|
91
155
|
|
|
92
156
|
/**
|
|
93
157
|
* Storybook Plugin for Cappa
|
|
94
|
-
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
158
|
+
* Fetches stories from a running Storybook server and takes screenshots of each story.
|
|
159
|
+
* Supports glob pattern matching for includeStories and excludeStories options.
|
|
95
160
|
*/
|
|
96
161
|
export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
97
162
|
options,
|
|
@@ -131,25 +196,18 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
131
196
|
const data = (await response.json()) as StorybookStoriesResponse;
|
|
132
197
|
const stories = Object.values(data.entries);
|
|
133
198
|
|
|
134
|
-
// Filter stories based on include/exclude patterns
|
|
199
|
+
// Filter stories based on include/exclude glob patterns
|
|
135
200
|
let filteredStories = stories;
|
|
136
201
|
|
|
137
202
|
if (includeStories.length > 0) {
|
|
138
203
|
filteredStories = filteredStories.filter((story) =>
|
|
139
|
-
includeStories
|
|
140
|
-
(pattern) =>
|
|
141
|
-
story.title.includes(pattern) || story.name.includes(pattern),
|
|
142
|
-
),
|
|
204
|
+
matchesGlobPatterns(story, includeStories),
|
|
143
205
|
);
|
|
144
206
|
}
|
|
145
207
|
|
|
146
208
|
if (excludeStories.length > 0) {
|
|
147
209
|
filteredStories = filteredStories.filter(
|
|
148
|
-
(story) =>
|
|
149
|
-
!excludeStories.some(
|
|
150
|
-
(pattern) =>
|
|
151
|
-
story.title.includes(pattern) || story.name.includes(pattern),
|
|
152
|
-
),
|
|
210
|
+
(story) => !matchesGlobPatterns(story, excludeStories),
|
|
153
211
|
);
|
|
154
212
|
}
|
|
155
213
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export const previewAnnotations = [require.resolve("./preview.mjs")];
|
|
1
|
+
export const previewAnnotations = [require.resolve("./preview.js")];
|
|
4
2
|
|
|
3
|
+
export { cappaPluginStorybook } from "./cappa/plugin";
|
|
5
4
|
export type { ScreenshotOptionsStorybook as CappaStorybookOptions } from "./types";
|
package/src/index.esm.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
export const previewAnnotations = [
|
|
3
|
+
fileURLToPath(new URL("./preview.js", import.meta.url)),
|
|
4
|
+
];
|
|
5
|
+
|
|
6
|
+
export { cappaPluginStorybook } from "./cappa/plugin";
|
|
7
|
+
export type { ScreenshotOptionsStorybook as CappaStorybookOptions } from "./types";
|
package/tsup.config.ts
CHANGED
|
@@ -2,11 +2,19 @@ import { defineConfig } from "tsup";
|
|
|
2
2
|
|
|
3
3
|
export default defineConfig([
|
|
4
4
|
{
|
|
5
|
-
entry:
|
|
6
|
-
format: ["
|
|
7
|
-
dts:
|
|
5
|
+
entry: { index: "src/index.esm.ts" },
|
|
6
|
+
format: ["esm"],
|
|
7
|
+
dts: { entry: "src/index.esm.ts" },
|
|
8
|
+
splitting: false,
|
|
9
|
+
external: ["./preview.js"],
|
|
10
|
+
sourcemap: false,
|
|
11
|
+
clean: true,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
entry: { index: "src/index.cjs.ts" },
|
|
15
|
+
format: ["cjs"],
|
|
8
16
|
splitting: false,
|
|
9
|
-
external: ["./preview.
|
|
17
|
+
external: ["./preview.js"],
|
|
10
18
|
sourcemap: false,
|
|
11
19
|
clean: true,
|
|
12
20
|
},
|
package/dist/index.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@cappa/core';
|
|
2
|
-
|
|
3
|
-
interface StorybookRenderOptions {
|
|
4
|
-
viewMode?: "story" | "docs";
|
|
5
|
-
args?: Record<string, unknown>;
|
|
6
|
-
globals?: Record<string, string | number | boolean>;
|
|
7
|
-
query?: Record<string, string | number | boolean>;
|
|
8
|
-
fullscreen?: boolean;
|
|
9
|
-
singleStory?: boolean;
|
|
10
|
-
}
|
|
11
|
-
interface ScreenshotVariantOverrideStorybook {
|
|
12
|
-
fullPage?: boolean;
|
|
13
|
-
delay?: number;
|
|
14
|
-
skip?: boolean;
|
|
15
|
-
mask?: string[];
|
|
16
|
-
omitBackground?: boolean;
|
|
17
|
-
viewport?: {
|
|
18
|
-
width: number;
|
|
19
|
-
height: number;
|
|
20
|
-
};
|
|
21
|
-
args?: Record<string, unknown>;
|
|
22
|
-
}
|
|
23
|
-
interface ScreenshotVariantOptionsStorybook {
|
|
24
|
-
id: string;
|
|
25
|
-
label?: string;
|
|
26
|
-
filename?: string;
|
|
27
|
-
options?: ScreenshotVariantOverrideStorybook;
|
|
28
|
-
}
|
|
29
|
-
interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook {
|
|
30
|
-
variants?: ScreenshotVariantOptionsStorybook[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface StorybookPluginOptions {
|
|
34
|
-
storybookUrl: string;
|
|
35
|
-
includeStories?: string[];
|
|
36
|
-
excludeStories?: string[];
|
|
37
|
-
defaultViewport?: {
|
|
38
|
-
width: number;
|
|
39
|
-
height: number;
|
|
40
|
-
};
|
|
41
|
-
waitForSelector?: string;
|
|
42
|
-
waitForTimeout?: number;
|
|
43
|
-
storybook?: StorybookRenderOptions;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Storybook Plugin for Cappa
|
|
47
|
-
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
48
|
-
*/
|
|
49
|
-
declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
50
|
-
|
|
51
|
-
declare const previewAnnotations: string[];
|
|
52
|
-
|
|
53
|
-
export { type ScreenshotOptionsStorybook as CappaStorybookOptions, cappaPluginStorybook, previewAnnotations };
|
|
File without changes
|
|
File without changes
|