forked from tokens-studio/plugin-example-tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
68 lines (56 loc) · 1.96 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
const StyleDictionaryPackage = require('style-dictionary');
const {createArray} = require('./fns');
// HAVE THE STYLE DICTIONARY CONFIG DYNAMICALLY GENERATED
StyleDictionaryPackage.registerFormat({
name: 'css/variables',
formatter: function (dictionary, config) {
return `${this.selector} {\n${dictionary.allProperties.map(prop => ` --${prop.name}: ${prop.value};`).join('\n')}\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 ["fontSizes", "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`,
],
"format": {
createArray
},
"platforms": {
"web": {
"transforms": ["attribute/cti", "name/cti/kebab", "sizes/px"],
"buildPath": `output/`,
"files": [{
"destination": `${theme}.json`,
"format": "createArray"
}, {
"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!');