-
Notifications
You must be signed in to change notification settings - Fork 1
/
sd.config.js
138 lines (131 loc) · 3.45 KB
/
sd.config.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
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
const yaml = require("yaml");
const StyleDictionary = require("style-dictionary");
// Custom transform for box-shadows
StyleDictionary.registerTransform({
name: "shadow/spreadShadow",
type: "value",
matcher: function (token) {
return token.type === "boxShadow";
},
transformer: (token) => {
const shadows = Object.values(token.value);
const result = shadows.map(
(shadow) =>
`${shadow.x}px ${shadow.y}px ${shadow.blur}px ${shadow.spread}px ${shadow.color}`
);
return result.join(",");
},
});
// Custom transform for borderRadius
StyleDictionary.registerTransform({
name: "border/radius",
type: "value",
matcher: function (token) {
return token.type === "borderRadius";
},
transformer: (token) => {
return `${token.value}rem`;
},
});
// Custom transform to convert font sizes to rem
StyleDictionary.registerTransform({
name: "size/pxToRem",
type: "value",
matcher: function (token) {
return token.type === "fontSizes";
},
transformer: (token, options) => {
const baseFont = (options && options.basePxFontSize) || 16;
const floatVal = parseFloat(token.value);
if (isNaN(floatVal)) {
throwSizeError(token.name, token.value, "rem");
}
if (floatVal === 0) {
return "0";
}
return `${floatVal / baseFont}rem`;
},
});
module.exports = {
parsers: [
{
// A custom parser will only run against filenames that match the pattern
// This pattern will match any file with the .yaml extension.
// This allows you to mix different types of files in your token source
pattern: /\.yml$/,
// the parse function takes a single argument, which is an object with
// 2 attributes: contents which is a string of the file contents, and
// filePath which is the path of the file.
// The function is expected to return a plain object.
parse: ({ contents, filePath }) => yaml.parse(contents),
},
],
source: ["tokens/!(figma-export)/**/*.{json,yml}", "tokens/*.{json,yml}"],
platforms: {
// SCSS is only used to iterate over sass maps to generate dynamic custom
// properties. SCSS variables should not actually be used in code directly.
scss: {
transforms: [
"attribute/cti",
"name/cti/kebab",
"time/seconds",
"content/icon",
"size/rem",
"color/hsl",
"shadow/spreadShadow",
"border/radius",
"size/pxToRem",
],
buildPath: "build/scss/",
files: [
{
destination: "tokens.scss",
format: "scss/map-deep",
},
],
},
css: {
transforms: [
"attribute/cti",
"name/cti/kebab",
"time/seconds",
"content/icon",
"size/rem",
"color/hsl",
"shadow/spreadShadow",
"border/radius",
"size/pxToRem",
],
buildPath: "build/css/",
files: [
{
destination: "tokens.css",
format: "css/variables",
},
],
options: {
outputReferences: true,
},
},
json: {
transforms: [
"attribute/cti",
"name/cti/pascal",
"time/seconds",
"content/icon",
"size/rem",
"color/hsl",
"shadow/spreadShadow",
"border/radius",
"size/pxToRem",
],
buildPath: "build/json/",
files: [
{
destination: "tokens.json",
format: "json/nested",
},
],
},
},
};