-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
98 lines (87 loc) · 2.31 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import StyleDictionary from "style-dictionary";
import { registerTransforms } from "@tokens-studio/sd-transforms";
import filterExcludeTokens from "./utils/filters/filterExcludeTokens.js";
import formatFontFace from "./utils/formats/formatFontFace.js";
import transformFont from "./utils/transforms/transformFont.js";
import transformToRem from "./utils/transforms/transformToRem.js";
registerTransforms(StyleDictionary);
const tokenGroups = ["core", "semantic"];
const common = {
buildPath: "tokens-generated/",
prefix: "wds",
transformGroup: "tokens-studio",
};
const sd = new StyleDictionary({
source: ["tokens/**/*.json"],
platforms: {
css: {
...common,
transforms: ["name/kebab", "custom/rem"],
files: tokenGroups.map((groupName) => {
return {
destination: `css/${groupName}.css`,
format: "css/variables",
filter: (token) =>
token.filePath === `tokens/tokens-figma/${groupName}.json` &&
filterExcludeTokens(token),
};
}),
},
fonts: {
...common,
transforms: ["custom/font"],
files: [
{
destination: "css/fonts.css",
format: "custom/font-face",
filter: {
attributes: {
category: "asset",
type: "font",
},
},
options: {
fontPathPrefix: "../../assets/",
},
},
],
},
json: {
...common,
files: [
{
destination: "wds-tokens.json",
format: "json/nested",
filter: (token) => filterExcludeTokens(token),
},
],
},
},
});
sd.registerFormat({
name: "custom/font-face",
format: ({ dictionary: { allTokens }, options }) =>
formatFontFace(allTokens, options),
});
sd.registerTransform({
name: "custom/font",
type: "attribute",
filter: (token) => token.path[0] === "asset" && token.path[1] === "font",
transform: (token) => transformFont(token.path),
});
sd.registerTransform({
name: "custom/rem",
type: "value",
transitive: true,
filter: (token) =>
[
"sizing",
"spacing",
"borderRadius",
"fontSizes",
"letterSpacing",
].includes(token.type),
transform: (token) => transformToRem(token.value),
});
sd.cleanAllPlatforms();
sd.buildAllPlatforms();