specweave 0.23.18 → 0.24.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 (174) hide show
  1. package/.claude-plugin/marketplace.json +144 -45
  2. package/CLAUDE.md +137 -4
  3. package/dist/src/cli/helpers/ado-area-path-mapper.d.ts +89 -0
  4. package/dist/src/cli/helpers/ado-area-path-mapper.d.ts.map +1 -0
  5. package/dist/src/cli/helpers/ado-area-path-mapper.js +213 -0
  6. package/dist/src/cli/helpers/ado-area-path-mapper.js.map +1 -0
  7. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.d.ts +29 -0
  8. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.d.ts.map +1 -0
  9. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.js +109 -0
  10. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.js.map +1 -0
  11. package/dist/src/cli/helpers/issue-tracker/ado.d.ts +1 -0
  12. package/dist/src/cli/helpers/issue-tracker/ado.d.ts.map +1 -1
  13. package/dist/src/cli/helpers/issue-tracker/ado.js +2 -0
  14. package/dist/src/cli/helpers/issue-tracker/ado.js.map +1 -1
  15. package/dist/src/cli/helpers/smart-filter.d.ts +83 -0
  16. package/dist/src/cli/helpers/smart-filter.d.ts.map +1 -0
  17. package/dist/src/cli/helpers/smart-filter.js +265 -0
  18. package/dist/src/cli/helpers/smart-filter.js.map +1 -0
  19. package/dist/src/core/qa/quality-gate-decider.d.ts +1 -1
  20. package/dist/src/core/qa/quality-gate-decider.js +2 -2
  21. package/dist/src/core/qa/quality-gate-decider.js.map +1 -1
  22. package/dist/src/core/qa/risk-calculator.d.ts +2 -2
  23. package/dist/src/core/qa/risk-calculator.js +2 -2
  24. package/dist/src/core/repo-structure/repo-structure-manager.d.ts.map +1 -1
  25. package/dist/src/core/repo-structure/repo-structure-manager.js +76 -43
  26. package/dist/src/core/repo-structure/repo-structure-manager.js.map +1 -1
  27. package/dist/src/core/validators/ac-presence-validator.d.ts +56 -0
  28. package/dist/src/core/validators/ac-presence-validator.d.ts.map +1 -0
  29. package/dist/src/core/validators/ac-presence-validator.js +149 -0
  30. package/dist/src/core/validators/ac-presence-validator.js.map +1 -0
  31. package/dist/src/integrations/ado/area-path-mapper.d.ts +137 -0
  32. package/dist/src/integrations/ado/area-path-mapper.d.ts.map +1 -0
  33. package/dist/src/integrations/ado/area-path-mapper.js +267 -0
  34. package/dist/src/integrations/ado/area-path-mapper.js.map +1 -0
  35. package/dist/src/integrations/jira/filter-processor.d.ts +126 -0
  36. package/dist/src/integrations/jira/filter-processor.d.ts.map +1 -0
  37. package/dist/src/integrations/jira/filter-processor.js +207 -0
  38. package/dist/src/integrations/jira/filter-processor.js.map +1 -0
  39. package/dist/src/integrations/jira/jira-client.d.ts +13 -0
  40. package/dist/src/integrations/jira/jira-client.d.ts.map +1 -1
  41. package/dist/src/integrations/jira/jira-client.js +33 -0
  42. package/dist/src/integrations/jira/jira-client.js.map +1 -1
  43. package/dist/src/utils/ac-embedder.d.ts +63 -0
  44. package/dist/src/utils/ac-embedder.d.ts.map +1 -0
  45. package/dist/src/utils/ac-embedder.js +217 -0
  46. package/dist/src/utils/ac-embedder.js.map +1 -0
  47. package/dist/src/utils/env-manager.d.ts +86 -0
  48. package/dist/src/utils/env-manager.d.ts.map +1 -0
  49. package/dist/src/utils/env-manager.js +188 -0
  50. package/dist/src/utils/env-manager.js.map +1 -0
  51. package/package.json +1 -1
  52. package/plugins/specweave/.claude-plugin/plugin.json +1 -1
  53. package/plugins/specweave/agents/AGENTS-INDEX.md +1 -1
  54. package/plugins/specweave/agents/increment-quality-judge-v2/AGENT.md +9 -9
  55. package/plugins/specweave/commands/specweave-do.md +37 -0
  56. package/plugins/specweave/commands/specweave-done.md +159 -0
  57. package/plugins/specweave/commands/specweave-embed-acs.md +446 -0
  58. package/plugins/specweave/commands/specweave-next.md +148 -3
  59. package/plugins/specweave/commands/specweave-qa.md +2 -2
  60. package/plugins/specweave/hooks/pre-increment-start.sh +168 -0
  61. package/plugins/specweave/skills/SKILLS-INDEX.md +1 -1
  62. package/plugins/specweave-ado/.claude-plugin/plugin.json +1 -1
  63. package/plugins/specweave-ado/commands/specweave-ado-import-projects.md +331 -0
  64. package/plugins/specweave-alternatives/.claude-plugin/plugin.json +10 -0
  65. package/plugins/specweave-alternatives/commands/alternatives-analyze.md +336 -0
  66. package/plugins/specweave-alternatives/skills/architecture-alternatives/SKILL.md +651 -0
  67. package/plugins/specweave-alternatives/skills/bmad-method/SKILL.md +420 -0
  68. package/plugins/specweave-alternatives/skills/spec-kit-expert/SKILL.md +487 -0
  69. package/plugins/specweave-backend/commands/api-scaffold.md +80 -0
  70. package/plugins/specweave-backend/commands/crud-generate.md +109 -0
  71. package/plugins/specweave-backend/commands/migration-generate.md +139 -0
  72. package/plugins/specweave-confluent/commands/connector-deploy.md +154 -0
  73. package/plugins/specweave-confluent/commands/ksqldb-query.md +179 -0
  74. package/plugins/specweave-confluent/commands/schema-register.md +123 -0
  75. package/plugins/specweave-core/.claude-plugin/plugin.json +21 -0
  76. package/plugins/specweave-core/commands/architecture-review.md +288 -0
  77. package/plugins/specweave-core/commands/code-review.md +213 -0
  78. package/plugins/specweave-core/commands/refactor-plan.md +249 -0
  79. package/plugins/specweave-core/skills/code-quality/SKILL.md +157 -0
  80. package/plugins/specweave-core/skills/design-patterns/SKILL.md +244 -0
  81. package/plugins/specweave-core/skills/software-architecture/SKILL.md +83 -0
  82. package/plugins/specweave-cost-optimizer/.claude-plugin/plugin.json +22 -0
  83. package/plugins/specweave-cost-optimizer/commands/cost-analyze.md +360 -0
  84. package/plugins/specweave-cost-optimizer/commands/cost-optimize.md +480 -0
  85. package/plugins/specweave-cost-optimizer/skills/aws-cost-expert/SKILL.md +416 -0
  86. package/plugins/specweave-cost-optimizer/skills/cloud-pricing/SKILL.md +325 -0
  87. package/plugins/specweave-cost-optimizer/skills/cost-optimization/SKILL.md +337 -0
  88. package/plugins/specweave-diagrams/.claude-plugin/plugin.json +1 -1
  89. package/plugins/specweave-diagrams/commands/diagrams-generate.md +168 -0
  90. package/plugins/specweave-docs/.claude-plugin/plugin.json +10 -0
  91. package/plugins/specweave-docs/commands/docs-generate.md +441 -0
  92. package/plugins/specweave-docs/commands/docs-init.md +334 -0
  93. package/plugins/specweave-docs/skills/docusaurus/SKILL.md +581 -0
  94. package/plugins/specweave-docs/skills/spec-driven-brainstorming/SKILL.md +689 -0
  95. package/plugins/specweave-docs/skills/technical-writing/SKILL.md +1039 -0
  96. package/plugins/specweave-docs-preview/.claude-plugin/plugin.json +1 -1
  97. package/plugins/specweave-figma/.claude-plugin/plugin.json +23 -0
  98. package/plugins/specweave-figma/commands/figma-import.md +690 -0
  99. package/plugins/specweave-figma/commands/figma-to-react.md +834 -0
  100. package/plugins/specweave-figma/commands/figma-tokens.md +815 -0
  101. package/plugins/specweave-frontend/.claude-plugin/plugin.json +21 -0
  102. package/plugins/specweave-frontend/agents/frontend-architect/AGENT.md +408 -0
  103. package/plugins/specweave-frontend/agents/frontend-architect/README.md +385 -0
  104. package/plugins/specweave-frontend/agents/frontend-architect/examples.md +590 -0
  105. package/plugins/specweave-frontend/agents/frontend-architect/templates/component-template.tsx +152 -0
  106. package/plugins/specweave-frontend/agents/frontend-architect/templates/hook-template.ts +311 -0
  107. package/plugins/specweave-frontend/agents/frontend-architect/templates/page-template.tsx +228 -0
  108. package/plugins/specweave-frontend/commands/component-generate.md +510 -0
  109. package/plugins/specweave-frontend/commands/design-system-init.md +494 -0
  110. package/plugins/specweave-frontend/commands/frontend-scaffold.md +207 -0
  111. package/plugins/specweave-frontend/commands/nextjs-setup.md +396 -0
  112. package/plugins/specweave-frontend/skills/design-system-architect/SKILL.md +278 -0
  113. package/plugins/specweave-frontend/skills/frontend/SKILL.md +420 -0
  114. package/plugins/specweave-frontend/skills/nextjs/SKILL.md +546 -0
  115. package/plugins/specweave-github/.claude-plugin/plugin.json +1 -1
  116. package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +212 -0
  117. package/plugins/specweave-infrastructure/.claude-plugin/plugin.json +1 -1
  118. package/plugins/specweave-jira/.claude-plugin/plugin.json +1 -1
  119. package/plugins/specweave-jira/commands/import-projects.js +183 -0
  120. package/plugins/specweave-jira/commands/import-projects.md +97 -0
  121. package/plugins/specweave-jira/commands/import-projects.ts +288 -0
  122. package/plugins/specweave-jira/commands/specweave-jira-import-projects.md +298 -0
  123. package/plugins/specweave-kafka/.claude-plugin/plugin.json +1 -1
  124. package/plugins/specweave-kafka-streams/.claude-plugin/plugin.json +1 -1
  125. package/plugins/specweave-kubernetes/commands/cluster-setup.md +262 -0
  126. package/plugins/specweave-kubernetes/commands/deployment-generate.md +242 -0
  127. package/plugins/specweave-kubernetes/commands/helm-scaffold.md +333 -0
  128. package/plugins/specweave-ml/.claude-plugin/plugin.json +1 -1
  129. package/plugins/specweave-mobile/commands/app-scaffold.md +233 -0
  130. package/plugins/specweave-mobile/commands/build-config.md +256 -0
  131. package/plugins/specweave-mobile/commands/screen-generate.md +289 -0
  132. package/plugins/specweave-n8n/.claude-plugin/plugin.json +1 -1
  133. package/plugins/specweave-payments/commands/stripe-setup.md +931 -0
  134. package/plugins/specweave-payments/commands/subscription-flow.md +1193 -0
  135. package/plugins/specweave-payments/commands/subscription-manage.md +386 -0
  136. package/plugins/specweave-payments/commands/webhook-setup.md +295 -0
  137. package/plugins/specweave-plugin-dev/.claude-plugin/plugin.json +13 -12
  138. package/plugins/specweave-plugin-dev/commands/plugin-create.md +333 -0
  139. package/plugins/specweave-plugin-dev/commands/plugin-publish.md +339 -0
  140. package/plugins/specweave-plugin-dev/commands/plugin-test.md +293 -0
  141. package/plugins/specweave-plugin-dev/skills/claude-sdk/SKILL.md +162 -0
  142. package/plugins/specweave-plugin-dev/skills/marketplace-publishing/SKILL.md +263 -0
  143. package/plugins/specweave-plugin-dev/skills/plugin-development/SKILL.md +316 -0
  144. package/plugins/specweave-release/.claude-plugin/plugin.json +1 -1
  145. package/plugins/specweave-release/commands/specweave-release-npm.md +110 -0
  146. package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +168 -0
  147. package/plugins/specweave-testing/.claude-plugin/plugin.json +21 -0
  148. package/plugins/specweave-testing/agents/qa-engineer/AGENT.md +818 -0
  149. package/plugins/specweave-testing/agents/qa-engineer/README.md +443 -0
  150. package/plugins/specweave-testing/agents/qa-engineer/templates/playwright-e2e-test.ts +470 -0
  151. package/plugins/specweave-testing/agents/qa-engineer/templates/test-data-factory.ts +507 -0
  152. package/plugins/specweave-testing/agents/qa-engineer/templates/vitest-unit-test.ts +400 -0
  153. package/plugins/specweave-testing/agents/qa-engineer/test-strategies.md +726 -0
  154. package/plugins/specweave-testing/commands/e2e-setup.md +1081 -0
  155. package/plugins/specweave-testing/commands/test-coverage.md +979 -0
  156. package/plugins/specweave-testing/commands/test-generate.md +1156 -0
  157. package/plugins/specweave-testing/commands/test-init.md +409 -0
  158. package/plugins/specweave-testing/skills/e2e-playwright/SKILL.md +769 -0
  159. package/plugins/specweave-testing/skills/tdd-expert/SKILL.md +934 -0
  160. package/plugins/specweave-testing/skills/unit-testing-expert/SKILL.md +1011 -0
  161. package/plugins/specweave-tooling/.claude-plugin/plugin.json +22 -0
  162. package/plugins/specweave-tooling/commands/specweave-tooling-skill-create.md +691 -0
  163. package/plugins/specweave-tooling/commands/specweave-tooling-skill-package.md +751 -0
  164. package/plugins/specweave-tooling/commands/specweave-tooling-skill-validate.md +858 -0
  165. package/plugins/specweave-ui/.claude-plugin/plugin.json +10 -0
  166. package/plugins/specweave-ui/commands/ui-automate.md +199 -0
  167. package/plugins/specweave-ui/commands/ui-inspect.md +70 -0
  168. package/plugins/specweave-ui/skills/browser-automation/SKILL.md +314 -0
  169. package/plugins/specweave-ui/skills/ui-testing/SKILL.md +716 -0
  170. package/plugins/specweave-ui/skills/visual-regression/SKILL.md +728 -0
  171. package/plugins/specweave/commands/check-hooks.md +0 -257
  172. package/plugins/specweave/commands/specweave-archive-increments.md +0 -82
  173. package/plugins/specweave-plugin-dev/skills/plugin-expert/SKILL.md +0 -1231
  174. /package/plugins/specweave/{agents/code-reviewer.md → skills/code-reviewer/SKILL.md} +0 -0
@@ -0,0 +1,815 @@
1
+ # /specweave-figma:tokens
2
+
3
+ Extract design tokens from Figma and generate token files for theme configuration (CSS variables, JavaScript, JSON, SCSS).
4
+
5
+ You are a design token expert who automates design system token extraction and synchronization from Figma.
6
+
7
+ ## Your Task
8
+
9
+ Extract design tokens (colors, typography, spacing, shadows, borders) from Figma and generate production-ready token files in multiple formats.
10
+
11
+ ### 1. Design Token Standards
12
+
13
+ **W3C Design Tokens Format** (Recommended):
14
+ ```json
15
+ {
16
+ "colors": {
17
+ "brand": {
18
+ "primary": {
19
+ "$type": "color",
20
+ "$value": "#0066FF",
21
+ "$description": "Primary brand color"
22
+ },
23
+ "secondary": {
24
+ "$type": "color",
25
+ "$value": "#00CC66"
26
+ }
27
+ }
28
+ },
29
+ "typography": {
30
+ "heading": {
31
+ "h1": {
32
+ "$type": "typography",
33
+ "$value": {
34
+ "fontFamily": "Inter",
35
+ "fontSize": "48px",
36
+ "fontWeight": 700,
37
+ "lineHeight": 1.2
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ **Token Categories**:
46
+ - Colors (brand, semantic, grayscale)
47
+ - Typography (font families, sizes, weights, line heights)
48
+ - Spacing (margins, paddings, gaps)
49
+ - Border radius (corners)
50
+ - Shadows (elevations)
51
+ - Borders (widths, styles)
52
+ - Breakpoints (responsive)
53
+ - Z-index (layering)
54
+ - Transitions (animations)
55
+
56
+ ### 2. Figma Token Extraction
57
+
58
+ **Extract Color Tokens from Styles**:
59
+
60
+ ```typescript
61
+ import { FigmaImporter } from './figma-importer';
62
+
63
+ interface ColorToken {
64
+ name: string;
65
+ value: string;
66
+ rgba: { r: number; g: number; b: number; a: number };
67
+ type: 'solid' | 'gradient';
68
+ description?: string;
69
+ }
70
+
71
+ async function extractColorTokens(fileKey: string): Promise<ColorToken[]> {
72
+ const importer = new FigmaImporter({
73
+ accessToken: process.env.FIGMA_ACCESS_TOKEN!,
74
+ fileKey,
75
+ });
76
+
77
+ const file = await importer.fetchFile();
78
+ const styles = await importer.fetchStyles();
79
+
80
+ const colorTokens: ColorToken[] = [];
81
+
82
+ for (const style of styles) {
83
+ if (style.style_type === 'FILL') {
84
+ const node = findNodeById(file.document, style.node_id);
85
+
86
+ if (node?.fills?.[0]) {
87
+ const fill = node.fills[0];
88
+
89
+ if (fill.type === 'SOLID') {
90
+ colorTokens.push({
91
+ name: style.name,
92
+ value: rgbaToHex(fill.color, fill.opacity),
93
+ rgba: {
94
+ r: fill.color.r,
95
+ g: fill.color.g,
96
+ b: fill.color.b,
97
+ a: fill.opacity ?? 1,
98
+ },
99
+ type: 'solid',
100
+ description: style.description || undefined,
101
+ });
102
+ } else if (fill.type === 'GRADIENT_LINEAR') {
103
+ colorTokens.push({
104
+ name: style.name,
105
+ value: convertGradientToCSS(fill),
106
+ rgba: fill.gradientStops[0].color,
107
+ type: 'gradient',
108
+ description: style.description,
109
+ });
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ return colorTokens;
116
+ }
117
+
118
+ function rgbaToHex(color: { r: number; g: number; b: number }, opacity = 1): string {
119
+ const r = Math.round(color.r * 255);
120
+ const g = Math.round(color.g * 255);
121
+ const b = Math.round(color.b * 255);
122
+
123
+ if (opacity < 1) {
124
+ const a = Math.round(opacity * 255);
125
+ return `#${[r, g, b, a].map(x => x.toString(16).padStart(2, '0')).join('')}`;
126
+ }
127
+
128
+ return `#${[r, g, b].map(x => x.toString(16).padStart(2, '0')).join('')}`;
129
+ }
130
+ ```
131
+
132
+ **Extract Typography Tokens**:
133
+
134
+ ```typescript
135
+ interface TypographyToken {
136
+ name: string;
137
+ fontFamily: string;
138
+ fontSize: number;
139
+ fontWeight: number;
140
+ lineHeight: number;
141
+ letterSpacing?: number;
142
+ textTransform?: 'none' | 'uppercase' | 'lowercase' | 'capitalize';
143
+ description?: string;
144
+ }
145
+
146
+ async function extractTypographyTokens(fileKey: string): Promise<TypographyToken[]> {
147
+ const importer = new FigmaImporter({
148
+ accessToken: process.env.FIGMA_ACCESS_TOKEN!,
149
+ fileKey,
150
+ });
151
+
152
+ const file = await importer.fetchFile();
153
+ const styles = await importer.fetchStyles();
154
+
155
+ const typographyTokens: TypographyToken[] = [];
156
+
157
+ for (const style of styles) {
158
+ if (style.style_type === 'TEXT') {
159
+ const node = findNodeById(file.document, style.node_id);
160
+
161
+ if (node?.style) {
162
+ typographyTokens.push({
163
+ name: style.name,
164
+ fontFamily: node.style.fontFamily,
165
+ fontSize: node.style.fontSize,
166
+ fontWeight: node.style.fontWeight,
167
+ lineHeight: node.style.lineHeightPx / node.style.fontSize,
168
+ letterSpacing: node.style.letterSpacing || undefined,
169
+ textTransform: node.style.textCase?.toLowerCase() as any,
170
+ description: style.description,
171
+ });
172
+ }
173
+ }
174
+ }
175
+
176
+ return typographyTokens;
177
+ }
178
+ ```
179
+
180
+ **Extract Spacing Tokens from Auto Layout**:
181
+
182
+ ```typescript
183
+ interface SpacingToken {
184
+ name: string;
185
+ value: number;
186
+ description?: string;
187
+ }
188
+
189
+ async function extractSpacingTokens(fileKey: string): Promise<SpacingToken[]> {
190
+ const importer = new FigmaImporter({
191
+ accessToken: process.env.FIGMA_ACCESS_TOKEN!,
192
+ fileKey,
193
+ });
194
+
195
+ const file = await importer.fetchFile();
196
+
197
+ const spacingValues = new Set<number>();
198
+
199
+ // Traverse all frames with auto layout
200
+ traverseNodes(file.document, (node) => {
201
+ if (node.layoutMode) {
202
+ // Item spacing (gap)
203
+ if (node.itemSpacing) {
204
+ spacingValues.add(node.itemSpacing);
205
+ }
206
+
207
+ // Padding
208
+ if (node.paddingLeft) spacingValues.add(node.paddingLeft);
209
+ if (node.paddingRight) spacingValues.add(node.paddingRight);
210
+ if (node.paddingTop) spacingValues.add(node.paddingTop);
211
+ if (node.paddingBottom) spacingValues.add(node.paddingBottom);
212
+ }
213
+ });
214
+
215
+ // Generate semantic names (4px → xs, 8px → sm, etc.)
216
+ const sortedSpacing = Array.from(spacingValues).sort((a, b) => a - b);
217
+
218
+ const sizeMap = ['xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl'];
219
+
220
+ return sortedSpacing.map((value, index) => ({
221
+ name: sizeMap[index] || `spacing-${index}`,
222
+ value,
223
+ description: `${value}px spacing`,
224
+ }));
225
+ }
226
+ ```
227
+
228
+ **Extract Shadow Tokens (Elevation)**:
229
+
230
+ ```typescript
231
+ interface ShadowToken {
232
+ name: string;
233
+ value: string; // CSS box-shadow value
234
+ layers: Array<{
235
+ x: number;
236
+ y: number;
237
+ blur: number;
238
+ spread: number;
239
+ color: string;
240
+ }>;
241
+ description?: string;
242
+ }
243
+
244
+ async function extractShadowTokens(fileKey: string): Promise<ShadowToken[]> {
245
+ const importer = new FigmaImporter({
246
+ accessToken: process.env.FIGMA_ACCESS_TOKEN!,
247
+ fileKey,
248
+ });
249
+
250
+ const file = await importer.fetchFile();
251
+ const styles = await importer.fetchStyles();
252
+
253
+ const shadowTokens: ShadowToken[] = [];
254
+
255
+ for (const style of styles) {
256
+ if (style.style_type === 'EFFECT') {
257
+ const node = findNodeById(file.document, style.node_id);
258
+
259
+ if (node?.effects) {
260
+ const shadows = node.effects.filter(
261
+ (e: any) => e.type === 'DROP_SHADOW' || e.type === 'INNER_SHADOW'
262
+ );
263
+
264
+ if (shadows.length > 0) {
265
+ const layers = shadows.map((shadow: any) => ({
266
+ x: shadow.offset.x,
267
+ y: shadow.offset.y,
268
+ blur: shadow.radius,
269
+ spread: shadow.spread || 0,
270
+ color: rgbaToHex(shadow.color, shadow.color.a),
271
+ }));
272
+
273
+ const cssValue = layers
274
+ .map(
275
+ (layer) =>
276
+ `${layer.x}px ${layer.y}px ${layer.blur}px ${layer.spread}px ${layer.color}`
277
+ )
278
+ .join(', ');
279
+
280
+ shadowTokens.push({
281
+ name: style.name,
282
+ value: cssValue,
283
+ layers,
284
+ description: style.description,
285
+ });
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ return shadowTokens;
292
+ }
293
+ ```
294
+
295
+ ### 3. Token Organization
296
+
297
+ **Hierarchical Token Structure**:
298
+
299
+ ```
300
+ tokens/
301
+ ├── global/
302
+ │ ├── colors.json # Brand colors, primitives
303
+ │ ├── typography.json # Font scales
304
+ │ ├── spacing.json # Spacing scale
305
+ │ └── shadows.json # Elevation scale
306
+ ├── semantic/
307
+ │ ├── colors.json # Semantic colors (success, error, warning)
308
+ │ ├── components.json # Component-specific tokens
309
+ │ └── themes.json # Light/dark theme mappings
310
+ └── platform/
311
+ ├── web.json # Web-specific tokens (CSS variables)
312
+ ├── ios.json # iOS-specific (Swift)
313
+ └── android.json # Android-specific (XML)
314
+ ```
315
+
316
+ **Naming Convention** (BEM-inspired):
317
+ ```
318
+ category-element-modifier-state
319
+
320
+ Examples:
321
+ - color-brand-primary
322
+ - color-semantic-success
323
+ - color-text-primary
324
+ - typography-heading-h1
325
+ - spacing-component-button-padding
326
+ - shadow-elevation-1
327
+ - border-radius-sm
328
+ ```
329
+
330
+ ### 4. Token File Formats
331
+
332
+ **CSS Variables** (Most Common):
333
+
334
+ ```css
335
+ /* tokens/global/colors.css */
336
+ :root {
337
+ /* Brand Colors */
338
+ --color-brand-primary: #0066FF;
339
+ --color-brand-secondary: #00CC66;
340
+ --color-brand-tertiary: #FF6600;
341
+
342
+ /* Semantic Colors */
343
+ --color-semantic-success: #00CC66;
344
+ --color-semantic-error: #FF3333;
345
+ --color-semantic-warning: #FFCC00;
346
+ --color-semantic-info: #0066FF;
347
+
348
+ /* Grayscale */
349
+ --color-gray-50: #F9FAFB;
350
+ --color-gray-100: #F3F4F6;
351
+ --color-gray-200: #E5E7EB;
352
+ --color-gray-300: #D1D5DB;
353
+ --color-gray-400: #9CA3AF;
354
+ --color-gray-500: #6B7280;
355
+ --color-gray-600: #4B5563;
356
+ --color-gray-700: #374151;
357
+ --color-gray-800: #1F2937;
358
+ --color-gray-900: #111827;
359
+
360
+ /* Typography */
361
+ --font-family-sans: 'Inter', -apple-system, sans-serif;
362
+ --font-family-mono: 'JetBrains Mono', monospace;
363
+
364
+ --font-size-xs: 0.75rem; /* 12px */
365
+ --font-size-sm: 0.875rem; /* 14px */
366
+ --font-size-base: 1rem; /* 16px */
367
+ --font-size-lg: 1.125rem; /* 18px */
368
+ --font-size-xl: 1.25rem; /* 20px */
369
+ --font-size-2xl: 1.5rem; /* 24px */
370
+ --font-size-3xl: 1.875rem; /* 30px */
371
+ --font-size-4xl: 2.25rem; /* 36px */
372
+
373
+ --font-weight-normal: 400;
374
+ --font-weight-medium: 500;
375
+ --font-weight-semibold: 600;
376
+ --font-weight-bold: 700;
377
+
378
+ --line-height-tight: 1.25;
379
+ --line-height-normal: 1.5;
380
+ --line-height-relaxed: 1.75;
381
+
382
+ /* Spacing */
383
+ --spacing-xs: 0.25rem; /* 4px */
384
+ --spacing-sm: 0.5rem; /* 8px */
385
+ --spacing-md: 1rem; /* 16px */
386
+ --spacing-lg: 1.5rem; /* 24px */
387
+ --spacing-xl: 2rem; /* 32px */
388
+ --spacing-2xl: 3rem; /* 48px */
389
+ --spacing-3xl: 4rem; /* 64px */
390
+
391
+ /* Shadows */
392
+ --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
393
+ --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
394
+ --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
395
+ --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
396
+
397
+ /* Border Radius */
398
+ --radius-sm: 0.25rem; /* 4px */
399
+ --radius-md: 0.5rem; /* 8px */
400
+ --radius-lg: 0.75rem; /* 12px */
401
+ --radius-xl: 1rem; /* 16px */
402
+ --radius-full: 9999px;
403
+
404
+ /* Transitions */
405
+ --transition-fast: 150ms;
406
+ --transition-base: 250ms;
407
+ --transition-slow: 350ms;
408
+ }
409
+ ```
410
+
411
+ **JavaScript/TypeScript**:
412
+
413
+ ```typescript
414
+ // tokens/global/colors.ts
415
+ export const colors = {
416
+ brand: {
417
+ primary: '#0066FF',
418
+ secondary: '#00CC66',
419
+ tertiary: '#FF6600',
420
+ },
421
+ semantic: {
422
+ success: '#00CC66',
423
+ error: '#FF3333',
424
+ warning: '#FFCC00',
425
+ info: '#0066FF',
426
+ },
427
+ gray: {
428
+ 50: '#F9FAFB',
429
+ 100: '#F3F4F6',
430
+ 200: '#E5E7EB',
431
+ 300: '#D1D5DB',
432
+ 400: '#9CA3AF',
433
+ 500: '#6B7280',
434
+ 600: '#4B5563',
435
+ 700: '#374151',
436
+ 800: '#1F2937',
437
+ 900: '#111827',
438
+ },
439
+ } as const;
440
+
441
+ // tokens/global/typography.ts
442
+ export const typography = {
443
+ fontFamily: {
444
+ sans: "'Inter', -apple-system, sans-serif",
445
+ mono: "'JetBrains Mono', monospace",
446
+ },
447
+ fontSize: {
448
+ xs: '0.75rem',
449
+ sm: '0.875rem',
450
+ base: '1rem',
451
+ lg: '1.125rem',
452
+ xl: '1.25rem',
453
+ '2xl': '1.5rem',
454
+ '3xl': '1.875rem',
455
+ '4xl': '2.25rem',
456
+ },
457
+ fontWeight: {
458
+ normal: 400,
459
+ medium: 500,
460
+ semibold: 600,
461
+ bold: 700,
462
+ },
463
+ lineHeight: {
464
+ tight: 1.25,
465
+ normal: 1.5,
466
+ relaxed: 1.75,
467
+ },
468
+ } as const;
469
+
470
+ // tokens/index.ts
471
+ export { colors } from './global/colors';
472
+ export { typography } from './global/typography';
473
+ export { spacing } from './global/spacing';
474
+ export { shadows } from './global/shadows';
475
+
476
+ // Type-safe token access
477
+ export type ColorToken = keyof typeof colors.brand | keyof typeof colors.semantic;
478
+ ```
479
+
480
+ **JSON** (W3C Design Tokens Format):
481
+
482
+ ```json
483
+ {
484
+ "$schema": "https://design-tokens.org/schemas/v1.0.0/design-tokens.schema.json",
485
+ "colors": {
486
+ "brand": {
487
+ "primary": {
488
+ "$type": "color",
489
+ "$value": "#0066FF",
490
+ "$description": "Primary brand color used for main actions and links"
491
+ },
492
+ "secondary": {
493
+ "$type": "color",
494
+ "$value": "#00CC66",
495
+ "$description": "Secondary brand color for accents"
496
+ }
497
+ },
498
+ "semantic": {
499
+ "success": {
500
+ "$type": "color",
501
+ "$value": "{colors.brand.secondary}",
502
+ "$description": "Success state color (references brand.secondary)"
503
+ }
504
+ }
505
+ },
506
+ "typography": {
507
+ "heading": {
508
+ "h1": {
509
+ "$type": "typography",
510
+ "$value": {
511
+ "fontFamily": "{typography.fontFamily.sans}",
512
+ "fontSize": "{typography.fontSize.4xl}",
513
+ "fontWeight": "{typography.fontWeight.bold}",
514
+ "lineHeight": "{typography.lineHeight.tight}"
515
+ }
516
+ }
517
+ }
518
+ }
519
+ }
520
+ ```
521
+
522
+ **SCSS Variables**:
523
+
524
+ ```scss
525
+ // tokens/global/_colors.scss
526
+ $color-brand-primary: #0066FF;
527
+ $color-brand-secondary: #00CC66;
528
+
529
+ $color-gray-50: #F9FAFB;
530
+ $color-gray-100: #F3F4F6;
531
+ // ...
532
+
533
+ // tokens/global/_typography.scss
534
+ $font-family-sans: 'Inter', -apple-system, sans-serif;
535
+ $font-size-base: 1rem;
536
+ $font-weight-bold: 700;
537
+
538
+ // tokens/_index.scss
539
+ @forward 'global/colors';
540
+ @forward 'global/typography';
541
+ @forward 'global/spacing';
542
+ ```
543
+
544
+ **Tailwind CSS Config**:
545
+
546
+ ```javascript
547
+ // tailwind.config.js
548
+ const { colors, typography, spacing, shadows } = require('./tokens');
549
+
550
+ module.exports = {
551
+ theme: {
552
+ extend: {
553
+ colors: {
554
+ brand: colors.brand,
555
+ semantic: colors.semantic,
556
+ gray: colors.gray,
557
+ },
558
+ fontFamily: typography.fontFamily,
559
+ fontSize: typography.fontSize,
560
+ fontWeight: typography.fontWeight,
561
+ lineHeight: typography.lineHeight,
562
+ spacing: spacing,
563
+ boxShadow: shadows,
564
+ },
565
+ },
566
+ };
567
+ ```
568
+
569
+ ### 5. Token Generation Automation
570
+
571
+ **Complete Pipeline**:
572
+
573
+ ```typescript
574
+ import fs from 'fs/promises';
575
+ import path from 'path';
576
+
577
+ interface TokenGeneratorConfig {
578
+ fileKey: string;
579
+ outputDir: string;
580
+ formats: Array<'css' | 'scss' | 'js' | 'ts' | 'json' | 'tailwind'>;
581
+ }
582
+
583
+ async function generateTokens(config: TokenGeneratorConfig) {
584
+ const { fileKey, outputDir, formats } = config;
585
+
586
+ // 1. Extract tokens from Figma
587
+ const colorTokens = await extractColorTokens(fileKey);
588
+ const typographyTokens = await extractTypographyTokens(fileKey);
589
+ const spacingTokens = await extractSpacingTokens(fileKey);
590
+ const shadowTokens = await extractShadowTokens(fileKey);
591
+
592
+ const allTokens = {
593
+ colors: colorTokens,
594
+ typography: typographyTokens,
595
+ spacing: spacingTokens,
596
+ shadows: shadowTokens,
597
+ };
598
+
599
+ // 2. Create output directory
600
+ await fs.mkdir(outputDir, { recursive: true });
601
+
602
+ // 3. Generate formats
603
+ if (formats.includes('css')) {
604
+ const css = generateCSSVariables(allTokens);
605
+ await fs.writeFile(path.join(outputDir, 'tokens.css'), css);
606
+ }
607
+
608
+ if (formats.includes('scss')) {
609
+ const scss = generateSCSSVariables(allTokens);
610
+ await fs.writeFile(path.join(outputDir, '_tokens.scss'), scss);
611
+ }
612
+
613
+ if (formats.includes('js') || formats.includes('ts')) {
614
+ const js = generateJavaScript(allTokens);
615
+ const ext = formats.includes('ts') ? '.ts' : '.js';
616
+ await fs.writeFile(path.join(outputDir, `tokens${ext}`), js);
617
+ }
618
+
619
+ if (formats.includes('json')) {
620
+ const json = generateW3CTokens(allTokens);
621
+ await fs.writeFile(path.join(outputDir, 'tokens.json'), json);
622
+ }
623
+
624
+ if (formats.includes('tailwind')) {
625
+ const tailwind = generateTailwindConfig(allTokens);
626
+ await fs.writeFile(path.join(outputDir, 'tailwind.tokens.js'), tailwind);
627
+ }
628
+
629
+ console.log(`✅ Generated design tokens in ${formats.join(', ')} format(s)`);
630
+ }
631
+
632
+ function generateCSSVariables(tokens: any): string {
633
+ let css = ':root {\n';
634
+
635
+ // Colors
636
+ css += ' /* Colors */\n';
637
+ tokens.colors.forEach((token: any) => {
638
+ css += ` --color-${token.name.toLowerCase().replace(/\s+/g, '-')}: ${token.value};\n`;
639
+ });
640
+
641
+ // Typography
642
+ css += '\n /* Typography */\n';
643
+ tokens.typography.forEach((token: any) => {
644
+ const name = token.name.toLowerCase().replace(/\s+/g, '-');
645
+ css += ` --font-family-${name}: ${token.fontFamily};\n`;
646
+ css += ` --font-size-${name}: ${token.fontSize}px;\n`;
647
+ css += ` --font-weight-${name}: ${token.fontWeight};\n`;
648
+ css += ` --line-height-${name}: ${token.lineHeight};\n`;
649
+ });
650
+
651
+ // Spacing
652
+ css += '\n /* Spacing */\n';
653
+ tokens.spacing.forEach((token: any) => {
654
+ css += ` --spacing-${token.name}: ${token.value}px;\n`;
655
+ });
656
+
657
+ // Shadows
658
+ css += '\n /* Shadows */\n';
659
+ tokens.shadows.forEach((token: any) => {
660
+ css += ` --shadow-${token.name.toLowerCase().replace(/\s+/g, '-')}: ${token.value};\n`;
661
+ });
662
+
663
+ css += '}\n';
664
+
665
+ return css;
666
+ }
667
+
668
+ function generateJavaScript(tokens: any): string {
669
+ const js = `
670
+ export const colors = {
671
+ ${tokens.colors.map((t: any) => ` '${t.name}': '${t.value}',`).join('\n')}
672
+ };
673
+
674
+ export const typography = {
675
+ ${tokens.typography.map((t: any) => ` '${t.name}': {
676
+ fontFamily: '${t.fontFamily}',
677
+ fontSize: ${t.fontSize},
678
+ fontWeight: ${t.fontWeight},
679
+ lineHeight: ${t.lineHeight},
680
+ },`).join('\n')}
681
+ };
682
+
683
+ export const spacing = {
684
+ ${tokens.spacing.map((t: any) => ` '${t.name}': ${t.value},`).join('\n')}
685
+ };
686
+
687
+ export const shadows = {
688
+ ${tokens.shadows.map((t: any) => ` '${t.name}': '${t.value}',`).join('\n')}
689
+ };
690
+ `;
691
+
692
+ return js.trim();
693
+ }
694
+
695
+ // Usage
696
+ generateTokens({
697
+ fileKey: 'ABC123XYZ456',
698
+ outputDir: './src/design-tokens',
699
+ formats: ['css', 'ts', 'json', 'tailwind'],
700
+ }).catch(console.error);
701
+ ```
702
+
703
+ ### 6. Token Synchronization (Watch Mode)
704
+
705
+ **Auto-sync on Figma Changes**:
706
+
707
+ ```typescript
708
+ import { watch } from 'fs';
709
+
710
+ async function watchFigmaTokens(fileKey: string, outputDir: string, pollInterval = 60000) {
711
+ let lastVersion: string | null = null;
712
+
713
+ setInterval(async () => {
714
+ const importer = new FigmaImporter({
715
+ accessToken: process.env.FIGMA_ACCESS_TOKEN!,
716
+ fileKey,
717
+ });
718
+
719
+ const file = await importer.fetchFile();
720
+
721
+ if (lastVersion && file.version !== lastVersion) {
722
+ console.log(`🔄 Figma file updated (v${file.version}). Re-generating tokens...`);
723
+
724
+ await generateTokens({
725
+ fileKey,
726
+ outputDir,
727
+ formats: ['css', 'ts', 'json'],
728
+ });
729
+
730
+ console.log('✅ Tokens synchronized!');
731
+ }
732
+
733
+ lastVersion = file.version;
734
+ }, pollInterval);
735
+
736
+ console.log(`👀 Watching Figma file for changes (polling every ${pollInterval / 1000}s)...`);
737
+ }
738
+
739
+ // Usage
740
+ watchFigmaTokens('ABC123XYZ456', './src/design-tokens', 60000); // Check every minute
741
+ ```
742
+
743
+ ### 7. Theme Support (Light/Dark Mode)
744
+
745
+ **Generate Theme Tokens**:
746
+
747
+ ```typescript
748
+ // tokens/themes/light.ts
749
+ export const lightTheme = {
750
+ colors: {
751
+ background: '#FFFFFF',
752
+ foreground: '#111827',
753
+ primary: '#0066FF',
754
+ secondary: '#6B7280',
755
+ border: '#E5E7EB',
756
+ },
757
+ };
758
+
759
+ // tokens/themes/dark.ts
760
+ export const darkTheme = {
761
+ colors: {
762
+ background: '#111827',
763
+ foreground: '#F9FAFB',
764
+ primary: '#3B82F6',
765
+ secondary: '#9CA3AF',
766
+ border: '#374151',
767
+ },
768
+ };
769
+
770
+ // CSS Variables with theme support
771
+ :root {
772
+ --color-background: #FFFFFF;
773
+ --color-foreground: #111827;
774
+ }
775
+
776
+ [data-theme="dark"] {
777
+ --color-background: #111827;
778
+ --color-foreground: #F9FAFB;
779
+ }
780
+ ```
781
+
782
+ ## Workflow
783
+
784
+ 1. Ask about Figma file and token extraction preferences
785
+ 2. Fetch color, typography, spacing, and shadow styles from Figma
786
+ 3. Analyze and categorize tokens (brand, semantic, primitives)
787
+ 4. Ask about output formats (CSS, SCSS, JS, JSON, Tailwind)
788
+ 5. Generate hierarchical token structure
789
+ 6. Create token files in requested formats
790
+ 7. Set up theme support if needed (light/dark modes)
791
+ 8. Provide integration examples for each format
792
+ 9. Optionally set up watch mode for auto-sync
793
+ 10. Generate documentation with token usage examples
794
+
795
+ ## When to Use
796
+
797
+ - Setting up design systems from Figma
798
+ - Synchronizing design tokens across platforms (web, iOS, Android)
799
+ - Migrating from hardcoded values to token-based theming
800
+ - Implementing light/dark mode support
801
+ - Automating design-to-code token updates
802
+ - Standardizing design values across teams
803
+
804
+ ## Best Practices
805
+
806
+ 1. **Organization**: Use hierarchical structure (global → semantic → component)
807
+ 2. **Naming**: Follow consistent naming conventions (BEM or similar)
808
+ 3. **Formats**: Generate multiple formats for different use cases
809
+ 4. **Aliasing**: Use token references for semantic tokens (W3C format)
810
+ 5. **Documentation**: Include descriptions from Figma styles
811
+ 6. **Versioning**: Track Figma file versions in metadata
812
+ 7. **Automation**: Set up CI/CD for token synchronization
813
+ 8. **Validation**: Validate token values before deployment
814
+
815
+ Extract and sync design tokens with production-ready automation!