@madgex/design-system 9.3.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -1
- package/dist/_tokens/css/{_tokens.css → variables.css} +3 -4
- package/dist/_tokens/js/_tokens-module.js +2599 -3884
- package/dist/_tokens/json/{_tokens-flat.json → variables-flat.json} +2 -28
- package/dist/_tokens/json/variables.json +331 -0
- package/dist/assets/icons.json +1 -1
- package/dist/css/index.css +1 -1
- package/dist/js/index.js +1 -1
- package/package.json +14 -17
- package/src/components/_preview.njk +1 -1
- package/src/components/inputs/combobox/combobox.scss +9 -3
- package/src/components/modal/modal.js +1 -1
- package/src/components/popover/popover.js +1 -1
- package/src/components/tabs/tabs.js +1 -1
- package/src/scss/constants/_sd-tokens.scss +1 -2
- package/src/tokens/_constants.json +35 -33
- package/src/tokens/color.json +64 -63
- package/src/tokens/custom.json +11 -7
- package/src/tokens/effects.json +4 -3
- package/src/tokens/email.json +30 -27
- package/src/tokens/size.json +16 -15
- package/src/tokens/typography.json +68 -62
- package/style-dictionary/color-transforms.js +143 -0
- package/style-dictionary/index.js +215 -0
- package/tasks/tokens.js +8 -26
- package/dist/_tokens/json/_tokens-nested.json +0 -4024
- package/src/tokens/_config.js +0 -181
- package/tasks/colorTransforms.js +0 -65
- package/tasks/registerTransforms.js +0 -17
|
@@ -1,206 +1,212 @@
|
|
|
1
1
|
{
|
|
2
2
|
"font": {
|
|
3
3
|
"family": {
|
|
4
|
+
"$type": "fontFamily",
|
|
4
5
|
"base": {
|
|
5
|
-
"value": "\"Helvetica\", Arial, sans-serif"
|
|
6
|
+
"$value": "\"Helvetica\", Arial, sans-serif"
|
|
6
7
|
},
|
|
7
8
|
"heading": {
|
|
8
9
|
"base": {
|
|
9
|
-
"value": "{font.family.base
|
|
10
|
+
"$value": "{font.family.base}"
|
|
10
11
|
},
|
|
11
12
|
"1": {
|
|
12
|
-
"value": "{font.family.heading.base
|
|
13
|
+
"$value": "{font.family.heading.base}"
|
|
13
14
|
},
|
|
14
15
|
"2": {
|
|
15
|
-
"value": "{font.family.heading.base
|
|
16
|
+
"$value": "{font.family.heading.base}"
|
|
16
17
|
},
|
|
17
18
|
"3": {
|
|
18
|
-
"value": "{font.family.heading.base
|
|
19
|
+
"$value": "{font.family.heading.base}"
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
"button": {
|
|
22
23
|
"base": {
|
|
23
|
-
"value": "{font.family.base
|
|
24
|
+
"$value": "{font.family.base}"
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
"weight": {
|
|
29
|
+
"$type": "fontWeight",
|
|
28
30
|
"base": {
|
|
29
|
-
"value": "400"
|
|
31
|
+
"$value": "400"
|
|
30
32
|
},
|
|
31
33
|
"heading": {
|
|
32
34
|
"base": {
|
|
33
|
-
"value": "{font.weight.base
|
|
35
|
+
"$value": "{font.weight.base}"
|
|
34
36
|
},
|
|
35
37
|
"1": {
|
|
36
|
-
"value": "{font.weight.heading.base
|
|
38
|
+
"$value": "{font.weight.heading.base}"
|
|
37
39
|
},
|
|
38
40
|
"2": {
|
|
39
|
-
"value": "{font.weight.heading.base
|
|
41
|
+
"$value": "{font.weight.heading.base}"
|
|
40
42
|
},
|
|
41
43
|
"3": {
|
|
42
|
-
"value": "{font.weight.heading.base
|
|
44
|
+
"$value": "{font.weight.heading.base}"
|
|
43
45
|
}
|
|
44
46
|
},
|
|
45
47
|
"button": {
|
|
46
48
|
"base": {
|
|
47
|
-
"value": "{font.weight.base
|
|
49
|
+
"$value": "{font.weight.base}"
|
|
48
50
|
}
|
|
49
51
|
},
|
|
50
52
|
"link": {
|
|
51
53
|
"base": {
|
|
52
|
-
"value": "inherit"
|
|
54
|
+
"$value": "inherit"
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
},
|
|
56
58
|
"spacing": {
|
|
59
|
+
"$type": "letterSpacing",
|
|
57
60
|
"base": {
|
|
58
|
-
"value": "normal"
|
|
61
|
+
"$value": "normal"
|
|
59
62
|
},
|
|
60
63
|
"heading": {
|
|
61
64
|
"base": {
|
|
62
|
-
"value": "{font.spacing.base
|
|
65
|
+
"$value": "{font.spacing.base}"
|
|
63
66
|
},
|
|
64
67
|
"1": {
|
|
65
|
-
"value": "{font.spacing.heading.base
|
|
68
|
+
"$value": "{font.spacing.heading.base}"
|
|
66
69
|
},
|
|
67
70
|
"2": {
|
|
68
|
-
"value": "{font.spacing.heading.base
|
|
71
|
+
"$value": "{font.spacing.heading.base}"
|
|
69
72
|
},
|
|
70
73
|
"3": {
|
|
71
|
-
"value": "{font.spacing.heading.base
|
|
74
|
+
"$value": "{font.spacing.heading.base}"
|
|
72
75
|
}
|
|
73
76
|
},
|
|
74
77
|
"button": {
|
|
75
|
-
"value": "{font.spacing.base
|
|
78
|
+
"$value": "{font.spacing.base}"
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
81
|
"type": {
|
|
82
|
+
"$type": "dimension",
|
|
79
83
|
"s-2": {
|
|
80
84
|
"size": {
|
|
81
|
-
"value": "0.75rem"
|
|
85
|
+
"$value": "0.75rem"
|
|
82
86
|
},
|
|
83
|
-
"line-height": {
|
|
84
|
-
"value": "1.35"
|
|
87
|
+
"line-height": {
|
|
88
|
+
"$value": "1.35"
|
|
85
89
|
}
|
|
86
90
|
},
|
|
87
91
|
"s-1": {
|
|
88
92
|
"size": {
|
|
89
|
-
"value": "0.875rem"
|
|
93
|
+
"$value": "0.875rem"
|
|
90
94
|
},
|
|
91
|
-
"line-height": {
|
|
92
|
-
"value": "1.35"
|
|
95
|
+
"line-height": {
|
|
96
|
+
"$value": "1.35"
|
|
93
97
|
}
|
|
94
98
|
},
|
|
95
99
|
"s0": {
|
|
96
100
|
"size": {
|
|
97
|
-
"value": "1rem"
|
|
101
|
+
"$value": "1rem"
|
|
98
102
|
},
|
|
99
|
-
"line-height": {
|
|
100
|
-
"value": "1.4"
|
|
103
|
+
"line-height": {
|
|
104
|
+
"$value": "1.4"
|
|
101
105
|
}
|
|
102
106
|
},
|
|
103
107
|
"s1": {
|
|
104
108
|
"size": {
|
|
105
|
-
"value": "clamp(1.067rem, 1.0468rem + 0.1009vi, 1.125rem)"
|
|
109
|
+
"$value": "clamp(1.067rem, 1.0468rem + 0.1009vi, 1.125rem)"
|
|
106
110
|
},
|
|
107
|
-
"line-height": {
|
|
108
|
-
"value": "1.4"
|
|
111
|
+
"line-height": {
|
|
112
|
+
"$value": "1.4"
|
|
109
113
|
}
|
|
110
114
|
},
|
|
111
115
|
"s2": {
|
|
112
116
|
"size": {
|
|
113
|
-
"value": "clamp(1.1385rem, 1.0943rem + 0.2211vi, 1.2656rem)"
|
|
117
|
+
"$value": "clamp(1.1385rem, 1.0943rem + 0.2211vi, 1.2656rem)"
|
|
114
118
|
},
|
|
115
|
-
"line-height": {
|
|
116
|
-
"value": "1.2"
|
|
119
|
+
"line-height": {
|
|
120
|
+
"$value": "1.2"
|
|
117
121
|
}
|
|
118
122
|
},
|
|
119
123
|
"s3": {
|
|
120
124
|
"size": {
|
|
121
|
-
"value": "clamp(1.2148rem, 1.1421rem + 0.3636vi, 1.4238rem)"
|
|
125
|
+
"$value": "clamp(1.2148rem, 1.1421rem + 0.3636vi, 1.4238rem)"
|
|
122
126
|
},
|
|
123
|
-
"line-height": {
|
|
124
|
-
"value": "1.2"
|
|
127
|
+
"line-height": {
|
|
128
|
+
"$value": "1.2"
|
|
125
129
|
}
|
|
126
130
|
},
|
|
127
131
|
"s4": {
|
|
128
132
|
"size": {
|
|
129
|
-
"value": "clamp(1.2962rem, 1.1898rem + 0.5316vi, 1.6018rem)"
|
|
133
|
+
"$value": "clamp(1.2962rem, 1.1898rem + 0.5316vi, 1.6018rem)"
|
|
130
134
|
},
|
|
131
|
-
"line-height": {
|
|
132
|
-
"value": "1.2"
|
|
135
|
+
"line-height": {
|
|
136
|
+
"$value": "1.2"
|
|
133
137
|
}
|
|
134
138
|
},
|
|
135
139
|
"s5": {
|
|
136
140
|
"size": {
|
|
137
|
-
"value": "clamp(1.383rem, 1.2372rem + 0.7288vi, 1.802rem)"
|
|
141
|
+
"$value": "clamp(1.383rem, 1.2372rem + 0.7288vi, 1.802rem)"
|
|
138
142
|
},
|
|
139
|
-
"line-height": {
|
|
140
|
-
"value": "1.2"
|
|
143
|
+
"line-height": {
|
|
144
|
+
"$value": "1.2"
|
|
141
145
|
}
|
|
142
146
|
},
|
|
143
147
|
"s6": {
|
|
144
148
|
"size": {
|
|
145
|
-
"value": "clamp(1.4757rem, 1.2838rem + 0.9593vi, 2.0273rem)"
|
|
149
|
+
"$value": "clamp(1.4757rem, 1.2838rem + 0.9593vi, 2.0273rem)"
|
|
146
150
|
},
|
|
147
|
-
"line-height": {
|
|
148
|
-
"value": "1.15"
|
|
151
|
+
"line-height": {
|
|
152
|
+
"$value": "1.15"
|
|
149
153
|
}
|
|
150
154
|
},
|
|
151
155
|
"s7": {
|
|
152
156
|
"size": {
|
|
153
|
-
"value": "clamp(1.5745rem, 1.3289rem + 1.2281vi, 2.2807rem)"
|
|
157
|
+
"$value": "clamp(1.5745rem, 1.3289rem + 1.2281vi, 2.2807rem)"
|
|
154
158
|
},
|
|
155
|
-
"line-height": {
|
|
156
|
-
"value": "1.15"
|
|
159
|
+
"line-height": {
|
|
160
|
+
"$value": "1.15"
|
|
157
161
|
}
|
|
158
162
|
},
|
|
159
163
|
"s8": {
|
|
160
164
|
"size": {
|
|
161
|
-
"value": "clamp(1.68rem, 1.3719rem + 1.5405vi, 2.5658rem)"
|
|
165
|
+
"$value": "clamp(1.68rem, 1.3719rem + 1.5405vi, 2.5658rem)"
|
|
162
166
|
},
|
|
163
|
-
"line-height": {
|
|
164
|
-
"value": "1.15"
|
|
167
|
+
"line-height": {
|
|
168
|
+
"$value": "1.15"
|
|
165
169
|
}
|
|
166
170
|
},
|
|
167
171
|
"s9": {
|
|
168
172
|
"size": {
|
|
169
|
-
"value": "clamp(1.7926rem, 1.4121rem + 1.9025vi, 2.8865rem)"
|
|
173
|
+
"$value": "clamp(1.7926rem, 1.4121rem + 1.9025vi, 2.8865rem)"
|
|
170
174
|
},
|
|
171
|
-
"line-height": {
|
|
172
|
-
"value": "1.15"
|
|
175
|
+
"line-height": {
|
|
176
|
+
"$value": "1.15"
|
|
173
177
|
}
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
},
|
|
177
181
|
"text": {
|
|
178
182
|
"transform": {
|
|
183
|
+
"$type": "textTransform",
|
|
179
184
|
"heading": {
|
|
180
185
|
"base": {
|
|
181
|
-
"value": "none"
|
|
186
|
+
"$value": "none"
|
|
182
187
|
},
|
|
183
188
|
"1": {
|
|
184
|
-
"value": "{text.transform.heading.base
|
|
189
|
+
"$value": "{text.transform.heading.base}"
|
|
185
190
|
},
|
|
186
191
|
"2": {
|
|
187
|
-
"value": "{text.transform.heading.base
|
|
192
|
+
"$value": "{text.transform.heading.base}"
|
|
188
193
|
},
|
|
189
194
|
"3": {
|
|
190
|
-
"value": "{text.transform.heading.base
|
|
195
|
+
"$value": "{text.transform.heading.base}"
|
|
191
196
|
}
|
|
192
197
|
},
|
|
193
198
|
"button": {
|
|
194
|
-
"value": "none"
|
|
199
|
+
"$value": "none"
|
|
195
200
|
}
|
|
196
201
|
},
|
|
197
202
|
"decoration": {
|
|
203
|
+
"$type": "textDecoration",
|
|
198
204
|
"link": {
|
|
199
205
|
"base": {
|
|
200
|
-
"value": "underline"
|
|
206
|
+
"$value": "underline"
|
|
201
207
|
},
|
|
202
208
|
"hover": {
|
|
203
|
-
"value": "underline"
|
|
209
|
+
"$value": "underline"
|
|
204
210
|
}
|
|
205
211
|
}
|
|
206
212
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const crypto = require('node:crypto');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const fs = require('node:fs/promises');
|
|
5
|
+
const { TinyColor } = require('@ctrl/tinycolor');
|
|
6
|
+
|
|
7
|
+
const TRANSFORM_AMOUNTS = {
|
|
8
|
+
LIGHT: 10,
|
|
9
|
+
LIGHTEST: 95,
|
|
10
|
+
DARK: 10,
|
|
11
|
+
DARKEST: 12,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef ColorGroupItem
|
|
16
|
+
* @type {object}
|
|
17
|
+
* @property {string} $value
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef ColorGroupInput
|
|
22
|
+
* @type {object}
|
|
23
|
+
* @property {!ColorGroupItem} base
|
|
24
|
+
* @property {?ColorGroupItem} light
|
|
25
|
+
* @property {?ColorGroupItem} lightest
|
|
26
|
+
* @property {?ColorGroupItem} dark
|
|
27
|
+
* @property {?ColorGroupItem} darkest
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Replicates Sass lightness($color) function
|
|
32
|
+
|
|
33
|
+
* @param {TinyColor} color
|
|
34
|
+
* @returns {number}
|
|
35
|
+
*/
|
|
36
|
+
function lightness(color) {
|
|
37
|
+
const { l } = color.toHsl();
|
|
38
|
+
|
|
39
|
+
return l * 100;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* adds `light`, `lightest`, `dark` and `darkest` to a token colour group, derived from `colorGroup.base.$value`.
|
|
44
|
+
*
|
|
45
|
+
* If keys already exist, they are **not** overwritten.
|
|
46
|
+
*
|
|
47
|
+
* @param {ColorGroupInput} colorGroup {base, light?, lightest?, dark?, darkest? }
|
|
48
|
+
* @returns {ColorGroupInput} {base, light, lightest, dark, darkest }
|
|
49
|
+
*/
|
|
50
|
+
function createColorsFromBase(colorGroup) {
|
|
51
|
+
const { base = {}, light = {}, lightest = {}, dark = {}, darkest = {} } = colorGroup;
|
|
52
|
+
const asTinyColor = new TinyColor(base.$value);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
base,
|
|
56
|
+
light: {
|
|
57
|
+
...light,
|
|
58
|
+
$value: light.$value || asTinyColor.lighten(TRANSFORM_AMOUNTS.LIGHT).toHexString(),
|
|
59
|
+
},
|
|
60
|
+
lightest: {
|
|
61
|
+
...lightest,
|
|
62
|
+
$value: lightest.$value || asTinyColor.lighten(TRANSFORM_AMOUNTS.LIGHTEST - lightness(asTinyColor)).toHexString(),
|
|
63
|
+
},
|
|
64
|
+
dark: {
|
|
65
|
+
...dark,
|
|
66
|
+
$value: dark?.$value || asTinyColor.darken(TRANSFORM_AMOUNTS.DARK).toHexString(),
|
|
67
|
+
},
|
|
68
|
+
darkest: {
|
|
69
|
+
...darkest,
|
|
70
|
+
$value: darkest?.$value || asTinyColor.darken(lightness(asTinyColor) - TRANSFORM_AMOUNTS.DARKEST).toHexString(),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* For each `tokensObject.color.brand.*`, add lightness tokens, if they dont already exist
|
|
77
|
+
*
|
|
78
|
+
* @param {object} tokensObject
|
|
79
|
+
* @returns {object} modified tokensObject
|
|
80
|
+
*/
|
|
81
|
+
function addBrandColorLightnessTokens(tokensObject) {
|
|
82
|
+
const { brand } = tokensObject.color;
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...tokensObject,
|
|
86
|
+
color: {
|
|
87
|
+
...tokensObject.color,
|
|
88
|
+
/**
|
|
89
|
+
* focus on `brand` object
|
|
90
|
+
*
|
|
91
|
+
* loop through all brand group keys e.g. "1", "2", "3"
|
|
92
|
+
*
|
|
93
|
+
* apply `createColorsFromBase` to each color group
|
|
94
|
+
*/
|
|
95
|
+
brand: Object.keys(brand).reduce((accu, brandKey) => {
|
|
96
|
+
const colorGroup = brand[brandKey];
|
|
97
|
+
const populatedColorGroup = createColorsFromBase(colorGroup);
|
|
98
|
+
// eslint-disable-next-line no-param-reassign
|
|
99
|
+
accu[brandKey] = { ...colorGroup, ...populatedColorGroup };
|
|
100
|
+
return accu;
|
|
101
|
+
}, {}),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports.addBrandColorLightnessTokens = addBrandColorLightnessTokens;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Although `addBrandColorLightnessTokens` does the job of adding lighten tokens to `color.brand.*` JSON, this function purely
|
|
110
|
+
* exists to: read, transform, and then write the result to a new temporary file.
|
|
111
|
+
*
|
|
112
|
+
* For use in Style Dictionary `source` array. Style Dictionary only supports files written to disk for `source` 🥲
|
|
113
|
+
*
|
|
114
|
+
* @param {string} originalFilePath path to original tokens json file
|
|
115
|
+
* @returns {string} new file path
|
|
116
|
+
*/
|
|
117
|
+
async function writeTransformedFileBrandColorLightnessTokens(originalFilePath) {
|
|
118
|
+
// construct new unique temp file path name where we will save new json file to disk
|
|
119
|
+
const TMP_DIR = await fs.realpath(os.tmpdir());
|
|
120
|
+
const filename = path.parse(originalFilePath).name;
|
|
121
|
+
const newTempFilePath = path.join(
|
|
122
|
+
TMP_DIR,
|
|
123
|
+
`/madgex-design-system/${filename}-transformed-${crypto.randomUUID()}.json`
|
|
124
|
+
);
|
|
125
|
+
const tmpDirPath = path.dirname(newTempFilePath);
|
|
126
|
+
|
|
127
|
+
// create temp folder if it doesn't exist
|
|
128
|
+
try {
|
|
129
|
+
await fs.access(tmpDirPath);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
await fs.mkdir(tmpDirPath, { recursive: true });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// read original tokens file
|
|
135
|
+
const colorTokens = await fs.readFile(originalFilePath, { encoding: 'utf8' });
|
|
136
|
+
// transform tokens
|
|
137
|
+
const transformed = JSON.stringify(addBrandColorLightnessTokens(JSON.parse(colorTokens)), null, ' ');
|
|
138
|
+
// write new file with transformed tokens
|
|
139
|
+
await fs.writeFile(newTempFilePath, transformed);
|
|
140
|
+
// return new file name for use in createStyleDictionary
|
|
141
|
+
return newTempFilePath;
|
|
142
|
+
}
|
|
143
|
+
module.exports.writeTransformedFileBrandColorLightnessTokens = writeTransformedFileBrandColorLightnessTokens;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
const fs = require('node:fs/promises');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { glob } = require('glob');
|
|
4
|
+
const { writeTransformedFileBrandColorLightnessTokens } = require('./color-transforms');
|
|
5
|
+
|
|
6
|
+
const defaultDistDir = path.resolve(__dirname, '../dist/_tokens/');
|
|
7
|
+
/**
|
|
8
|
+
* Base Style Dictionary Config which includes our base tokens.
|
|
9
|
+
* @type {import('style-dictionary').Config}
|
|
10
|
+
*/
|
|
11
|
+
const baseConfig = Object.freeze({
|
|
12
|
+
log: {
|
|
13
|
+
verbosity: 'verbose',
|
|
14
|
+
},
|
|
15
|
+
// This include path needs to be in posix because combineJSON util inside style dictionary only accepts that
|
|
16
|
+
include: [path.posix.resolve(__dirname, '../src/tokens/*.json')],
|
|
17
|
+
hooks: {
|
|
18
|
+
transforms: {
|
|
19
|
+
/**
|
|
20
|
+
* escape when we need to pass through the token value without transformation.
|
|
21
|
+
*
|
|
22
|
+
* Try not to use this.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```json
|
|
26
|
+
* {
|
|
27
|
+
* "myStrangeItem": {
|
|
28
|
+
* "$value": "special-new-css-value",
|
|
29
|
+
* "$type": "raw"
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*/
|
|
33
|
+
'css/rawData': {
|
|
34
|
+
type: 'value',
|
|
35
|
+
filter: (token) => token.type === 'raw',
|
|
36
|
+
transform: (token) => token.rawData,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* various outputs
|
|
42
|
+
*
|
|
43
|
+
* transforms match the `type` on each token, built in transforms: https://styledictionary.com/reference/hooks/transforms/predefined/
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
platforms: {
|
|
48
|
+
/**
|
|
49
|
+
* Primary CSS Variables render
|
|
50
|
+
*/
|
|
51
|
+
'css-variables': {
|
|
52
|
+
transforms: ['name/kebab', 'color/css', 'css/rawData'],
|
|
53
|
+
buildPath: path.join(defaultDistDir, 'css/'),
|
|
54
|
+
prefix: 'mds',
|
|
55
|
+
files: [
|
|
56
|
+
{
|
|
57
|
+
destination: 'variables.css',
|
|
58
|
+
format: 'css/variables',
|
|
59
|
+
filter: 'removePrivate',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* used to render another scss source file! Constants for use in main DS scss build
|
|
65
|
+
*/
|
|
66
|
+
'scss-variables': {
|
|
67
|
+
transforms: ['name/kebab'],
|
|
68
|
+
buildPath: `${path.resolve(__dirname, '../src/scss/constants/')}/`,
|
|
69
|
+
prefix: 'constant',
|
|
70
|
+
files: [
|
|
71
|
+
{
|
|
72
|
+
destination: '_sd-tokens.scss',
|
|
73
|
+
format: 'scss/map-deep',
|
|
74
|
+
options: {
|
|
75
|
+
themeable: false,
|
|
76
|
+
},
|
|
77
|
+
filter(token) {
|
|
78
|
+
// only keep "private" tokens aka constants
|
|
79
|
+
return !!(token && token.private);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* used by:
|
|
86
|
+
*
|
|
87
|
+
* #### 'template-renderer'
|
|
88
|
+
* https://github.com/wiley/madgex-template-renderer/blob/e5eb868e6b789a8d751efc98768672d877196fa5/lib/services/dataUtils.js#L101
|
|
89
|
+
*
|
|
90
|
+
* #### display-image-render-api
|
|
91
|
+
* https://github.com/wiley/madgex-display-image-render-api/blob/27e6e219400a98a41f39861c8b362a0849888ea3/lib/services/templates.js#L157
|
|
92
|
+
*/
|
|
93
|
+
'json-variables': {
|
|
94
|
+
// transformGroup: 'js',
|
|
95
|
+
transforms: ['name/kebab', 'color/css'],
|
|
96
|
+
buildPath: path.join(defaultDistDir, 'json/'),
|
|
97
|
+
files: [
|
|
98
|
+
{
|
|
99
|
+
destination: 'variables.json',
|
|
100
|
+
format: 'json/nested',
|
|
101
|
+
// https://github.com/amzn/style-dictionary/blob/f2395f3d4638e1fa57a86bd821b28e2f043067c4/lib/common/filters.js#L28
|
|
102
|
+
filter: 'removePrivate',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* used by Jack's Chrome Extension
|
|
108
|
+
*/
|
|
109
|
+
'json-variables-flat': {
|
|
110
|
+
// transformGroup: 'js',
|
|
111
|
+
transforms: ['name/kebab', 'color/css'],
|
|
112
|
+
buildPath: path.join(defaultDistDir, 'json/'),
|
|
113
|
+
files: [
|
|
114
|
+
{
|
|
115
|
+
destination: 'variables-flat.json',
|
|
116
|
+
format: 'json/flat',
|
|
117
|
+
// https://github.com/amzn/style-dictionary/blob/f2395f3d4638e1fa57a86bd821b28e2f043067c4/lib/common/filters.js#L28
|
|
118
|
+
filter: 'removePrivate',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* only used for fractal docs visualisation of tokens
|
|
124
|
+
*/
|
|
125
|
+
'js-module': {
|
|
126
|
+
transforms: ['name/pascal'],
|
|
127
|
+
buildPath: path.join(defaultDistDir, 'js/'),
|
|
128
|
+
prefix: 'mds',
|
|
129
|
+
files: [
|
|
130
|
+
{
|
|
131
|
+
destination: '_tokens-module.js',
|
|
132
|
+
format: 'javascript/module',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* Create an instance of Style Dictionary with base Design System tokens already loaded.
|
|
142
|
+
*
|
|
143
|
+
* Supplied `source` paths will have brand color transformation applied
|
|
144
|
+
*
|
|
145
|
+
* existing Design System `platforms` which can be overriden (e.g. override buildPath)
|
|
146
|
+
*
|
|
147
|
+
* - 'css-variables'
|
|
148
|
+
* - 'scss-variables'
|
|
149
|
+
* - 'json-variables'
|
|
150
|
+
* - 'json-variables-flat'
|
|
151
|
+
* - 'js-module'
|
|
152
|
+
*
|
|
153
|
+
* @param {import('style-dictionary').Config} incomingConfig
|
|
154
|
+
* @param {import('style-dictionary').PlatformConfig} incomingConfig.platforms
|
|
155
|
+
* @param {Array<string>} incomingConfig.source
|
|
156
|
+
*
|
|
157
|
+
* @returns {{styleDictionary:import('style-dictionary').default, cleanTempFiles: Function}} Style Dictionary Config
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```javascript
|
|
161
|
+
* // frontend-rollout-tool only wants to build 2 platforms to specific directories
|
|
162
|
+
* const { styleDictionary, cleanTempFiles } = await createStyleDictionary({
|
|
163
|
+
* // override platform defaults, like buildPath
|
|
164
|
+
* platforms: {
|
|
165
|
+
* 'css-variables': { buildPath: Path.join(buildPath, 'css-vars/') },
|
|
166
|
+
* 'json-variables': { buildPath: Path.join(buildPath, 'json/') },
|
|
167
|
+
* },
|
|
168
|
+
* source: [Path.join(srcTokensPath, 'brand.json')]
|
|
169
|
+
* })
|
|
170
|
+
* await styleDictionary.buildPlatform('css-variables');
|
|
171
|
+
* await styleDictionary.buildPlatform('json-variables');
|
|
172
|
+
* await cleanTempFiles();
|
|
173
|
+
*
|
|
174
|
+
* ///////////////////////////////
|
|
175
|
+
*
|
|
176
|
+
* // Design System wants to build all platforms to default directories
|
|
177
|
+
* const { styleDictionary, cleanTempFiles } = await createStyleDictionary();
|
|
178
|
+
* await styleDictionary.buildAllPlatforms();
|
|
179
|
+
* await cleanTempFiles();
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
async function createStyleDictionary(incomingConfig = {}) {
|
|
183
|
+
const StyleDictionaryPackage = (await import('style-dictionary')).default;
|
|
184
|
+
|
|
185
|
+
// create Style Dictionary instance using base tokens, includes all our all platforms
|
|
186
|
+
let styleDictionary = new StyleDictionaryPackage(baseConfig);
|
|
187
|
+
|
|
188
|
+
// if source was supplied (e.g. by frontend-rollout-tool brand.json), make sure brand lightness is generated
|
|
189
|
+
const transformedSource = [];
|
|
190
|
+
// use `glob` on `source` as this is what style-dictionary uses, keep api compatability
|
|
191
|
+
const sourceFilePaths = await glob(incomingConfig?.source || []);
|
|
192
|
+
|
|
193
|
+
for (const sourceFilePath of sourceFilePaths) {
|
|
194
|
+
// forced to write new source files to disk (required for style-dictionary, unfortunately)
|
|
195
|
+
const newSourceFilePath = await writeTransformedFileBrandColorLightnessTokens(sourceFilePath);
|
|
196
|
+
transformedSource.push(newSourceFilePath);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const cleanTempFiles = async () => {
|
|
200
|
+
for (const sourceFilePath of sourceFilePaths) {
|
|
201
|
+
try {
|
|
202
|
+
await fs.unlink(sourceFilePath);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.warn('couldnt clean temp file ', sourceFilePath);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
// merged incomingConfig & transformed incomingConfig.source to our base styleDictionary
|
|
209
|
+
styleDictionary = await styleDictionary.extend({ ...incomingConfig, source: transformedSource });
|
|
210
|
+
|
|
211
|
+
await styleDictionary.hasInitialized;
|
|
212
|
+
return { styleDictionary, cleanTempFiles };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
module.exports.createStyleDictionary = createStyleDictionary;
|
package/tasks/tokens.js
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const { promisify } = require('util');
|
|
4
|
-
const StyleDictionaryPackage = require('style-dictionary');
|
|
5
|
-
const { registerTransforms } = require('./registerTransforms');
|
|
6
|
-
const transformTokens = require('./colorTransforms');
|
|
7
|
-
|
|
8
|
-
const readFileAsync = promisify(fs.readFile);
|
|
9
|
-
const writeFileAsync = promisify(fs.writeFile);
|
|
10
|
-
|
|
11
|
-
async function transformBaseTokens(filePath) {
|
|
12
|
-
const baseTokens = await readFileAsync(filePath, { encoding: 'utf8' });
|
|
13
|
-
const transformed = JSON.stringify(transformTokens(JSON.parse(baseTokens)), null, ' ')
|
|
14
|
-
// Add a space after every key, before the `:`
|
|
15
|
-
.replace(/: "(?:[^"]+|\\")*",?$/gm, ' $&');
|
|
16
|
-
|
|
17
|
-
return writeFileAsync(filePath, transformed);
|
|
18
|
-
}
|
|
1
|
+
const { createStyleDictionary } = require('../style-dictionary');
|
|
19
2
|
|
|
3
|
+
/**
|
|
4
|
+
* build tokens via style-dictionary
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
20
7
|
async function tokens() {
|
|
21
|
-
|
|
22
|
-
await transformBaseTokens(path.resolve(__dirname, '../src/tokens/color.json'));
|
|
23
|
-
const StyleDictionary = StyleDictionaryPackage.extend(path.resolve(__dirname, '../src/tokens/_config'));
|
|
8
|
+
const { styleDictionary, cleanTempFiles } = await createStyleDictionary();
|
|
24
9
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} catch (e) {
|
|
28
|
-
console.error(e);
|
|
29
|
-
}
|
|
10
|
+
await styleDictionary.buildAllPlatforms();
|
|
11
|
+
await cleanTempFiles();
|
|
30
12
|
}
|
|
31
13
|
|
|
32
14
|
exports.tokens = tokens;
|