-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
59 lines (49 loc) · 1.49 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
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}`;
},
});
function getStyleDictionaryConfig(theme) {
return {
source: [`tokens/${theme}.json`],
format: {
createArray,
},
platforms: {
web: {
transforms: ["attribute/cti", "name/cti/kebab"],
buildPath: `output/`,
files: [
{
destination: `${theme}.json`,
format: "createArray",
},
{
destination: `${theme}.css`,
format: "css/variables",
selector: `.${theme}`,
},
],
},
},
};
}
console.log("Build started...");
// PROCESS THE DESIGN TOKENS FOR THE DIFFEREN BRANDS AND PLATFORMS
["global", "components", "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!");