-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle-dictionary-builder.js
More file actions
73 lines (68 loc) · 1.77 KB
/
style-dictionary-builder.js
File metadata and controls
73 lines (68 loc) · 1.77 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
import StyleDictionary from "style-dictionary";
import { register } from "@tokens-studio/sd-transforms";
register(StyleDictionary);
const generateConfig = (name, sources, buildPath = "src/.cache/tokens/") => {
return {
source: sources,
platforms: {
css: {
preprocessors: ["tokens-studio"],
transformGroup: "tokens-studio",
transforms: ["size/pxToRem", "shadow/css/shorthand", "name/kebab"],
buildPath: buildPath,
files: [
{
destination: `${name}.css`,
format: "css/variables",
options: {
outputReferences: true,
},
},
],
},
js: {
preprocessors: ["tokens-studio"],
transformGroup: "tokens-studio",
transforms: ["size/pxToRem", "shadow/css/shorthand", "name/pascal"],
buildPath: buildPath,
files: [
{
format: "javascript/esm",
destination: `${name}.js`,
options: {
outputReferences: true,
},
},
{
format: "typescript/module-declarations",
destination: `${name}.d.ts`,
options: {
outputReferences: true,
},
},
],
},
},
};
};
const configs = {
light: generateConfig("light", [
"tokens/core.json",
"tokens/light.json",
"tokens/theme.json",
]),
dark: generateConfig("dark", [
"tokens/core.json",
"tokens/dark.json",
"tokens/theme.json",
]),
};
export const buildTokens = async () => {
for (const cfg of Object.values(configs)) {
const sd = new StyleDictionary(cfg);
await sd.buildAllPlatforms();
}
};
if (import.meta.url === import.meta.resolve(process.argv[1])) {
buildTokens();
}