-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-tokens.js
More file actions
95 lines (76 loc) · 2.42 KB
/
Copy pathbuild-tokens.js
File metadata and controls
95 lines (76 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env node
/**
* Generate CSS custom properties from UnlockOpen design tokens
* Uses the same utilities as the main website for consistency
*/
import {
colors,
spacing,
textSizes,
fonts,
textWeights,
textLeading,
themes,
tokensToTailwind,
clampGenerator
} from 'unlockopen-design-tokens';
import fs from 'fs';
function generateTokenCSS() {
let css = `/**
* Generated CSS Custom Properties from UnlockOpen Design Tokens
* Do not edit this file directly - regenerate with: npm run build:tokens
*/
:root {
`;
// Colors
css += ' /* Colors */\n';
Object.entries(tokensToTailwind(colors.items)).forEach(([key, value]) => {
css += ` --color-${key}: ${value};\n`;
});
// Spacing
css += '\n /* Spacing */\n';
Object.entries(tokensToTailwind(clampGenerator(spacing.items))).forEach(([key, value]) => {
css += ` --space-${key}: ${value};\n`;
});
// Text sizes
css += '\n /* Text Sizes */\n';
Object.entries(tokensToTailwind(clampGenerator(textSizes.items))).forEach(([key, value]) => {
// Remove 'step-' prefix if it exists since we're adding '--size-step-'
const cleanKey = key.startsWith('step-') ? key.slice(5) : key;
css += ` --size-step-${cleanKey}: ${value};\n`;
});
// Typography
css += '\n /* Typography */\n';
Object.entries(tokensToTailwind(fonts.items)).forEach(([key, value]) => {
css += ` --font-${key}: ${value};\n`;
});
Object.entries(tokensToTailwind(textWeights.items)).forEach(([key, value]) => {
css += ` --font-${key}: ${value};\n`;
});
Object.entries(tokensToTailwind(textLeading.items)).forEach(([key, value]) => {
css += ` --leading-${key}: ${value};\n`;
});
css += '}\n\n';
// Generate theme classes
css += '/* Theme Classes */\n';
themes.items.forEach(theme => {
css += `.theme-${theme.name} {\n`;
css += ` --theme-color-light: var(--color-${theme.name}-light);\n`;
css += ` --theme-color-dark: var(--color-${theme.name});\n`;
css += '}\n';
});
return css;
}
function main() {
try {
console.log('🚀 Generating CSS from design tokens...');
const css = generateTokenCSS();
fs.writeFileSync('./tokens-generated.css', css);
console.log('✅ Generated CSS custom properties at tokens-generated.css');
console.log('📋 Build system will copy this to the final location');
} catch (error) {
console.error('❌ Error generating tokens:', error);
process.exit(1);
}
}
main();