-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
154 lines (131 loc) · 4.9 KB
/
Copy pathbuild.js
File metadata and controls
154 lines (131 loc) · 4.9 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const StyleDictionaryPackage = require('style-dictionary');
StyleDictionaryPackage.registerTransform({
name: 'vsCodeName',
type: 'name',
transformer: (token) => {
// syntax tokens we remove the first part of the object path
if (token.path[0] === 'colors') {
return token.path.slice(1).join('.');
}
if (token.path[0] === 'syntax') {
// This allows you to have tokens at multiple levels
// like `comment` and `comment.line`
if (token.name === '*') {
// removes the first and last parts of the path
return token.path.slice(1,-1).join('.')
} else {
// removes the first part of the path which would be 'syntax'
return token.path.slice(1).join('.')
}
}
}});
// 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';
// }
// });
// StyleDictionaryPackage.registerFormat({
// name: 'css/variables',
// formatter: function (dictionary, config) {
// return `${this.selector} {
// ${dictionary.allProperties.map(prop => ` --${prop.name}: ${prop.value};`).join('\n')}
// }`
// }
// });
// Add a custom format that will generate the VSCode theme JSON
StyleDictionaryPackage.registerFormat({
name: 'vsCodeTheme',
formatter: (dictionary, config) => {
// VSCode theme JSON files have this structure
const theme = {
"name": `Arduino ${config.themeType}`,
"type": config.themeType,
"colors": {},
}
// Filter out the design tokens we don't want to add to the
// 'colors' object. This includes core colors defined in tokens/core.json5
// and syntax tokens defined in tokens/syntax
dictionary.allProperties.filter((token) => {
return !['color','syntax'].includes(token.path[0])
}).forEach((token) => {
// Add each token to the colors object, the name is generated by the custom
// transform defined above
theme.colors[token.name] = token.value;
});
// Map the syntax styles
theme.tokenColors = dictionary.allProperties.filter((token) => {
return token.path[0] === 'syntax'
}).map((token) => ({
name: token.name,
scope: token.scope,
settings: {
foreground: token.value,
fontStyle: token.fontStyle,
}
})
);
// theme.tokenColors = dictionary.allProperties.filter((token) => {
// return token.path[0] === 'tokenColors'
// }).map((token) => ({
// scope: token.name,
// settings: {
// foreground: token.value,
// fontStyle: token.fontStyle,
// }
// })
// );
// Style Dictionary formats expect a string that will be then written to a file
return JSON.stringify(theme, null, 2);
}
});
function getStyleDictionaryConfig(theme) {
return {
"source": [
`tokens/${theme}.json`,
],
"platforms": {
"vscode": {
// Directory to build files to
"buildPath": `theia-themes/`,
"themeType": `${theme}`,
// The name of the custom transform we defined above
"transforms": ["vsCodeName"],
"files": [{
// The path the file will be created at. Make sure this matches
// the file paths defined in the package.json
"destination": `${theme}.color-theme.json`,
// The name of the custom format defined above
"format": "vsCodeTheme",
"selector": `${theme}-theme`
}]
}
// "web": {
// "transforms": ["attribute/cti", "name/cti/kebab", "sizes/px"],
// "buildPath": `output/`,
// "files": [{
// "destination": `${theme}.json`,
// "format": "css/variables",
// "selector": `.${theme}-theme`
// }]
// }
}
};
}
console.log('Build started...');
// PROCESS THE DESIGN TOKENS FOR THE DIFFEREN BRANDS AND PLATFORMS
['default', 'dark'].map(function (theme) {
console.log('\n==============================================');
console.log(`\nProcessing: [${theme}]`);
const StyleDictionary = StyleDictionaryPackage.extend(getStyleDictionaryConfig(theme));
StyleDictionary.buildPlatform('vscode');
console.log('\nEnd processing');
})
console.log('\n==============================================');
console.log('\nBuild completed!');