@effinrich/forgekit-storybook-plugin 2.0.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/README.md +221 -0
- package/bin/forgekit.js +2 -0
- package/dist/chunk-C2HX5UGS.mjs +704 -0
- package/dist/chunk-C2HX5UGS.mjs.map +1 -0
- package/dist/chunk-D2RQPIRR.mjs +413 -0
- package/dist/chunk-D2RQPIRR.mjs.map +1 -0
- package/dist/chunk-T4UFXGMC.js +704 -0
- package/dist/chunk-T4UFXGMC.js.map +1 -0
- package/dist/chunk-WUKJNZOF.js +413 -0
- package/dist/chunk-WUKJNZOF.js.map +1 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +523 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +523 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/forge-test-EGP3AGFI.mjs +7 -0
- package/dist/forge-test-EGP3AGFI.mjs.map +1 -0
- package/dist/forge-test-FLCVDJFR.js +7 -0
- package/dist/forge-test-FLCVDJFR.js.map +1 -0
- package/dist/index.d.mts +206 -0
- package/dist/index.d.ts +206 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +29 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# ForgeKit Storybook Plugin
|
|
2
|
+
|
|
3
|
+
Auto-generate Storybook stories, interaction tests, Playwright component tests, and accessibility audits from React component analysis.
|
|
4
|
+
|
|
5
|
+
ForgeKit Storybook Plugin analyzes your React components — props, callbacks, union types, features — and generates complete `.stories.tsx` files with controls, variants, interaction tests, and a11y audits. No configuration required.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -D @effinrich/forgekit-storybook-plugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Peer dependencies** (optional):
|
|
14
|
+
|
|
15
|
+
- `storybook >= 8.0.0`
|
|
16
|
+
- `typescript >= 5.0.0`
|
|
17
|
+
|
|
18
|
+
Run `npx forgekit-storybook-plugin init` to check prerequisites and see what's installed.
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Generate a story for a single component
|
|
24
|
+
npx forgekit-storybook-plugin story src/components/Button.tsx
|
|
25
|
+
|
|
26
|
+
# Generate stories for every component in a directory
|
|
27
|
+
npx forgekit-storybook-plugin stories src/components/
|
|
28
|
+
|
|
29
|
+
# Check coverage without generating anything
|
|
30
|
+
npx forgekit-storybook-plugin coverage src/components/
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## CLI Commands
|
|
34
|
+
|
|
35
|
+
### `forgekit-storybook-plugin story <path>`
|
|
36
|
+
|
|
37
|
+
Generate a Storybook story for a single React component.
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx forgekit-storybook-plugin story src/Button.tsx
|
|
41
|
+
npx forgekit-storybook-plugin story src/Button.tsx --dry-run
|
|
42
|
+
npx forgekit-storybook-plugin story src/Button.tsx --overwrite --skip-interaction-tests
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| Option | Default | Description |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `--story-title` | auto-inferred | Custom Storybook title |
|
|
48
|
+
| `--skip-interaction-tests` | `false` | Skip generating play functions |
|
|
49
|
+
| `--overwrite` | `false` | Overwrite existing story file |
|
|
50
|
+
| `--dry-run` | `false` | Preview without writing files |
|
|
51
|
+
|
|
52
|
+
### `forgekit-storybook-plugin stories <dir>`
|
|
53
|
+
|
|
54
|
+
Bulk generate stories for all components in a directory.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx forgekit-storybook-plugin stories src/components/
|
|
58
|
+
npx forgekit-storybook-plugin stories src/components/ --include-tests --overwrite
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
| Option | Default | Description |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `--skip-interaction-tests` | `false` | Skip generating play functions |
|
|
64
|
+
| `--overwrite` | `false` | Overwrite existing story files |
|
|
65
|
+
| `--dry-run` | `false` | Preview without writing files |
|
|
66
|
+
| `--include-tests` | `false` | Also generate Playwright component tests |
|
|
67
|
+
|
|
68
|
+
### `forgekit-storybook-plugin test <path>`
|
|
69
|
+
|
|
70
|
+
Generate a Playwright component test for a React component.
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx forgekit-storybook-plugin test src/Button.tsx
|
|
74
|
+
npx forgekit-storybook-plugin test src/Button.tsx --dry-run
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
| Option | Default | Description |
|
|
78
|
+
| --- | --- | --- |
|
|
79
|
+
| `--overwrite` | `false` | Overwrite existing test file |
|
|
80
|
+
| `--dry-run` | `false` | Preview without writing files |
|
|
81
|
+
|
|
82
|
+
### `forgekit-storybook-plugin watch <dir>`
|
|
83
|
+
|
|
84
|
+
Watch a directory and auto-generate stories when components change.
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npx forgekit-storybook-plugin watch src/components/
|
|
88
|
+
npx forgekit-storybook-plugin watch src/components/ --debounce 500
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Option | Default | Description |
|
|
92
|
+
| --- | --- | --- |
|
|
93
|
+
| `--skip-interaction-tests` | `false` | Skip generating play functions |
|
|
94
|
+
| `--debounce` | `300` | Debounce interval in milliseconds |
|
|
95
|
+
|
|
96
|
+
### `forgekit-storybook-plugin coverage <dir>`
|
|
97
|
+
|
|
98
|
+
Report story coverage for a directory without generating files.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npx forgekit-storybook-plugin coverage src/components/
|
|
102
|
+
npx forgekit-storybook-plugin coverage src/components/ --json
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
| Option | Default | Description |
|
|
106
|
+
| --- | --- | --- |
|
|
107
|
+
| `--json` | `false` | Output results as JSON |
|
|
108
|
+
|
|
109
|
+
Coverage grades: **A** (≥ 90%) · **B** (≥ 75%) · **C** (≥ 50%) · **D** (≥ 25%) · **F** (< 25%)
|
|
110
|
+
|
|
111
|
+
### `forgekit-storybook-plugin init`
|
|
112
|
+
|
|
113
|
+
Check prerequisites and display the setup guide.
|
|
114
|
+
|
|
115
|
+
## What Gets Generated
|
|
116
|
+
|
|
117
|
+
For each component, ForgeKit Storybook Plugin can generate up to **9 Storybook stories**:
|
|
118
|
+
|
|
119
|
+
| Story | Condition | Tests |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| **Default** | Always | Component with default/required props |
|
|
122
|
+
| **Sizes** | `size` prop with union values | All size variants side by side |
|
|
123
|
+
| **Variants** | `variant` prop with union values | All style variants |
|
|
124
|
+
| **ColorPalettes** | `colorPalette` prop with union values | All color options |
|
|
125
|
+
| **Disabled** | `disabled`/`isDisabled` prop | Disabled state rendering |
|
|
126
|
+
| **ClickInteraction** | Any `onClick`/`onPress` callback | Click fires handler |
|
|
127
|
+
| **KeyboardNavigation** | Any interactive callback | Tab focus + Enter triggers |
|
|
128
|
+
| **RendersCorrectly** | Always | Mounts without crashing |
|
|
129
|
+
| **AccessibilityAudit** | Always | axe-core a11y check |
|
|
130
|
+
|
|
131
|
+
And up to **7 Playwright test cases** (visual regression, interaction, accessibility).
|
|
132
|
+
|
|
133
|
+
## Programmatic API
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import {
|
|
137
|
+
forgeStory,
|
|
138
|
+
forgeStories,
|
|
139
|
+
forgeTest,
|
|
140
|
+
analyzeComponent,
|
|
141
|
+
generateStoryContent,
|
|
142
|
+
scoreCoverage,
|
|
143
|
+
scanDirectory,
|
|
144
|
+
watchDirectory,
|
|
145
|
+
} from '@effinrich/forgekit-storybook-plugin';
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `forgeStory(options)`
|
|
149
|
+
|
|
150
|
+
Analyze a component, generate a story, and optionally write it to disk.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const result = await forgeStory({
|
|
154
|
+
componentPath: 'src/Button.tsx',
|
|
155
|
+
overwrite: false,
|
|
156
|
+
dryRun: false,
|
|
157
|
+
});
|
|
158
|
+
// result: { storyPath, content, analysis, storiesGenerated, written }
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### `forgeStories(options)`
|
|
162
|
+
|
|
163
|
+
Bulk generate stories for all components in a directory.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const result = await forgeStories({
|
|
167
|
+
dir: 'src/components',
|
|
168
|
+
includeComponentTests: true,
|
|
169
|
+
});
|
|
170
|
+
// result: { generated, failed, alreadyCovered, notAnalyzable, total, coverage, errors }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### `forgeTest(options)`
|
|
174
|
+
|
|
175
|
+
Generate a Playwright component test for a component.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
const result = await forgeTest({
|
|
179
|
+
componentPath: 'src/Button.tsx',
|
|
180
|
+
});
|
|
181
|
+
// result: { testPath, content, analysis, written }
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### `analyzeComponent(filePath)`
|
|
185
|
+
|
|
186
|
+
Low-level: parse a React component and extract props, imports, features, and export type.
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
const analysis = analyzeComponent('src/Button.tsx');
|
|
190
|
+
// analysis: { componentName, props, imports, features, exportType }
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `scoreCoverage(covered, total)`
|
|
194
|
+
|
|
195
|
+
Calculate coverage percentage and letter grade.
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
const report = scoreCoverage(8, 10);
|
|
199
|
+
// report: { covered: 8, total: 10, percentage: 80, grade: 'B' }
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Component Analysis
|
|
203
|
+
|
|
204
|
+
ForgeKit Storybook Plugin detects:
|
|
205
|
+
|
|
206
|
+
- **Props** — name, type, required, callbacks, union values (`'sm' | 'md' | 'lg'`)
|
|
207
|
+
- **Features** — children, React Router, React Query, Chakra UI
|
|
208
|
+
- **Export type** — default, named, or both
|
|
209
|
+
- **Patterns** — `React.forwardRef`, `React.memo`, intersection types
|
|
210
|
+
|
|
211
|
+
Controls are auto-mapped: `text`, `number`, `boolean`, `select` (for unions), `action` (for callbacks).
|
|
212
|
+
|
|
213
|
+
## Requirements
|
|
214
|
+
|
|
215
|
+
- Node.js ≥ 18.17.1
|
|
216
|
+
- React components (`.tsx` / `.jsx`)
|
|
217
|
+
- Storybook ≥ 8.0.0 (optional peer dep — CLI works without it for dry-run/analysis)
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
MIT
|
package/bin/forgekit.js
ADDED