@tpitre/story-ui 1.7.1 โ†’ 2.0.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.
Files changed (35) hide show
  1. package/.env.sample +3 -1
  2. package/README.md +160 -606
  3. package/dist/cli/index.js +23 -24
  4. package/dist/cli/setup.js +295 -36
  5. package/dist/mcp-server/index.js +67 -0
  6. package/dist/mcp-server/routes/generateStory.js +323 -56
  7. package/dist/story-generator/componentBlacklist.js +181 -0
  8. package/dist/story-generator/componentDiscovery.js +9 -2
  9. package/dist/story-generator/configLoader.js +109 -39
  10. package/dist/story-generator/considerationsLoader.js +204 -0
  11. package/dist/story-generator/documentation-sources.js +36 -0
  12. package/dist/story-generator/documentationLoader.js +214 -0
  13. package/dist/story-generator/dynamicPackageDiscovery.js +527 -0
  14. package/dist/story-generator/enhancedComponentDiscovery.js +369 -118
  15. package/dist/story-generator/generateStory.js +7 -3
  16. package/dist/story-generator/postProcessStory.js +71 -0
  17. package/dist/story-generator/promptGenerator.js +286 -37
  18. package/dist/story-generator/storyHistory.js +118 -0
  19. package/dist/story-generator/storyTracker.js +33 -18
  20. package/dist/story-generator/storyValidator.js +39 -0
  21. package/dist/story-generator/universalDesignSystemAdapter.js +209 -0
  22. package/dist/story-generator/validateStory.js +82 -7
  23. package/dist/story-ui.config.js +12 -5
  24. package/package.json +11 -6
  25. package/templates/StoryUI/StoryUIPanel.stories.tsx +29 -13
  26. package/templates/StoryUI/StoryUIPanel.tsx +489 -359
  27. package/templates/react-import-rule.json +36 -0
  28. package/templates/story-generation-rules.json +29 -0
  29. package/templates/story-ui-considerations.json +156 -0
  30. package/templates/story-ui-considerations.md +109 -0
  31. package/templates/story-ui-docs-README.md +55 -0
  32. package/dist/scripts/test-validation.js +0 -81
  33. package/dist/test-storybooks/chakra-test/src/components/index.js +0 -3
  34. package/dist/test-storybooks/custom-design-test/src/components/index.js +0 -3
  35. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,36 @@
1
+ {
2
+ "globalRules": {
3
+ "reactImportMandatory": {
4
+ "name": "React Import is Mandatory",
5
+ "priority": "CRITICAL",
6
+ "rule": "Every story file MUST include 'import React from 'react';' as the FIRST import. This is non-negotiable for JSX to work.",
7
+ "enforcement": "automatic",
8
+ "details": {
9
+ "why": "JSX syntax requires React to be in scope. Without this import, stories will fail with 'React is not defined' error.",
10
+ "where": "First line of imports, before any other imports",
11
+ "format": "import React from 'react';",
12
+ "examples": {
13
+ "correct": [
14
+ "import React from 'react';",
15
+ "import type { Meta, StoryObj } from '@storybook/react-webpack5';",
16
+ "import { Button, Card } from 'antd';"
17
+ ],
18
+ "incorrect": [
19
+ "import type { Meta, StoryObj } from '@storybook/react-webpack5';",
20
+ "import { Button, Card } from 'antd';",
21
+ "// Missing React import!"
22
+ ]
23
+ }
24
+ },
25
+ "automaticFix": {
26
+ "enabled": true,
27
+ "description": "The system will automatically add 'import React from 'react';' if it detects JSX without React import"
28
+ }
29
+ }
30
+ },
31
+ "implementation": {
32
+ "validation": "Story validation will check for React import when JSX is present",
33
+ "autoFix": "Missing React imports will be automatically added during generation",
34
+ "promptGuidance": "AI prompts emphasize React import as the first mandatory import"
35
+ }
36
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "storyGenerationRules": {
3
+ "navigationStructure": {
4
+ "name": "Story Navigation Structure",
5
+ "priority": "HIGH",
6
+ "rule": "All generated stories MUST be placed under the 'Generated' section in Storybook navigation",
7
+ "implementation": {
8
+ "requirement": "Story title must be prefixed with 'Generated/'",
9
+ "example": "title: 'Generated/My Story Name'",
10
+ "enforcement": "Automatic via storyPrefix configuration"
11
+ },
12
+ "rationale": "Keeps generated stories organized and separate from manually created stories"
13
+ },
14
+ "titleFormat": {
15
+ "name": "Story Title Format",
16
+ "rule": "Story titles should be human-readable without technical prefixes",
17
+ "examples": {
18
+ "good": ["Recipe Card", "User Profile", "Navigation Menu"],
19
+ "avoid": ["Generate Recipe Card", "Build User Profile", "Create Navigation Menu"]
20
+ }
21
+ },
22
+ "fileNaming": {
23
+ "name": "Generated File Naming",
24
+ "rule": "Story files should use kebab-case with a unique hash suffix",
25
+ "format": "[descriptive-name]-[8-char-hash].stories.tsx",
26
+ "example": "recipe-card-f7bca0c5.stories.tsx"
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,156 @@
1
+ {
2
+ "libraryName": "Your Component Library",
3
+ "importPath": "your-import-path",
4
+ "description": "Brief description of your component library and its design philosophy",
5
+
6
+ "corePrinciples": [
7
+ "Add fundamental principles of your design system",
8
+ "E.g., 'Always use design tokens for spacing'",
9
+ "E.g., 'Prefer composition over complex components'"
10
+ ],
11
+
12
+ "componentRules": {
13
+ "layout": {
14
+ "description": "How layouts should be structured",
15
+ "rules": [
16
+ "Use Grid component for multi-column layouts",
17
+ "Wrap content in Container for consistent padding"
18
+ ],
19
+ "examples": {
20
+ "twoColumn": "<Grid cols={2}><GridItem>...</GridItem><GridItem>...</GridItem></Grid>",
21
+ "responsive": "<Grid cols={{ base: 1, md: 2, lg: 3 }}>...</Grid>"
22
+ }
23
+ },
24
+ "spacing": {
25
+ "description": "Spacing and sizing system",
26
+ "rules": [
27
+ "Use spacing tokens (space-1, space-2, etc.)",
28
+ "Never use raw pixel values"
29
+ ],
30
+ "validValues": ["space-1", "space-2", "space-4", "space-8", "space-16"]
31
+ },
32
+ "colors": {
33
+ "description": "Color system usage",
34
+ "rules": [
35
+ "Use semantic color tokens (primary, secondary, etc.)",
36
+ "Avoid hex codes or rgb values"
37
+ ],
38
+ "validValues": ["primary", "secondary", "success", "warning", "error"]
39
+ },
40
+ "typography": {
41
+ "description": "Typography rules",
42
+ "rules": [
43
+ "Use Text component for all text",
44
+ "Use semantic size props (sm, md, lg)"
45
+ ]
46
+ }
47
+ },
48
+
49
+ "imports": {
50
+ "primary": {
51
+ "path": "main-package",
52
+ "components": ["Component1", "Component2", "Component3"],
53
+ "description": "Main components imported from the primary package"
54
+ },
55
+ "secondary": [
56
+ {
57
+ "path": "icons-package",
58
+ "components": ["Icon1", "Icon2"],
59
+ "when": "Only when using icons",
60
+ "example": "import { Icon1 } from 'icons-package';"
61
+ },
62
+ {
63
+ "path": "utils-package",
64
+ "components": ["util1", "util2"],
65
+ "when": "For specific utilities",
66
+ "example": "import { util1 } from 'utils-package';"
67
+ }
68
+ ]
69
+ },
70
+
71
+ "patterns": {
72
+ "card": {
73
+ "description": "Standard card pattern",
74
+ "correct": "<Card><CardHeader>Title</CardHeader><CardBody>Content</CardBody></Card>",
75
+ "incorrect": "<div className='card'>...</div>",
76
+ "notes": "Always use Card components, never divs with classes"
77
+ },
78
+ "form": {
79
+ "description": "Form layout pattern",
80
+ "correct": "<Form><FormField label='Name'><Input /></FormField></Form>",
81
+ "incorrect": "<form><label>Name</label><input /></form>",
82
+ "notes": "Use Form components for proper validation and styling"
83
+ },
84
+ "grid": {
85
+ "description": "Grid layout pattern",
86
+ "correct": "<Grid cols={3} gap='space-4'>...</Grid>",
87
+ "incorrect": "<div style={{display: 'grid'}}>...</div>",
88
+ "notes": "Use Grid component with tokens for gaps"
89
+ }
90
+ },
91
+
92
+ "dos": [
93
+ "Use design tokens for all spacing, colors, and sizes",
94
+ "Import components from the official package",
95
+ "Follow composition patterns",
96
+ "Use semantic props (size='lg' not style={{fontSize: '24px'}})"
97
+ ],
98
+
99
+ "donts": [
100
+ "Don't use raw HTML elements when components exist",
101
+ "Don't use inline styles with pixel values",
102
+ "Don't import from internal/private paths",
103
+ "Don't mix different component libraries"
104
+ ],
105
+
106
+ "specialConsiderations": [
107
+ "Component X requires prop Y to be set when using feature Z",
108
+ "Always wrap Component A in Provider B",
109
+ "Theme must be configured before using color props"
110
+ ],
111
+
112
+ "commonMistakes": [
113
+ {
114
+ "issue": "Using HTML div instead of View/Box component",
115
+ "wrong": "<div>Content</div>",
116
+ "correct": "<View>Content</View>",
117
+ "explanation": "Native HTML elements don't respect the design system"
118
+ },
119
+ {
120
+ "issue": "Raw pixel values in spacing",
121
+ "wrong": "margin: '10px'",
122
+ "correct": "margin='space-2'",
123
+ "explanation": "Design tokens ensure consistent spacing"
124
+ }
125
+ ],
126
+
127
+ "aiInstructions": {
128
+ "general": [
129
+ "Always prefer composition over creating complex single components",
130
+ "Use the design system's patterns, don't create custom solutions",
131
+ "When unsure, check the examples in this file"
132
+ ],
133
+ "codeGeneration": [
134
+ "Start with imports from the main package",
135
+ "Use proper TypeScript types when available",
136
+ "Include accessibility props (aria-labels, etc.)"
137
+ ],
138
+ "testing": [
139
+ "Generated components should be testable",
140
+ "Include data-testid props where appropriate"
141
+ ]
142
+ },
143
+
144
+ "examplePrompts": {
145
+ "good": [
146
+ "Create a card with title and description",
147
+ "Build a two-column layout with cards",
148
+ "Make a form with name and email fields"
149
+ ],
150
+ "clarificationNeeded": [
151
+ "Make it pretty -> Specify which components and layout",
152
+ "Add some buttons -> Specify button types and actions",
153
+ "Create a dashboard -> Break down into specific components"
154
+ ]
155
+ }
156
+ }
@@ -0,0 +1,109 @@
1
+ # Story UI AI Considerations
2
+
3
+ This file contains specific instructions and considerations for the AI when generating stories for your component library. You can customize this file to match your design system's requirements.
4
+
5
+ ## Component Library Details
6
+
7
+ **Library Name**: [Your Component Library]
8
+ **Import Path**: `[your-import-path]`
9
+
10
+ ## Core Principles
11
+
12
+ <!-- Add the fundamental principles of your design system -->
13
+ -
14
+ -
15
+ -
16
+
17
+ ## Component Usage Rules
18
+
19
+ ### Layout Components
20
+ <!-- Describe how layouts should be structured -->
21
+ -
22
+ -
23
+ -
24
+
25
+ ### Spacing and Sizing
26
+ <!-- Explain your spacing/sizing system -->
27
+ -
28
+ -
29
+ -
30
+
31
+ ### Color System
32
+ <!-- Describe how colors should be used -->
33
+ -
34
+ -
35
+ -
36
+
37
+ ## Import Guidelines
38
+
39
+ ### Primary Imports
40
+ <!-- List components that should be imported from the main package -->
41
+ ```javascript
42
+ import { Component1, Component2 } from 'main-package';
43
+ ```
44
+
45
+ ### Secondary Imports
46
+ <!-- List any additional packages and when to use them -->
47
+ ```javascript
48
+ // Only for specific use cases:
49
+ import { SpecialUtil } from 'secondary-package';
50
+ ```
51
+
52
+ ## Common Patterns
53
+
54
+ ### Card Layouts
55
+ ```jsx
56
+ // Example of proper card structure
57
+ ```
58
+
59
+ ### Form Layouts
60
+ ```jsx
61
+ // Example of proper form structure
62
+ ```
63
+
64
+ ### Grid Layouts
65
+ ```jsx
66
+ // Example of proper grid structure
67
+ ```
68
+
69
+ ## Do's and Don'ts
70
+
71
+ ### โœ… DO
72
+ -
73
+ -
74
+ -
75
+
76
+ ### โŒ DON'T
77
+ -
78
+ -
79
+ -
80
+
81
+ ## Special Considerations
82
+
83
+ <!-- Add any library-specific quirks or important notes -->
84
+ -
85
+ -
86
+ -
87
+
88
+ ## Examples of Correct Usage
89
+
90
+ ### Example 1: [Component Name]
91
+ ```jsx
92
+ // Show a complete, correct example
93
+ ```
94
+
95
+ ### Example 2: [Component Name]
96
+ ```jsx
97
+ // Show another complete, correct example
98
+ ```
99
+
100
+ ## Error Patterns to Avoid
101
+
102
+ <!-- List common mistakes and how to avoid them -->
103
+ 1. **Wrong**: `<div>...</div>`
104
+ **Right**: `<View>...</View>`
105
+ **Why**: [Explanation]
106
+
107
+ 2. **Wrong**: `style={{margin: '10px'}}`
108
+ **Right**: `margin="size-100"`
109
+ **Why**: [Explanation]
@@ -0,0 +1,55 @@
1
+ # Design System Documentation
2
+
3
+ This directory is automatically discovered by Story UI to enhance AI-generated stories with your design system's specific guidelines, tokens, and patterns.
4
+
5
+ ## Directory Structure
6
+
7
+ Organize your documentation into these categories:
8
+
9
+ ### `guidelines/`
10
+ Design principles, accessibility rules, brand guidelines
11
+ - `accessibility.md` - WCAG compliance, screen reader support
12
+ - `brand-guidelines.md` - Logo usage, voice, tone
13
+ - `responsive-design.md` - Breakpoints, mobile-first rules
14
+
15
+ ### `tokens/`
16
+ Design tokens in JSON or Markdown format
17
+ - `colors.json` - Color palette, semantic colors
18
+ - `spacing.md` - Spacing scale, grid system
19
+ - `typography.json` - Font families, sizes, line heights
20
+ - `shadows.json` - Elevation, shadow tokens
21
+
22
+ ### `components/`
23
+ Component-specific documentation
24
+ - `button.md` - Button variants, usage, examples
25
+ - `forms.md` - Form components, validation patterns
26
+ - `navigation.md` - Menu, breadcrumb patterns
27
+
28
+ ### `patterns/`
29
+ Layout and interaction patterns
30
+ - `forms.md` - Form layout best practices
31
+ - `cards.md` - Card designs and usage
32
+ - `data-tables.md` - Table patterns, sorting, filtering
33
+
34
+ ## Supported Formats
35
+
36
+ - **Markdown** (`.md`) - Rich documentation with examples
37
+ - **JSON** (`.json`) - Structured data like design tokens
38
+ - **HTML** (`.html`) - Complex documentation
39
+ - **Text** (`.txt`) - Simple notes and guidelines
40
+
41
+ ## Usage
42
+
43
+ 1. Add documentation files to the appropriate subdirectories
44
+ 2. Story UI automatically discovers and loads all files
45
+ 3. Documentation content enhances AI story generation
46
+ 4. Files are categorized based on their directory location
47
+
48
+ ## Tips
49
+
50
+ - Use clear, descriptive filenames
51
+ - Include examples and code snippets in Markdown files
52
+ - Structure JSON files with consistent naming conventions
53
+ - Keep documentation up-to-date with your design system
54
+
55
+ When you prompt Story UI to generate stories, this documentation will be automatically included in the AI context to create more accurate, design-system-compliant components.
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- import { validateStoryCode, extractAndValidateCodeBlock } from '../story-generator/validateStory.js';
3
- console.log('๐Ÿงช Testing Story UI validation improvements...\n');
4
- // Test 1: Truncated JSX code
5
- const truncatedJSX = `import React from 'react';
6
- import { Card, Button, Input } from 'antd';
7
-
8
- export default {
9
- title: 'Test/Truncated',
10
- component: Card,
11
- };
12
-
13
- export const Default = {
14
- args: {
15
- children: (
16
- <div>
17
- <Card>
18
- <h1>Hello World</h1>
19
- <Input placeholder="Enter text" />
20
- <Button type="primary">Submit</Button>
21
- <div>
22
- <span>Nested content that gets`;
23
- console.log('Test 1: Truncated JSX code');
24
- const result1 = validateStoryCode(truncatedJSX);
25
- console.log('Valid:', result1.isValid);
26
- console.log('Errors:', result1.errors.length);
27
- if (result1.fixedCode) {
28
- console.log('โœ… Code was automatically fixed!');
29
- console.log('Fixed code ends with:', result1.fixedCode.slice(-100));
30
- }
31
- console.log('\n---\n');
32
- // Test 2: Missing closing braces
33
- const missingBraces = `import React from 'react';
34
- import { Card } from 'antd';
35
-
36
- export default {
37
- title: 'Test/MissingBraces',
38
- component: Card,
39
- };
40
-
41
- export const Default = {
42
- args: {
43
- children: (
44
- <Card>
45
- <h1>Test</h1>
46
- </Card>
47
- )
48
- }`;
49
- console.log('Test 2: Missing closing braces');
50
- const result2 = validateStoryCode(missingBraces);
51
- console.log('Valid:', result2.isValid);
52
- console.log('Errors:', result2.errors.length);
53
- if (result2.fixedCode) {
54
- console.log('โœ… Code was automatically fixed!');
55
- }
56
- console.log('\n---\n');
57
- // Test 3: AI response with code block
58
- const aiResponse = `\`\`\`typescript
59
- import React from 'react';
60
- import { Card, Table } from 'antd';
61
-
62
- export default {
63
- title: 'Test/Dashboard',
64
- component: Card,
65
- };
66
-
67
- export const Default = {
68
- args: {
69
- children: (
70
- <div>
71
- <Card title="Dashboard">
72
- <Table dataSource={[]} columns={[]} />
73
- \`\`\``;
74
- console.log('Test 3: AI response extraction and validation');
75
- const result3 = extractAndValidateCodeBlock(aiResponse);
76
- console.log('Valid:', result3.isValid);
77
- console.log('Errors:', result3.errors.length);
78
- if (result3.fixedCode) {
79
- console.log('โœ… Code was automatically fixed!');
80
- }
81
- console.log('\nโœจ Validation testing complete!');
@@ -1,3 +0,0 @@
1
- export { Button } from './Button';
2
- export { Card } from './Card';
3
- export { Input } from './Input';
@@ -1,3 +0,0 @@
1
- export { Button } from './Button';
2
- export { Card } from './Card';
3
- export { Input } from './Input';
@@ -1 +0,0 @@
1
- {"root":["../index.ts","../story-ui.config.loader.ts","../story-ui.config.ts","../cli/index.ts","../cli/setup.ts","../mcp-server/index.ts","../mcp-server/routes/claude.ts","../mcp-server/routes/components.ts","../mcp-server/routes/generatestory.ts","../mcp-server/routes/memorystories.ts","../mcp-server/routes/storysync.ts","../story-generator/componentdiscovery.ts","../story-generator/configloader.ts","../story-generator/generatestory.ts","../story-generator/gitignoremanager.ts","../story-generator/inmemorystoryservice.ts","../story-generator/productiongitignoremanager.ts","../story-generator/promptgenerator.ts","../story-generator/storysync.ts"],"version":"5.8.3"}