generated from tokens-studio/plugin-example-css
-
Notifications
You must be signed in to change notification settings - Fork 24
/
build.js
63 lines (51 loc) · 1.82 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
const StyleDictionaryPackage = require('style-dictionary');
// HAVE THE STYLE DICTIONARY CONFIG DYNAMICALLY GENERATED
StyleDictionaryPackage.registerFormat({
name: 'css/variables',
formatter: function (dictionary, config) {
return `${this.selector} {
${dictionary.allProperties.map(prop => ` --${prop.name}: ${prop.value};`).join('\n')}
}`
}
});
StyleDictionaryPackage.registerTransform({
name: 'sizes/px',
type: 'value',
matcher: function(prop) {
// You can be more specific here if you only want 'em' units for font sizes
return ["fontSize", "spacing", "borderRadius", "borderWidth", "sizing"].includes(prop.attributes.category);
},
transformer: function(prop) {
// You can also modify the value here if you want to convert pixels to ems
return parseFloat(prop.original.value) + 'px';
}
});
function getStyleDictionaryConfig(theme) {
return {
"source": [
`tokens/${theme}.json`,
],
"platforms": {
"web": {
"transforms": ["attribute/cti", "name/cti/kebab", "sizes/px"],
"buildPath": `output/`,
"files": [{
"destination": `${theme}.css`,
"format": "css/variables",
"selector": `.${theme}-theme`
}]
}
}
};
}
console.log('Build started...');
// PROCESS THE DESIGN TOKENS FOR THE DIFFEREN BRANDS AND PLATFORMS
['global', 'dark', 'light'].map(function (theme) {
console.log('\n==============================================');
console.log(`\nProcessing: [${theme}]`);
const StyleDictionary = StyleDictionaryPackage.extend(getStyleDictionaryConfig(theme));
StyleDictionary.buildPlatform('web');
console.log('\nEnd processing');
})
console.log('\n==============================================');
console.log('\nBuild completed!');