@mindvalley/design-system 3.4.2 → 4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindvalley/design-system",
3
- "version": "3.4.2",
3
+ "version": "4.0.0",
4
4
  "description": "Resources, components, design guidelines and tooling for Mindvalley's design system",
5
5
  "keywords": [
6
6
  "design-system",
@@ -42,6 +42,10 @@
42
42
  "types": "./dist/tailwind/*.d.ts",
43
43
  "default": "./dist/tailwind/*.js"
44
44
  },
45
+ "./typography/*": {
46
+ "types": "./dist/typography/*.d.ts",
47
+ "default": "./dist/typography/*"
48
+ },
45
49
  "./dist/*": "./dist/*"
46
50
  },
47
51
  "peerDependencies": {
@@ -65,12 +69,21 @@
65
69
  "test:watch": "jest --watch",
66
70
  "watch": "webpack --mode development --watch",
67
71
  "type-check": "tsc --noEmit",
68
- "build:types": "tsc --emitDeclarationOnly"
72
+ "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
73
+ "format": "biome format --write ./src",
74
+ "format:check": "biome format ./src",
75
+ "lint": "biome lint ./src",
76
+ "lint:fix": "biome lint --write ./src",
77
+ "check": "biome check --write ./src",
78
+ "check:ci": "biome ci ./src",
79
+ "check:staged": "biome check --staged",
80
+ "check:changed": "biome check --changed"
69
81
  },
70
82
  "devDependencies": {
71
83
  "@babel/core": "^7.22.9",
72
84
  "@babel/preset-env": "^7.22.9",
73
85
  "@babel/preset-typescript": "^7.27.1",
86
+ "@biomejs/biome": "^2.3.4",
74
87
  "@commitlint/cli": "^17.7.1",
75
88
  "@commitlint/config-conventional": "^17.7.0",
76
89
  "@figma-export/cli": "^6.2.3",
@@ -81,6 +94,7 @@
81
94
  "@types/jest": "^30.0.0",
82
95
  "@types/lodash.kebabcase": "^4.1.9",
83
96
  "@types/node": "^24.1.0",
97
+ "@types/svg-sprite": "^0.0.39",
84
98
  "@types/tailwindcss": "^3.0.11",
85
99
  "@types/tinycolor2": "^1.4.6",
86
100
  "babel-jest": "^30.1.2",
@@ -100,7 +114,7 @@
100
114
  "semantic-release": "^25.0.1",
101
115
  "semantic-release-github-pullrequest": "github:njausteve/semantic-release-github-pullrequest",
102
116
  "semantic-release-unsquash": "^0.1.2",
103
- "style-dictionary": "^3.8.0",
117
+ "style-dictionary": "^5.0.4",
104
118
  "svg-sprite": "^2.0.2",
105
119
  "tailwindcss": "^3.4.17",
106
120
  "tinycolor2": "^1.6.0",
@@ -1,298 +0,0 @@
1
- # Design Token Validation with Zod
2
-
3
- This document describes the **internal** token validation system implemented using Zod for runtime validation and TypeScript type inference. These utilities are used during the build process and are not exported to package consumers.
4
-
5
- ## Overview
6
-
7
- The Mindvalley Design System uses Supernova to manage design tokens. These tokens are automatically pushed to the repository in JSON format. To ensure type safety and catch issues early, we've implemented a validation system using Zod that:
8
-
9
- - Validates token structure at build time
10
- - Provides TypeScript types derived from the same schemas
11
- - Offers clear error messages when tokens don't match expected structure
12
- - Handles the complex, nested structures that Supernova generates
13
-
14
- ## Architecture
15
-
16
- ### Core Files
17
-
18
- - `src/types/token-schemas.ts` - Zod schemas defining token structure
19
- - `src/types/token-validation.ts` - Validation utilities and functions
20
- - `src/types/index.d.ts` - TypeScript type exports
21
-
22
- ### Token Structure
23
-
24
- Supernova generates tokens with varying levels of nesting:
25
-
26
- ```json
27
- {
28
- "color": {
29
- "primary": {
30
- "500": {
31
- "value": "#ff0000ff",
32
- "type": "color"
33
- }
34
- },
35
- "black": {
36
- "value": "#000000ff",
37
- "type": "color"
38
- }
39
- }
40
- }
41
- ```
42
-
43
- ## For Package Consumers
44
-
45
- If you're using the `@mindvalley/design-system` npm package, the validation happens at build time and you receive:
46
-
47
- - Type-safe `ColorTokens` interface for the colors object
48
- - `TypographyToken` and `TypographySet` types from the Tailwind plugin
49
- - Pre-validated, transformed tokens ready for use
50
-
51
- The examples below are for **contributors and maintainers** working on the design system itself.
52
-
53
- ## Usage Guide (Internal Development)
54
-
55
- ### 1. Basic Validation
56
-
57
- ```typescript
58
- import { validateTokenFile } from './types/token-validation';
59
-
60
- const result = validateTokenFile('src/tokens/brands/mindvalley/colors.json');
61
- if (result.success) {
62
- console.log('Tokens are valid!', result.data);
63
- } else {
64
- console.error('Validation failed:', result.errors);
65
- }
66
- ```
67
-
68
- ### 2. Type-Safe Token Access
69
-
70
- ```typescript
71
- import { ColorToken } from './types/token-schemas';
72
- import { validateColorToken } from './types/token-validation';
73
-
74
- // Runtime validation with automatic type inference
75
- try {
76
- const token: ColorToken = validateColorToken(unknownData);
77
- // TypeScript knows token.value is a hex string
78
- console.log(token.value);
79
- } catch (error) {
80
- console.error('Invalid color token:', error);
81
- }
82
- ```
83
-
84
- ### 3. Batch Validation
85
-
86
- ```typescript
87
- import { validateAllTokens, getValidationSummary } from './types/token-validation';
88
-
89
- // Validate all tokens in the project
90
- const summary = getValidationSummary('./src/tokens');
91
- console.log(`Valid: ${summary.valid}, Invalid: ${summary.invalid}`);
92
-
93
- if (summary.invalid > 0) {
94
- summary.errors.forEach(error => {
95
- console.error(`❌ ${error.file}:`, error.errors);
96
- });
97
- }
98
- ```
99
-
100
- ### 4. CI/CD Integration
101
-
102
- Add to your `package.json`:
103
-
104
- ```json
105
- {
106
- "scripts": {
107
- "validate-tokens": "ts-node src/scripts/validate-tokens.ts",
108
- "prebuild": "npm run validate-tokens"
109
- }
110
- }
111
- ```
112
-
113
- Create `src/scripts/validate-tokens.ts`:
114
-
115
- ```typescript
116
- import { getValidationSummary } from '../types/token-validation';
117
-
118
- const summary = getValidationSummary('./src/tokens');
119
-
120
- if (summary.invalid > 0) {
121
- console.error('Token validation failed!');
122
- summary.errors.forEach(error => {
123
- console.error(`❌ ${error.file}:`, error.errors.join('\n '));
124
- });
125
- process.exit(1);
126
- }
127
-
128
- console.log('✅ All tokens validated successfully!');
129
- ```
130
-
131
- ### 5. Type Guards
132
-
133
- ```typescript
134
- import { isColorToken, isTypographyToken } from './types/token-validation';
135
-
136
- function processToken(token: unknown) {
137
- if (isColorToken(token)) {
138
- // TypeScript knows this is a ColorToken
139
- return createColorVariable(token.value);
140
- } else if (isTypographyToken(token)) {
141
- // TypeScript knows this is a TypographyToken
142
- return createTypographyStyles(token.value);
143
- }
144
- }
145
- ```
146
-
147
- ### 6. Error Handling
148
-
149
- ```typescript
150
- import { safeValidate, ColorFileSchema, formatZodError } from './types/token-validation';
151
-
152
- function handleSupernovaWebhook(payload: unknown) {
153
- const result = safeValidate(ColorFileSchema, payload);
154
-
155
- if (!result.success) {
156
- const errors = formatZodError(result.errors);
157
-
158
- // Log structured errors
159
- console.error('Token validation failed:', {
160
- errors,
161
- timestamp: new Date().toISOString(),
162
- source: 'supernova-webhook'
163
- });
164
-
165
- // Alert team
166
- notifySlack({
167
- channel: '#design-system',
168
- message: `Token validation failed: ${errors.join(', ')}`
169
- });
170
-
171
- return;
172
- }
173
-
174
- // Process valid tokens
175
- updateTokens(result.data);
176
- }
177
- ```
178
-
179
- ## Testing
180
-
181
- ### Unit Tests
182
-
183
- ```typescript
184
- import { ColorTokenSchema } from './types/token-schemas';
185
-
186
- describe('Color Token Validation', () => {
187
- it('should accept valid color tokens', () => {
188
- const validToken = {
189
- value: '#ff0000ff',
190
- type: 'color'
191
- };
192
-
193
- expect(() => ColorTokenSchema.parse(validToken)).not.toThrow();
194
- });
195
-
196
- it('should reject invalid hex values', () => {
197
- const invalidToken = {
198
- value: 'not-a-color',
199
- type: 'color'
200
- };
201
-
202
- expect(() => ColorTokenSchema.parse(invalidToken)).toThrow();
203
- });
204
- });
205
- ```
206
-
207
- ### Integration Tests
208
-
209
- ```typescript
210
- import { validateAllTokens } from './types/token-validation';
211
-
212
- describe('Token File Validation', () => {
213
- it('should validate all production tokens', () => {
214
- const results = validateAllTokens('./src/tokens');
215
- const failures = results.filter(r => !r.success);
216
-
217
- expect(failures).toHaveLength(0);
218
- });
219
- });
220
- ```
221
-
222
- ## Schema Flexibility
223
-
224
- The schemas are designed to handle Supernova's complex output:
225
-
226
- - **Nested structures**: Tokens can be nested at varying levels
227
- - **Optional properties**: Some tokens have optional fields like `comment`
228
- - **Mixed structures**: Different brands may have slightly different structures
229
- - **Type variations**: Properties like `textCase` can be strings or objects
230
-
231
- ## Extending the System
232
-
233
- ### Adding New Token Types
234
-
235
- 1. Add the schema in `token-schemas.ts`:
236
-
237
- ```typescript
238
- export const NewTokenSchema = z.object({
239
- value: z.string(),
240
- type: z.literal('newtype'),
241
- metadata: z.object({
242
- // Define metadata structure
243
- }).optional()
244
- });
245
- ```
246
-
247
- 2. Add to file schema mapping in `token-validation.ts`:
248
-
249
- ```typescript
250
- const FILE_SCHEMA_MAP = {
251
- // existing mappings...
252
- 'newtokens.json': NewTokenFileSchema
253
- };
254
- ```
255
-
256
- ### Custom Validation Rules
257
-
258
- ```typescript
259
- const CustomColorSchema = ColorTokenSchema.refine(
260
- (token) => token.value.length === 9, // RGBA with alpha
261
- { message: 'Colors must include alpha channel' }
262
- );
263
- ```
264
-
265
- ## Troubleshooting
266
-
267
- ### Common Issues
268
-
269
- 1. **"Invalid input" errors**: Check if Supernova changed the token structure
270
- 2. **Missing properties**: Some tokens may have optional fields
271
- 3. **Type mismatches**: Use the flexible schemas that accept `z.any()` for complex nested structures
272
-
273
- ### Debugging
274
-
275
- ```typescript
276
- import { validateTokenFile, getErrorReport } from './types/token-validation';
277
-
278
- const result = validateTokenFile('path/to/tokens.json');
279
- if (!result.success) {
280
- // Get detailed error report
281
- console.log(getErrorReport(result.errors));
282
- }
283
- ```
284
-
285
- ## Best Practices
286
-
287
- 1. **Run validation in CI/CD**: Catch issues before they reach production
288
- 2. **Validate after Supernova updates**: Add webhook handlers that validate incoming tokens
289
- 3. **Use type guards**: Leverage TypeScript's type narrowing with `isColorToken()` etc.
290
- 4. **Keep schemas updated**: When Supernova changes output format, update schemas accordingly
291
- 5. **Test with real data**: Always test schemas against actual token files
292
-
293
- ## Future Improvements
294
-
295
- - Add schema versioning to handle Supernova format changes
296
- - Create a CLI tool for token validation
297
- - Add visual regression tests for token changes
298
- - Implement token transformation pipelines with validation