@cappa/plugin-storybook 0.1.0 → 0.1.2

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- > @cappa/plugin-storybook@0.0.27 build /home/tim/cappa/packages/plugins/plugin-storybook
3
+ > @cappa/plugin-storybook@0.1.1 build /home/tim/cappa/packages/plugins/plugin-storybook
4
4
  > tsup
5
5
 
6
6
  CLI Building entry: src/index.ts
@@ -26,14 +26,14 @@
26
26
  CLI Cleaning output folder
27
27
  ESM Build start
28
28
  ESM dist/browser.mjs 138.00 B
29
- ESM ⚡️ Build success in 11ms
29
+ ESM ⚡️ Build success in 8ms
30
30
  ESM dist/preview.mjs 1.34 KB
31
+ ESM ⚡️ Build success in 10ms
32
+ ESM dist/index.mjs 9.40 KB
31
33
  ESM ⚡️ Build success in 14ms
32
- ESM dist/index.mjs 9.65 KB
33
- ESM ⚡️ Build success in 17ms
34
- CJS dist/index.js 11.02 KB
35
- CJS ⚡️ Build success in 17ms
34
+ CJS dist/index.js 10.79 KB
35
+ CJS ⚡️ Build success in 15ms
36
36
  DTS Build start
37
- DTS ⚡️ Build success in 1192ms
37
+ DTS ⚡️ Build success in 937ms
38
38
  DTS dist/index.d.ts 593.00 B
39
39
  DTS dist/index.d.mts 593.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @cappa/plugin-storybook
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a772b76: Add better logging + cleanup
8
+ - Updated dependencies [a772b76]
9
+ - @cappa/core@0.1.2
10
+ - @cappa/logger@0.0.2
11
+
12
+ ## 0.1.1
13
+
14
+ ### Patch Changes
15
+
16
+ - d640855: Fix server public folder publish
17
+ - Updated dependencies [d640855]
18
+ - @cappa/core@0.1.1
19
+
3
20
  ## 0.1.0
4
21
 
5
22
  ### Minor Changes
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
38
  // src/cappa/plugin.ts
39
+ var import_logger = require("@cappa/logger");
39
40
  var import_chalk = __toESM(require("chalk"));
40
41
 
41
42
  // src/cappa/util.ts
@@ -123,27 +124,28 @@ var cappaPluginStorybook = (options) => {
123
124
  name: "StorybookPlugin",
124
125
  description: "Takes screenshots of Storybook stories with configurable options",
125
126
  version: "1.0.0",
126
- execute: async (screenshotTool, logger) => {
127
+ execute: async (screenshotTool) => {
127
128
  if (!options) {
128
129
  throw new Error("Storybook plugin options are required");
129
130
  }
130
131
  if (!options.storybookUrl) {
131
132
  throw new Error("storybookUrl is required");
132
133
  }
134
+ const logger = (0, import_logger.getLogger)();
133
135
  const {
134
136
  storybookUrl,
135
137
  includeStories = [],
136
138
  excludeStories = []
137
139
  } = options;
138
140
  const storiesUrl = `${storybookUrl}/index.json`;
139
- console.log(`Fetching stories from: ${storiesUrl}`);
141
+ logger.debug(`Fetching stories from: ${storiesUrl}`);
142
+ const response = await fetch(storiesUrl);
143
+ if (!response.ok) {
144
+ throw new Error(
145
+ `Failed to fetch stories: ${response.status} ${response.statusText}`
146
+ );
147
+ }
140
148
  try {
141
- const response = await fetch(storiesUrl);
142
- if (!response.ok) {
143
- throw new Error(
144
- `Failed to fetch stories: ${response.status} ${response.statusText}`
145
- );
146
- }
147
149
  const data = await response.json();
148
150
  const stories = Object.values(data.entries);
149
151
  let filteredStories = stories;
@@ -164,7 +166,9 @@ var cappaPluginStorybook = (options) => {
164
166
  filteredStories = filteredStories.filter(
165
167
  (story) => story.type === "story"
166
168
  );
167
- console.log(`Found ${filteredStories.length} stories to screenshot`);
169
+ logger.start(
170
+ `Found ${filteredStories.length} stories to screenshot...`
171
+ );
168
172
  const results = [];
169
173
  await screenshotTool.init();
170
174
  let currentLatch = createLatch();
@@ -191,7 +195,7 @@ var cappaPluginStorybook = (options) => {
191
195
  const options2 = await currentLatch.p;
192
196
  currentLatch = createLatch();
193
197
  if (options2.skip) {
194
- logger.log(`Skipping story ${story.title} - ${story.name}`);
198
+ logger.warn(`Skipping story ${story.title} - ${story.name}`);
195
199
  results.push({
196
200
  storyId: story.id,
197
201
  storyName: `${story.title} - ${story.name}`,
@@ -225,15 +229,6 @@ var cappaPluginStorybook = (options) => {
225
229
  }
226
230
  );
227
231
  actualFilepath = screenshotPath;
228
- if (comparisonResult.passed) {
229
- logger.log(
230
- `Story ${story.title} - ${story.name} passed visual comparison`
231
- );
232
- } else {
233
- logger.log(
234
- `Story ${story.title} - ${story.name} failed visual comparison`
235
- );
236
- }
237
232
  results.push({
238
233
  storyId: story.id,
239
234
  storyName: `${story.title} - ${story.name}`,
@@ -261,7 +256,7 @@ var cappaPluginStorybook = (options) => {
261
256
  });
262
257
  }
263
258
  } catch (error) {
264
- console.error(
259
+ logger.error(
265
260
  `Error taking screenshot of story ${story.title} - ${story.name}:`,
266
261
  error.message
267
262
  );
@@ -273,13 +268,13 @@ var cappaPluginStorybook = (options) => {
273
268
  }
274
269
  }
275
270
  if (results.some((r) => r.error)) {
276
- console.log(
271
+ logger.error(
277
272
  `Error report:
278
273
  ${results.filter((r) => r.error).map((r) => `${r.storyName}: ${r.error}`).join("\n")}`
279
274
  );
280
275
  }
281
276
  if (results.some((r) => r.skipped)) {
282
- console.log(
277
+ logger.warn(
283
278
  `Skipped stories:
284
279
  ${results.filter((r) => r.skipped).map((r) => `${r.storyName}`).join("\n")}`
285
280
  );
@@ -301,7 +296,7 @@ ${results.filter((r) => r.skipped).map((r) => `${r.storyName}`).join("\n")}`
301
296
  });
302
297
  return results;
303
298
  } catch (error) {
304
- console.error("Error in Storybook plugin:", error.message);
299
+ logger.error("Error in Storybook plugin:", error.message);
305
300
  throw error;
306
301
  }
307
302
  }
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/cappa/plugin.ts
9
+ import { getLogger } from "@cappa/logger";
9
10
  import chalk from "chalk";
10
11
 
11
12
  // src/cappa/util.ts
@@ -93,27 +94,28 @@ var cappaPluginStorybook = (options) => {
93
94
  name: "StorybookPlugin",
94
95
  description: "Takes screenshots of Storybook stories with configurable options",
95
96
  version: "1.0.0",
96
- execute: async (screenshotTool, logger) => {
97
+ execute: async (screenshotTool) => {
97
98
  if (!options) {
98
99
  throw new Error("Storybook plugin options are required");
99
100
  }
100
101
  if (!options.storybookUrl) {
101
102
  throw new Error("storybookUrl is required");
102
103
  }
104
+ const logger = getLogger();
103
105
  const {
104
106
  storybookUrl,
105
107
  includeStories = [],
106
108
  excludeStories = []
107
109
  } = options;
108
110
  const storiesUrl = `${storybookUrl}/index.json`;
109
- console.log(`Fetching stories from: ${storiesUrl}`);
111
+ logger.debug(`Fetching stories from: ${storiesUrl}`);
112
+ const response = await fetch(storiesUrl);
113
+ if (!response.ok) {
114
+ throw new Error(
115
+ `Failed to fetch stories: ${response.status} ${response.statusText}`
116
+ );
117
+ }
110
118
  try {
111
- const response = await fetch(storiesUrl);
112
- if (!response.ok) {
113
- throw new Error(
114
- `Failed to fetch stories: ${response.status} ${response.statusText}`
115
- );
116
- }
117
119
  const data = await response.json();
118
120
  const stories = Object.values(data.entries);
119
121
  let filteredStories = stories;
@@ -134,7 +136,9 @@ var cappaPluginStorybook = (options) => {
134
136
  filteredStories = filteredStories.filter(
135
137
  (story) => story.type === "story"
136
138
  );
137
- console.log(`Found ${filteredStories.length} stories to screenshot`);
139
+ logger.start(
140
+ `Found ${filteredStories.length} stories to screenshot...`
141
+ );
138
142
  const results = [];
139
143
  await screenshotTool.init();
140
144
  let currentLatch = createLatch();
@@ -161,7 +165,7 @@ var cappaPluginStorybook = (options) => {
161
165
  const options2 = await currentLatch.p;
162
166
  currentLatch = createLatch();
163
167
  if (options2.skip) {
164
- logger.log(`Skipping story ${story.title} - ${story.name}`);
168
+ logger.warn(`Skipping story ${story.title} - ${story.name}`);
165
169
  results.push({
166
170
  storyId: story.id,
167
171
  storyName: `${story.title} - ${story.name}`,
@@ -195,15 +199,6 @@ var cappaPluginStorybook = (options) => {
195
199
  }
196
200
  );
197
201
  actualFilepath = screenshotPath;
198
- if (comparisonResult.passed) {
199
- logger.log(
200
- `Story ${story.title} - ${story.name} passed visual comparison`
201
- );
202
- } else {
203
- logger.log(
204
- `Story ${story.title} - ${story.name} failed visual comparison`
205
- );
206
- }
207
202
  results.push({
208
203
  storyId: story.id,
209
204
  storyName: `${story.title} - ${story.name}`,
@@ -231,7 +226,7 @@ var cappaPluginStorybook = (options) => {
231
226
  });
232
227
  }
233
228
  } catch (error) {
234
- console.error(
229
+ logger.error(
235
230
  `Error taking screenshot of story ${story.title} - ${story.name}:`,
236
231
  error.message
237
232
  );
@@ -243,13 +238,13 @@ var cappaPluginStorybook = (options) => {
243
238
  }
244
239
  }
245
240
  if (results.some((r) => r.error)) {
246
- console.log(
241
+ logger.error(
247
242
  `Error report:
248
243
  ${results.filter((r) => r.error).map((r) => `${r.storyName}: ${r.error}`).join("\n")}`
249
244
  );
250
245
  }
251
246
  if (results.some((r) => r.skipped)) {
252
- console.log(
247
+ logger.warn(
253
248
  `Skipped stories:
254
249
  ${results.filter((r) => r.skipped).map((r) => `${r.storyName}`).join("\n")}`
255
250
  );
@@ -271,7 +266,7 @@ ${results.filter((r) => r.skipped).map((r) => `${r.storyName}`).join("\n")}`
271
266
  });
272
267
  return results;
273
268
  } catch (error) {
274
- console.error("Error in Storybook plugin:", error.message);
269
+ logger.error("Error in Storybook plugin:", error.message);
275
270
  throw error;
276
271
  }
277
272
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/plugin-storybook",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -31,7 +31,8 @@
31
31
  "@swc/core": "^1.13.5",
32
32
  "chalk": "^5.6.2",
33
33
  "storybook": "^9.1.5",
34
- "@cappa/core": "0.1.0"
34
+ "@cappa/core": "0.1.2",
35
+ "@cappa/logger": "0.0.2"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@vitest/coverage-v8": "3.2.4",
@@ -1,5 +1,7 @@
1
- import type { Plugin, ScreenshotOptions } from "@cappa/core";
1
+ import type { Plugin } from "@cappa/core";
2
+ import { getLogger } from "@cappa/logger";
2
3
  import chalk from "chalk";
4
+ import type { ScreenshotOptionsStorybook } from "../types";
3
5
  import { buildFilename, freezeUI, waitForVisualIdle } from "./util";
4
6
 
5
7
  export interface StorybookStory {
@@ -48,7 +50,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
48
50
  description:
49
51
  "Takes screenshots of Storybook stories with configurable options",
50
52
  version: "1.0.0",
51
- execute: async (screenshotTool, logger) => {
53
+ execute: async (screenshotTool) => {
52
54
  if (!options) {
53
55
  throw new Error("Storybook plugin options are required");
54
56
  }
@@ -56,6 +58,8 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
56
58
  throw new Error("storybookUrl is required");
57
59
  }
58
60
 
61
+ const logger = getLogger();
62
+
59
63
  const {
60
64
  storybookUrl,
61
65
  includeStories = [],
@@ -63,17 +67,17 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
63
67
  } = options;
64
68
 
65
69
  const storiesUrl = `${storybookUrl}/index.json`;
66
- console.log(`Fetching stories from: ${storiesUrl}`);
70
+ logger.debug(`Fetching stories from: ${storiesUrl}`);
67
71
 
68
- try {
69
- // Fetch stories from Storybook
70
- const response = await fetch(storiesUrl);
71
- if (!response.ok) {
72
- throw new Error(
73
- `Failed to fetch stories: ${response.status} ${response.statusText}`,
74
- );
75
- }
72
+ // Fetch stories from Storybook
73
+ const response = await fetch(storiesUrl);
74
+ if (!response.ok) {
75
+ throw new Error(
76
+ `Failed to fetch stories: ${response.status} ${response.statusText}`,
77
+ );
78
+ }
76
79
 
80
+ try {
77
81
  const data = (await response.json()) as StorybookStoriesResponse;
78
82
  const stories = Object.values(data.entries);
79
83
 
@@ -104,7 +108,9 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
104
108
  (story) => story.type === "story",
105
109
  );
106
110
 
107
- console.log(`Found ${filteredStories.length} stories to screenshot`);
111
+ logger.start(
112
+ `Found ${filteredStories.length} stories to screenshot...`,
113
+ );
108
114
 
109
115
  const results: Array<{
110
116
  storyId: string;
@@ -117,11 +123,11 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
117
123
 
118
124
  await screenshotTool.init();
119
125
 
120
- let currentLatch = createLatch<ScreenshotOptions>();
126
+ let currentLatch = createLatch<ScreenshotOptionsStorybook>();
121
127
 
122
128
  await screenshotTool.page?.exposeFunction(
123
129
  "__cappa_parameters",
124
- async (payload: ScreenshotOptions) => {
130
+ async (payload: ScreenshotOptionsStorybook) => {
125
131
  currentLatch.resolve(payload);
126
132
  },
127
133
  );
@@ -146,10 +152,10 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
146
152
  await page.goto(storyUrl);
147
153
 
148
154
  const options = await currentLatch.p;
149
- currentLatch = createLatch<ScreenshotOptions>();
155
+ currentLatch = createLatch<ScreenshotOptionsStorybook>();
150
156
 
151
157
  if (options.skip) {
152
- logger.log(`Skipping story ${story.title} - ${story.name}`);
158
+ logger.warn(`Skipping story ${story.title} - ${story.name}`);
153
159
  results.push({
154
160
  storyId: story.id,
155
161
  storyName: `${story.title} - ${story.name}`,
@@ -191,15 +197,6 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
191
197
  );
192
198
 
193
199
  actualFilepath = screenshotPath;
194
- if (comparisonResult.passed) {
195
- logger.log(
196
- `Story ${story.title} - ${story.name} passed visual comparison`,
197
- );
198
- } else {
199
- logger.log(
200
- `Story ${story.title} - ${story.name} failed visual comparison`,
201
- );
202
- }
203
200
 
204
201
  results.push({
205
202
  storyId: story.id,
@@ -229,7 +226,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
229
226
  });
230
227
  }
231
228
  } catch (error) {
232
- console.error(
229
+ logger.error(
233
230
  `Error taking screenshot of story ${story.title} - ${story.name}:`,
234
231
  (error as Error).message,
235
232
  );
@@ -243,7 +240,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
243
240
 
244
241
  // Print error report if there are any errors
245
242
  if (results.some((r) => r.error)) {
246
- console.log(
243
+ logger.error(
247
244
  `Error report: \n${results
248
245
  .filter((r) => r.error)
249
246
  .map((r) => `${r.storyName}: ${r.error}`)
@@ -253,7 +250,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
253
250
 
254
251
  // Print skipped stories if there are any
255
252
  if (results.some((r) => r.skipped)) {
256
- console.log(
253
+ logger.warn(
257
254
  `Skipped stories: \n${results
258
255
  .filter((r) => r.skipped)
259
256
  .map((r) => `${r.storyName}`)
@@ -281,7 +278,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
281
278
 
282
279
  return results;
283
280
  } catch (error) {
284
- console.error("Error in Storybook plugin:", (error as Error).message);
281
+ logger.error("Error in Storybook plugin:", (error as Error).message);
285
282
  throw error;
286
283
  }
287
284
  },
@@ -4,7 +4,10 @@
4
4
  * @param timeoutMs - The timeout in milliseconds
5
5
  * @returns The function or rejects if the function is not exposed within the timeout
6
6
  */
7
- export const waitForExposed = (name: string, timeoutMs = 5000) => {
7
+ export const waitForExposed = (
8
+ name: string,
9
+ timeoutMs = 5000,
10
+ ): Promise<(parameters: any) => void> => {
8
11
  return new Promise((resolve, reject) => {
9
12
  const start = performance.now();
10
13
 
package/src/types.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { ScreenshotOptions } from "@cappa/core";
2
+
3
+ export type ScreenshotOptionsStorybook = Omit<ScreenshotOptions, "mask"> & {
4
+ mask: string[];
5
+ };