@fragments-sdk/cli 0.2.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.
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +4783 -0
- package/dist/bin.js.map +1 -0
- package/dist/chunk-4FDQSGKX.js +786 -0
- package/dist/chunk-4FDQSGKX.js.map +1 -0
- package/dist/chunk-7H2MMGYG.js +369 -0
- package/dist/chunk-7H2MMGYG.js.map +1 -0
- package/dist/chunk-BSCG3IP7.js +619 -0
- package/dist/chunk-BSCG3IP7.js.map +1 -0
- package/dist/chunk-LY2CFFPY.js +898 -0
- package/dist/chunk-LY2CFFPY.js.map +1 -0
- package/dist/chunk-MUZ6CM66.js +6636 -0
- package/dist/chunk-MUZ6CM66.js.map +1 -0
- package/dist/chunk-OAENNG3G.js +1489 -0
- package/dist/chunk-OAENNG3G.js.map +1 -0
- package/dist/chunk-XHNKNI6J.js +235 -0
- package/dist/chunk-XHNKNI6J.js.map +1 -0
- package/dist/core-DWKLGY4N.js +68 -0
- package/dist/core-DWKLGY4N.js.map +1 -0
- package/dist/generate-4LQNJ7SX.js +249 -0
- package/dist/generate-4LQNJ7SX.js.map +1 -0
- package/dist/index.d.ts +775 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/init-EMVI47QG.js +416 -0
- package/dist/init-EMVI47QG.js.map +1 -0
- package/dist/mcp-bin.d.ts +1 -0
- package/dist/mcp-bin.js +1117 -0
- package/dist/mcp-bin.js.map +1 -0
- package/dist/scan-4YPRF7FV.js +12 -0
- package/dist/scan-4YPRF7FV.js.map +1 -0
- package/dist/service-QSZMZJBJ.js +208 -0
- package/dist/service-QSZMZJBJ.js.map +1 -0
- package/dist/static-viewer-MIPGZ4Z7.js +12 -0
- package/dist/static-viewer-MIPGZ4Z7.js.map +1 -0
- package/dist/test-SQ5ZHXWU.js +1067 -0
- package/dist/test-SQ5ZHXWU.js.map +1 -0
- package/dist/tokens-HSGMYK64.js +173 -0
- package/dist/tokens-HSGMYK64.js.map +1 -0
- package/dist/viewer-YRF4SQE4.js +11101 -0
- package/dist/viewer-YRF4SQE4.js.map +1 -0
- package/package.json +107 -0
- package/src/ai.ts +266 -0
- package/src/analyze.ts +265 -0
- package/src/bin.ts +916 -0
- package/src/build.ts +248 -0
- package/src/commands/a11y.ts +302 -0
- package/src/commands/add.ts +313 -0
- package/src/commands/audit.ts +195 -0
- package/src/commands/baseline.ts +221 -0
- package/src/commands/build.ts +144 -0
- package/src/commands/compare.ts +337 -0
- package/src/commands/context.ts +107 -0
- package/src/commands/dev.ts +107 -0
- package/src/commands/enhance.ts +858 -0
- package/src/commands/generate.ts +391 -0
- package/src/commands/init.ts +531 -0
- package/src/commands/link/figma.ts +645 -0
- package/src/commands/link/index.ts +10 -0
- package/src/commands/link/storybook.ts +267 -0
- package/src/commands/list.ts +49 -0
- package/src/commands/metrics.ts +114 -0
- package/src/commands/reset.ts +242 -0
- package/src/commands/scan.ts +537 -0
- package/src/commands/storygen.ts +207 -0
- package/src/commands/tokens.ts +251 -0
- package/src/commands/validate.ts +93 -0
- package/src/commands/verify.ts +215 -0
- package/src/core/composition.test.ts +262 -0
- package/src/core/composition.ts +255 -0
- package/src/core/config.ts +84 -0
- package/src/core/constants.ts +111 -0
- package/src/core/context.ts +380 -0
- package/src/core/defineSegment.ts +137 -0
- package/src/core/discovery.ts +337 -0
- package/src/core/figma.ts +263 -0
- package/src/core/fragment-types.ts +214 -0
- package/src/core/generators/context.ts +389 -0
- package/src/core/generators/index.ts +23 -0
- package/src/core/generators/registry.ts +364 -0
- package/src/core/generators/typescript-extractor.ts +374 -0
- package/src/core/importAnalyzer.ts +217 -0
- package/src/core/index.ts +149 -0
- package/src/core/loader.ts +155 -0
- package/src/core/node.ts +63 -0
- package/src/core/parser.ts +551 -0
- package/src/core/previewLoader.ts +172 -0
- package/src/core/schema/fragment.schema.json +189 -0
- package/src/core/schema/registry.schema.json +137 -0
- package/src/core/schema.ts +182 -0
- package/src/core/storyAdapter.test.ts +571 -0
- package/src/core/storyAdapter.ts +761 -0
- package/src/core/token-types.ts +287 -0
- package/src/core/types.ts +754 -0
- package/src/diff.ts +323 -0
- package/src/index.ts +43 -0
- package/src/mcp/__tests__/projectFields.test.ts +130 -0
- package/src/mcp/bin.ts +36 -0
- package/src/mcp/index.ts +8 -0
- package/src/mcp/server.ts +1310 -0
- package/src/mcp/utils.ts +54 -0
- package/src/mcp-bin.ts +36 -0
- package/src/migrate/__tests__/argTypes/argTypes.test.ts +189 -0
- package/src/migrate/__tests__/args/args.test.ts +452 -0
- package/src/migrate/__tests__/meta/meta.test.ts +198 -0
- package/src/migrate/__tests__/stories/stories.test.ts +278 -0
- package/src/migrate/__tests__/utils/utils.test.ts +371 -0
- package/src/migrate/__tests__/values/values.test.ts +303 -0
- package/src/migrate/bin.ts +108 -0
- package/src/migrate/converter.ts +658 -0
- package/src/migrate/detect.ts +196 -0
- package/src/migrate/index.ts +45 -0
- package/src/migrate/migrate.ts +163 -0
- package/src/migrate/parser.ts +1136 -0
- package/src/migrate/report.ts +624 -0
- package/src/migrate/types.ts +169 -0
- package/src/screenshot.ts +249 -0
- package/src/service/__tests__/ast-utils.test.ts +426 -0
- package/src/service/__tests__/enhance-scanner.test.ts +200 -0
- package/src/service/__tests__/figma/figma.test.ts +652 -0
- package/src/service/__tests__/metrics-store.test.ts +409 -0
- package/src/service/__tests__/patch-generator.test.ts +186 -0
- package/src/service/__tests__/props-extractor.test.ts +365 -0
- package/src/service/__tests__/token-registry.test.ts +267 -0
- package/src/service/analytics.ts +659 -0
- package/src/service/ast-utils.ts +444 -0
- package/src/service/browser-pool.ts +339 -0
- package/src/service/capture.ts +267 -0
- package/src/service/diff.ts +279 -0
- package/src/service/enhance/aggregator.ts +489 -0
- package/src/service/enhance/cache.ts +275 -0
- package/src/service/enhance/codebase-scanner.ts +357 -0
- package/src/service/enhance/context-generator.ts +529 -0
- package/src/service/enhance/doc-extractor.ts +523 -0
- package/src/service/enhance/index.ts +131 -0
- package/src/service/enhance/props-extractor.ts +665 -0
- package/src/service/enhance/scanner.ts +445 -0
- package/src/service/enhance/storybook-parser.ts +552 -0
- package/src/service/enhance/types.ts +346 -0
- package/src/service/enhance/variant-renderer.ts +479 -0
- package/src/service/figma.ts +1008 -0
- package/src/service/index.ts +249 -0
- package/src/service/metrics-store.ts +333 -0
- package/src/service/patch-generator.ts +349 -0
- package/src/service/report.ts +854 -0
- package/src/service/storage.ts +401 -0
- package/src/service/token-fixes.ts +281 -0
- package/src/service/token-parser.ts +504 -0
- package/src/service/token-registry.ts +721 -0
- package/src/service/utils.ts +172 -0
- package/src/setup.ts +241 -0
- package/src/shared/command-wrapper.ts +81 -0
- package/src/shared/dev-server-client.ts +199 -0
- package/src/shared/index.ts +8 -0
- package/src/shared/segment-loader.ts +59 -0
- package/src/shared/types.ts +147 -0
- package/src/static-viewer.ts +715 -0
- package/src/test/discovery.ts +172 -0
- package/src/test/index.ts +281 -0
- package/src/test/reporters/console.ts +194 -0
- package/src/test/reporters/json.ts +190 -0
- package/src/test/reporters/junit.ts +186 -0
- package/src/test/runner.ts +598 -0
- package/src/test/types.ts +245 -0
- package/src/test/watch.ts +200 -0
- package/src/validators.ts +152 -0
- package/src/viewer/__tests__/jsx-parser.test.ts +502 -0
- package/src/viewer/__tests__/render-utils.test.ts +232 -0
- package/src/viewer/__tests__/style-utils.test.ts +404 -0
- package/src/viewer/bin.ts +86 -0
- package/src/viewer/cli/health.ts +256 -0
- package/src/viewer/cli/index.ts +33 -0
- package/src/viewer/cli/scan.ts +124 -0
- package/src/viewer/cli/utils.ts +174 -0
- package/src/viewer/components/AccessibilityPanel.tsx +1404 -0
- package/src/viewer/components/ActionCapture.tsx +172 -0
- package/src/viewer/components/ActionsPanel.tsx +371 -0
- package/src/viewer/components/App.tsx +638 -0
- package/src/viewer/components/BottomPanel.tsx +224 -0
- package/src/viewer/components/CodePanel.tsx +589 -0
- package/src/viewer/components/CommandPalette.tsx +336 -0
- package/src/viewer/components/ComponentGraph.tsx +394 -0
- package/src/viewer/components/ComponentHeader.tsx +85 -0
- package/src/viewer/components/ContractPanel.tsx +234 -0
- package/src/viewer/components/ErrorBoundary.tsx +85 -0
- package/src/viewer/components/FigmaEmbed.tsx +231 -0
- package/src/viewer/components/FragmentEditor.tsx +485 -0
- package/src/viewer/components/HealthDashboard.tsx +452 -0
- package/src/viewer/components/HmrStatusIndicator.tsx +71 -0
- package/src/viewer/components/Icons.tsx +417 -0
- package/src/viewer/components/InteractionsPanel.tsx +720 -0
- package/src/viewer/components/IsolatedPreviewFrame.tsx +321 -0
- package/src/viewer/components/IsolatedRender.tsx +111 -0
- package/src/viewer/components/KeyboardShortcutsHelp.tsx +89 -0
- package/src/viewer/components/LandingPage.tsx +441 -0
- package/src/viewer/components/Layout.tsx +22 -0
- package/src/viewer/components/LeftSidebar.tsx +391 -0
- package/src/viewer/components/MultiViewportPreview.tsx +429 -0
- package/src/viewer/components/PreviewArea.tsx +404 -0
- package/src/viewer/components/PreviewFrameHost.tsx +310 -0
- package/src/viewer/components/PreviewPane.tsx +150 -0
- package/src/viewer/components/PreviewToolbar.tsx +176 -0
- package/src/viewer/components/PropsEditor.tsx +512 -0
- package/src/viewer/components/PropsTable.tsx +98 -0
- package/src/viewer/components/RelationsSection.tsx +57 -0
- package/src/viewer/components/ResizablePanel.tsx +328 -0
- package/src/viewer/components/RightSidebar.tsx +118 -0
- package/src/viewer/components/ScreenshotButton.tsx +90 -0
- package/src/viewer/components/Sidebar.tsx +169 -0
- package/src/viewer/components/SkeletonLoader.tsx +156 -0
- package/src/viewer/components/StoryRenderer.tsx +128 -0
- package/src/viewer/components/ThemeProvider.tsx +96 -0
- package/src/viewer/components/Toast.tsx +67 -0
- package/src/viewer/components/TokenStylePanel.tsx +708 -0
- package/src/viewer/components/UsageSection.tsx +95 -0
- package/src/viewer/components/VariantMatrix.tsx +350 -0
- package/src/viewer/components/VariantRenderer.tsx +131 -0
- package/src/viewer/components/VariantTabs.tsx +84 -0
- package/src/viewer/components/ViewportSelector.tsx +165 -0
- package/src/viewer/components/_future/CreatePage.tsx +836 -0
- package/src/viewer/composition-renderer.ts +381 -0
- package/src/viewer/constants/index.ts +1 -0
- package/src/viewer/constants/ui.ts +185 -0
- package/src/viewer/entry.tsx +299 -0
- package/src/viewer/hooks/index.ts +2 -0
- package/src/viewer/hooks/useA11yCache.ts +383 -0
- package/src/viewer/hooks/useA11yService.ts +498 -0
- package/src/viewer/hooks/useActions.ts +138 -0
- package/src/viewer/hooks/useAppState.ts +124 -0
- package/src/viewer/hooks/useFigmaIntegration.ts +132 -0
- package/src/viewer/hooks/useHmrStatus.ts +109 -0
- package/src/viewer/hooks/useKeyboardShortcuts.ts +222 -0
- package/src/viewer/hooks/usePreviewBridge.ts +347 -0
- package/src/viewer/hooks/useScrollSpy.ts +78 -0
- package/src/viewer/hooks/useUrlState.ts +330 -0
- package/src/viewer/hooks/useViewSettings.ts +125 -0
- package/src/viewer/index.html +28 -0
- package/src/viewer/index.ts +14 -0
- package/src/viewer/intelligence/healthReport.ts +505 -0
- package/src/viewer/intelligence/styleDrift.ts +340 -0
- package/src/viewer/intelligence/usageScanner.ts +309 -0
- package/src/viewer/jsx-parser.ts +485 -0
- package/src/viewer/postcss.config.js +6 -0
- package/src/viewer/preview-frame-entry.tsx +25 -0
- package/src/viewer/preview-frame.html +109 -0
- package/src/viewer/render-template.html +68 -0
- package/src/viewer/render-utils.ts +170 -0
- package/src/viewer/server.ts +276 -0
- package/src/viewer/style-utils.ts +414 -0
- package/src/viewer/styles/globals.css +355 -0
- package/src/viewer/tailwind.config.js +37 -0
- package/src/viewer/types/a11y.ts +197 -0
- package/src/viewer/utils/a11y-fixes.ts +471 -0
- package/src/viewer/utils/actionExport.ts +372 -0
- package/src/viewer/utils/colorSchemes.ts +201 -0
- package/src/viewer/utils/detectRelationships.ts +256 -0
- package/src/viewer/vite-plugin.ts +2143 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://fragments.dev/schema/v1.json",
|
|
4
|
+
"title": "Fragment",
|
|
5
|
+
"description": "Component enrichment metadata for AI agents and developers",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "JSON Schema reference"
|
|
11
|
+
},
|
|
12
|
+
"name": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Component name (must match the component export name)"
|
|
15
|
+
},
|
|
16
|
+
"description": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Brief description of the component's purpose"
|
|
19
|
+
},
|
|
20
|
+
"figma": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"description": "Figma design links and mappings",
|
|
23
|
+
"properties": {
|
|
24
|
+
"file": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"format": "uri",
|
|
27
|
+
"description": "Figma file URL"
|
|
28
|
+
},
|
|
29
|
+
"nodeId": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Default Figma node ID for this component"
|
|
32
|
+
},
|
|
33
|
+
"variants": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"description": "Mapping of variant names to Figma node IDs",
|
|
36
|
+
"additionalProperties": {
|
|
37
|
+
"type": "string"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"usage": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"description": "Usage guidelines for AI agents and developers",
|
|
45
|
+
"properties": {
|
|
46
|
+
"when": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"description": "Scenarios when this component should be used",
|
|
49
|
+
"items": {
|
|
50
|
+
"type": "string"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"doNot": {
|
|
54
|
+
"type": "array",
|
|
55
|
+
"description": "Anti-patterns and what to use instead",
|
|
56
|
+
"items": {
|
|
57
|
+
"oneOf": [
|
|
58
|
+
{
|
|
59
|
+
"type": "string"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"type": "object",
|
|
63
|
+
"properties": {
|
|
64
|
+
"text": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "What not to do"
|
|
67
|
+
},
|
|
68
|
+
"instead": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"description": "Component name to use instead"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"required": ["text"]
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"patterns": {
|
|
79
|
+
"type": "array",
|
|
80
|
+
"description": "Common usage patterns with code examples",
|
|
81
|
+
"items": {
|
|
82
|
+
"type": "object",
|
|
83
|
+
"properties": {
|
|
84
|
+
"name": {
|
|
85
|
+
"type": "string",
|
|
86
|
+
"description": "Pattern name"
|
|
87
|
+
},
|
|
88
|
+
"code": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"description": "Code example"
|
|
91
|
+
},
|
|
92
|
+
"description": {
|
|
93
|
+
"type": "string",
|
|
94
|
+
"description": "When to use this pattern"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"required": ["name", "code"]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"accessibility": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"description": "Accessibility requirements and guidelines",
|
|
105
|
+
"properties": {
|
|
106
|
+
"role": {
|
|
107
|
+
"type": "string",
|
|
108
|
+
"description": "ARIA role this component implements"
|
|
109
|
+
},
|
|
110
|
+
"requirements": {
|
|
111
|
+
"type": "array",
|
|
112
|
+
"description": "Accessibility requirements",
|
|
113
|
+
"items": {
|
|
114
|
+
"type": "string"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"keyboard": {
|
|
118
|
+
"type": "object",
|
|
119
|
+
"description": "Keyboard interaction patterns",
|
|
120
|
+
"additionalProperties": {
|
|
121
|
+
"type": "string"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"related": {
|
|
127
|
+
"type": "object",
|
|
128
|
+
"description": "Relationships to other components",
|
|
129
|
+
"properties": {
|
|
130
|
+
"similar": {
|
|
131
|
+
"type": "array",
|
|
132
|
+
"description": "Similar components that might be alternatives",
|
|
133
|
+
"items": {
|
|
134
|
+
"type": "string"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"composedWith": {
|
|
138
|
+
"type": "array",
|
|
139
|
+
"description": "Components commonly used together with this one",
|
|
140
|
+
"items": {
|
|
141
|
+
"type": "string"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"usedIn": {
|
|
145
|
+
"type": "array",
|
|
146
|
+
"description": "Parent components or patterns where this is commonly used",
|
|
147
|
+
"items": {
|
|
148
|
+
"type": "string"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
"meta": {
|
|
154
|
+
"type": "object",
|
|
155
|
+
"description": "Administrative metadata",
|
|
156
|
+
"properties": {
|
|
157
|
+
"owner": {
|
|
158
|
+
"type": "string",
|
|
159
|
+
"description": "Team or person responsible for this component"
|
|
160
|
+
},
|
|
161
|
+
"status": {
|
|
162
|
+
"type": "string",
|
|
163
|
+
"enum": ["draft", "experimental", "beta", "stable", "deprecated"],
|
|
164
|
+
"description": "Component lifecycle status"
|
|
165
|
+
},
|
|
166
|
+
"since": {
|
|
167
|
+
"type": "string",
|
|
168
|
+
"description": "Version when this component was introduced"
|
|
169
|
+
},
|
|
170
|
+
"deprecatedSince": {
|
|
171
|
+
"type": "string",
|
|
172
|
+
"description": "Version when this component was deprecated"
|
|
173
|
+
},
|
|
174
|
+
"deprecatedReason": {
|
|
175
|
+
"type": "string",
|
|
176
|
+
"description": "Why this component was deprecated and what to use instead"
|
|
177
|
+
},
|
|
178
|
+
"tags": {
|
|
179
|
+
"type": "array",
|
|
180
|
+
"description": "Tags for categorization and search",
|
|
181
|
+
"items": {
|
|
182
|
+
"type": "string"
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"required": ["name"]
|
|
189
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://fragments.dev/schema/registry-v1.json",
|
|
4
|
+
"title": "Fragment Registry",
|
|
5
|
+
"description": "Auto-generated component index with resolved paths and extracted metadata",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "JSON Schema reference"
|
|
11
|
+
},
|
|
12
|
+
"version": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Schema version"
|
|
15
|
+
},
|
|
16
|
+
"generatedAt": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"format": "date-time",
|
|
19
|
+
"description": "When this registry was generated"
|
|
20
|
+
},
|
|
21
|
+
"projectRoot": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Absolute path to the project root"
|
|
24
|
+
},
|
|
25
|
+
"components": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"description": "Component index keyed by component name",
|
|
28
|
+
"additionalProperties": {
|
|
29
|
+
"$ref": "#/$defs/ComponentEntry"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"categories": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"description": "Components grouped by category",
|
|
35
|
+
"additionalProperties": {
|
|
36
|
+
"type": "array",
|
|
37
|
+
"items": {
|
|
38
|
+
"type": "string"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"required": ["version", "generatedAt", "components"],
|
|
44
|
+
"$defs": {
|
|
45
|
+
"ComponentEntry": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"description": "Component registry entry with resolved paths and metadata",
|
|
48
|
+
"properties": {
|
|
49
|
+
"path": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "Relative path to the component source file"
|
|
52
|
+
},
|
|
53
|
+
"fragmentPath": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"description": "Relative path to the .fragment.json file"
|
|
56
|
+
},
|
|
57
|
+
"storyPath": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "Relative path to the .stories.tsx file (if exists)"
|
|
60
|
+
},
|
|
61
|
+
"category": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "Component category"
|
|
64
|
+
},
|
|
65
|
+
"status": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"enum": ["draft", "experimental", "beta", "stable", "deprecated"],
|
|
68
|
+
"description": "Component lifecycle status"
|
|
69
|
+
},
|
|
70
|
+
"description": {
|
|
71
|
+
"type": "string",
|
|
72
|
+
"description": "Component description"
|
|
73
|
+
},
|
|
74
|
+
"props": {
|
|
75
|
+
"type": "object",
|
|
76
|
+
"description": "Extracted prop definitions",
|
|
77
|
+
"additionalProperties": {
|
|
78
|
+
"$ref": "#/$defs/PropEntry"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"exports": {
|
|
82
|
+
"type": "array",
|
|
83
|
+
"description": "Named exports from the component file",
|
|
84
|
+
"items": {
|
|
85
|
+
"type": "string"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"type": "array",
|
|
90
|
+
"description": "Component dependencies (other components used)",
|
|
91
|
+
"items": {
|
|
92
|
+
"type": "string"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"fragment": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"description": "Merged fragment enrichment data",
|
|
98
|
+
"additionalProperties": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"required": ["path"]
|
|
102
|
+
},
|
|
103
|
+
"PropEntry": {
|
|
104
|
+
"type": "object",
|
|
105
|
+
"description": "Extracted prop definition",
|
|
106
|
+
"properties": {
|
|
107
|
+
"type": {
|
|
108
|
+
"type": "string",
|
|
109
|
+
"description": "TypeScript type (e.g., 'string', 'boolean', enum values)"
|
|
110
|
+
},
|
|
111
|
+
"typeKind": {
|
|
112
|
+
"type": "string",
|
|
113
|
+
"enum": ["string", "number", "boolean", "enum", "object", "array", "function", "node", "element", "union", "unknown"],
|
|
114
|
+
"description": "Simplified type category"
|
|
115
|
+
},
|
|
116
|
+
"options": {
|
|
117
|
+
"type": "array",
|
|
118
|
+
"description": "For enum types, the allowed values",
|
|
119
|
+
"items": {
|
|
120
|
+
"type": "string"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"default": {
|
|
124
|
+
"description": "Default value if specified"
|
|
125
|
+
},
|
|
126
|
+
"required": {
|
|
127
|
+
"type": "boolean",
|
|
128
|
+
"description": "Whether this prop is required"
|
|
129
|
+
},
|
|
130
|
+
"description": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"description": "Prop description from JSDoc or TypeScript"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schemas for runtime validation of segment definitions
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Figma property mapping schemas
|
|
8
|
+
const figmaStringMappingSchema = z.object({
|
|
9
|
+
__type: z.literal('figma-string'),
|
|
10
|
+
figmaProperty: z.string().min(1),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const figmaBooleanMappingSchema = z.object({
|
|
14
|
+
__type: z.literal('figma-boolean'),
|
|
15
|
+
figmaProperty: z.string().min(1),
|
|
16
|
+
valueMapping: z.object({ true: z.unknown(), false: z.unknown() }).optional(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const figmaEnumMappingSchema = z.object({
|
|
20
|
+
__type: z.literal('figma-enum'),
|
|
21
|
+
figmaProperty: z.string().min(1),
|
|
22
|
+
valueMapping: z.record(z.unknown()),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const figmaInstanceMappingSchema = z.object({
|
|
26
|
+
__type: z.literal('figma-instance'),
|
|
27
|
+
figmaProperty: z.string().min(1),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const figmaChildrenMappingSchema = z.object({
|
|
31
|
+
__type: z.literal('figma-children'),
|
|
32
|
+
layers: z.array(z.string().min(1)),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const figmaTextContentMappingSchema = z.object({
|
|
36
|
+
__type: z.literal('figma-text-content'),
|
|
37
|
+
layer: z.string().min(1),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const figmaPropMappingSchema = z.discriminatedUnion('__type', [
|
|
41
|
+
figmaStringMappingSchema,
|
|
42
|
+
figmaBooleanMappingSchema,
|
|
43
|
+
figmaEnumMappingSchema,
|
|
44
|
+
figmaInstanceMappingSchema,
|
|
45
|
+
figmaChildrenMappingSchema,
|
|
46
|
+
figmaTextContentMappingSchema,
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export const segmentMetaSchema = z.object({
|
|
50
|
+
name: z.string().min(1),
|
|
51
|
+
description: z.string().min(1),
|
|
52
|
+
category: z.string().min(1),
|
|
53
|
+
tags: z.array(z.string()).optional(),
|
|
54
|
+
status: z.enum(['stable', 'beta', 'deprecated', 'experimental']).optional(),
|
|
55
|
+
since: z.string().optional(),
|
|
56
|
+
figma: z.string().url().optional(),
|
|
57
|
+
figmaProps: z.record(figmaPropMappingSchema).optional(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const segmentUsageSchema = z.object({
|
|
61
|
+
when: z.array(z.string()).min(1),
|
|
62
|
+
whenNot: z.array(z.string()).min(1),
|
|
63
|
+
guidelines: z.array(z.string()).optional(),
|
|
64
|
+
accessibility: z.array(z.string()).optional(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const propTypeSchema: z.ZodType<string> = z.enum([
|
|
68
|
+
'string',
|
|
69
|
+
'number',
|
|
70
|
+
'boolean',
|
|
71
|
+
'enum',
|
|
72
|
+
'function',
|
|
73
|
+
'node',
|
|
74
|
+
'element',
|
|
75
|
+
'object',
|
|
76
|
+
'array',
|
|
77
|
+
'union',
|
|
78
|
+
'custom',
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
export const propDefinitionSchema = z.object({
|
|
82
|
+
type: propTypeSchema,
|
|
83
|
+
values: z.array(z.string()).readonly().optional(),
|
|
84
|
+
default: z.unknown().optional(),
|
|
85
|
+
description: z.string().optional(),
|
|
86
|
+
required: z.boolean().optional(),
|
|
87
|
+
constraints: z.array(z.string()).optional(),
|
|
88
|
+
typeDetails: z.record(z.unknown()).optional(),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export const relationshipTypeSchema = z.enum([
|
|
92
|
+
'alternative',
|
|
93
|
+
'sibling',
|
|
94
|
+
'parent',
|
|
95
|
+
'child',
|
|
96
|
+
'composition',
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
export const componentRelationSchema = z.object({
|
|
100
|
+
component: z.string().min(1),
|
|
101
|
+
relationship: relationshipTypeSchema,
|
|
102
|
+
note: z.string().min(1),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const segmentVariantSchema = z.object({
|
|
106
|
+
name: z.string().min(1),
|
|
107
|
+
description: z.string().min(1),
|
|
108
|
+
render: z.function().returns(z.unknown()),
|
|
109
|
+
code: z.string().optional(),
|
|
110
|
+
figma: z.string().url().optional(),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Schema for banned patterns in codebase
|
|
115
|
+
*/
|
|
116
|
+
export const segmentBanSchema = z.object({
|
|
117
|
+
pattern: z.string().min(1),
|
|
118
|
+
message: z.string().min(1),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Schema for agent-optimized contract metadata
|
|
123
|
+
*/
|
|
124
|
+
export const segmentContractSchema = z.object({
|
|
125
|
+
propsSummary: z.array(z.string()).optional(),
|
|
126
|
+
a11yRules: z.array(z.string()).optional(),
|
|
127
|
+
bans: z.array(segmentBanSchema).optional(),
|
|
128
|
+
scenarioTags: z.array(z.string()).optional(),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Schema for provenance tracking of generated segments
|
|
133
|
+
*/
|
|
134
|
+
export const segmentGeneratedSchema = z.object({
|
|
135
|
+
source: z.enum(['storybook', 'manual', 'ai']),
|
|
136
|
+
sourceFile: z.string().optional(),
|
|
137
|
+
confidence: z.number().min(0).max(1).optional(),
|
|
138
|
+
timestamp: z.string().datetime().optional(),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Schema for recipe definitions
|
|
143
|
+
*/
|
|
144
|
+
export const recipeDefinitionSchema = z.object({
|
|
145
|
+
name: z.string().min(1),
|
|
146
|
+
description: z.string().min(1),
|
|
147
|
+
category: z.string().min(1),
|
|
148
|
+
components: z.array(z.string().min(1)).min(1),
|
|
149
|
+
code: z.string().min(1),
|
|
150
|
+
tags: z.array(z.string()).optional(),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export const segmentDefinitionSchema = z.object({
|
|
154
|
+
component: z.any(), // Allow any component type (function, class, forwardRef, etc.)
|
|
155
|
+
meta: segmentMetaSchema,
|
|
156
|
+
usage: segmentUsageSchema,
|
|
157
|
+
props: z.record(propDefinitionSchema),
|
|
158
|
+
relations: z.array(componentRelationSchema).optional(),
|
|
159
|
+
variants: z.array(segmentVariantSchema), // Allow empty variants array
|
|
160
|
+
contract: segmentContractSchema.optional(),
|
|
161
|
+
_generated: segmentGeneratedSchema.optional(),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Config schema - validates required fields, passes through optional config objects.
|
|
166
|
+
* Type definitions are in types.ts - schema just ensures basic structure.
|
|
167
|
+
*/
|
|
168
|
+
export const segmentsConfigSchema = z.object({
|
|
169
|
+
include: z.array(z.string()).min(1),
|
|
170
|
+
exclude: z.array(z.string()).optional(),
|
|
171
|
+
components: z.array(z.string()).optional(),
|
|
172
|
+
outFile: z.string().optional(),
|
|
173
|
+
framework: z.enum(['react', 'vue', 'svelte']).optional(),
|
|
174
|
+
figmaFile: z.string().url().optional(),
|
|
175
|
+
figmaToken: z.string().optional(),
|
|
176
|
+
screenshots: z.object({}).passthrough().optional(),
|
|
177
|
+
service: z.object({}).passthrough().optional(),
|
|
178
|
+
registry: z.object({}).passthrough().optional(),
|
|
179
|
+
tokens: z.object({
|
|
180
|
+
include: z.array(z.string()).min(1),
|
|
181
|
+
}).passthrough().optional(),
|
|
182
|
+
});
|