-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
83 lines (74 loc) · 1.73 KB
/
build.js
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
// build.js
const StyleDictionary = require('style-dictionary').extend('config.json');
console.log('📦 Building SCSS and CSS...');
StyleDictionary.registerTransform({
name: 'font/family',
type: "value",
transitive: true,
matcher: (token) => token.type === "fontFamilies",
transformer: (token) => {
if (token.original.value.startsWith('{'))
return token.value
else
return `'${token.value}'`
},
});
StyleDictionary.registerTransform({
name: 'font/weight',
type: 'value',
matcher: function(prop) {
return prop.original.type === 'fontWeights';
},
transformer: function(prop) {
const fontWeight = prop.original.value;
switch (fontWeight) {
case 'Regular':
return '400';
case 'SemiBold':
return 600;
case 'Bold':
return 700;
default:
return '400';
}
}
});
StyleDictionary.registerTransform({
name: 'spacing/px',
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'spacer';
},
transformer: function(prop) {
return parseFloat(prop.original.value) + 'px';
}
});
StyleDictionary.registerTransform({
name: 'shadow/type',
type: 'value',
matcher: function(prop) {
return prop.original.type === 'type';
},
transformer: function(prop) {
const dropShadow = prop.original.value;
switch (dropShadow) {
case 'dropShadow':
return "''";
case 'innerShadow':
return 'inset';
default:
return "''";
}
}
});
// REGISTER A CUSTOM FORMAT
StyleDictionary.registerFormat({
name: 'custom/scss/variables',
formatter: function({ dictionary }) {
return dictionary.allTokens.map(function(token) {
return `$${token.name}: ${token.value};`;
}).join('\n');
}
});
StyleDictionary.buildAllPlatforms();
console.log(`\n✅ CSS + SCSS variables files created \n`)