@digdir/designsystemet 1.0.7 → 1.1.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/dist/bin/config.d.ts +12 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +517 -0
- package/dist/bin/designsystemet.js +3699 -3572
- package/dist/config.schema.json +1 -0
- package/dist/src/colors/index.d.ts +2 -2
- package/dist/src/colors/index.d.ts.map +1 -1
- package/dist/src/colors/index.js +143 -143
- package/dist/src/colors/theme.d.ts +1 -2
- package/dist/src/colors/theme.d.ts.map +1 -1
- package/dist/src/config.d.ts +25 -14
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +68 -24
- package/dist/src/index.js +431 -404
- package/dist/src/migrations/beta-to-v1.js +9 -2
- package/dist/src/migrations/codemods/css/run.js +9 -2
- package/dist/src/migrations/color-rename-next49.js +9 -2
- package/dist/src/migrations/index.js +9 -2
- package/dist/src/scripts/createJsonSchema.js +28 -23
- package/dist/src/scripts/update-template.d.ts.map +1 -1
- package/dist/src/scripts/update-template.js +9 -2
- package/dist/src/tokens/build.d.ts +1 -1
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +140 -57
- package/dist/src/tokens/create/generators/$designsystemet.js +13 -14
- package/dist/src/tokens/create/generators/color.js +21 -21
- package/dist/src/tokens/create/write.js +23 -17
- package/dist/src/tokens/create.d.ts +1 -0
- package/dist/src/tokens/create.d.ts.map +1 -1
- package/dist/src/tokens/create.js +22 -21
- package/dist/src/tokens/format.d.ts +1 -1
- package/dist/src/tokens/format.d.ts.map +1 -1
- package/dist/src/tokens/format.js +916 -890
- package/dist/src/tokens/index.d.ts +2 -2
- package/dist/src/tokens/index.d.ts.map +1 -1
- package/dist/src/tokens/index.js +308 -281
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/color.js +17 -15
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/semantic.js +16 -14
- package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/storefront.js +12 -2
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/typography.js +16 -14
- package/dist/src/tokens/process/configs.d.ts.map +1 -1
- package/dist/src/tokens/process/configs.js +18 -31
- package/dist/src/tokens/process/formats/css/color.js +5 -3
- package/dist/src/tokens/process/formats/css/semantic.js +2 -2
- package/dist/src/tokens/process/formats/css/typography.js +1 -1
- package/dist/src/tokens/process/formats/css.js +8 -6
- package/dist/src/tokens/process/formats/js-tokens.js +12 -2
- package/dist/src/tokens/process/output/tailwind.d.ts +3 -0
- package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
- package/dist/src/tokens/process/output/tailwind.js +59 -0
- package/dist/src/tokens/process/{theme.d.ts → output/theme.d.ts} +2 -2
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
- package/dist/src/tokens/process/{theme.js → output/theme.js} +16 -17
- package/dist/src/tokens/process/platform.d.ts +6 -6
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/process/platform.js +46 -19
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +10 -9
- package/dist/src/tokens/types.d.ts +3 -3
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/tokens/utils.d.ts +2 -2
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/dist/src/tokens/utils.js +11 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +9 -2
- package/package.json +13 -14
- package/dist/src/tokens/process/theme.d.ts.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Command, OptionValues } from '@commander-js/extra-typings';
|
|
2
|
+
import { type ConfigSchemaBuild, type ConfigSchemaCreate } from '../src/config.js';
|
|
3
|
+
export declare function readConfigFile(configPath: string, allowFileNotFound?: boolean): Promise<string>;
|
|
4
|
+
export declare function parseCreateConfig(configFile: string, options: {
|
|
5
|
+
theme: string;
|
|
6
|
+
cmd: Command<unknown[], OptionValues>;
|
|
7
|
+
configPath: string;
|
|
8
|
+
}): Promise<ConfigSchemaCreate>;
|
|
9
|
+
export declare function parseBuildConfig(configFile: string, { configPath }: {
|
|
10
|
+
configPath: string;
|
|
11
|
+
}): Promise<ConfigSchemaBuild>;
|
|
12
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../bin/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGzE,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAKxB,MAAM,kBAAkB,CAAC;AAI1B,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,iBAAiB,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBlG;AAED,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACpF,OAAO,CAAC,kBAAkB,CAAC,CAqE7B;AAED,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GACrC,OAAO,CAAC,iBAAiB,CAAC,CAI5B"}
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
// bin/config.ts
|
|
2
|
+
import path2 from "path";
|
|
3
|
+
import chalk3 from "chalk";
|
|
4
|
+
import * as R8 from "ramda";
|
|
5
|
+
|
|
6
|
+
// src/config.ts
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import * as R7 from "ramda";
|
|
9
|
+
import { z } from "zod/v4";
|
|
10
|
+
import { fromError } from "zod-validation-error";
|
|
11
|
+
|
|
12
|
+
// src/colors/colorMetadata.ts
|
|
13
|
+
import * as R from "ramda";
|
|
14
|
+
var colorMetadata = {
|
|
15
|
+
"background-default": {
|
|
16
|
+
number: 1,
|
|
17
|
+
name: "background-default",
|
|
18
|
+
group: "background",
|
|
19
|
+
displayName: "Background Default",
|
|
20
|
+
description: {
|
|
21
|
+
long: "Background Default er den mest n\xF8ytrale bakgrunnsfargen.",
|
|
22
|
+
short: "Standard bakgrunnsfarge."
|
|
23
|
+
},
|
|
24
|
+
luminance: {
|
|
25
|
+
light: 1,
|
|
26
|
+
dark: 9e-3,
|
|
27
|
+
contrast: 1e-3
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"background-tinted": {
|
|
31
|
+
number: 2,
|
|
32
|
+
name: "background-tinted",
|
|
33
|
+
group: "background",
|
|
34
|
+
displayName: "Background Tinted",
|
|
35
|
+
description: {
|
|
36
|
+
long: "Background Tinted er en bakgrunnsfarge som har et hint av farge i seg.",
|
|
37
|
+
short: "Bakgrunn med et hint av farge i seg."
|
|
38
|
+
},
|
|
39
|
+
luminance: {
|
|
40
|
+
light: 0.9,
|
|
41
|
+
dark: 0.014,
|
|
42
|
+
contrast: 65e-4
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"surface-default": {
|
|
46
|
+
number: 3,
|
|
47
|
+
name: "surface-default",
|
|
48
|
+
group: "surface",
|
|
49
|
+
displayName: "Surface Default",
|
|
50
|
+
description: {
|
|
51
|
+
long: "Surface Default brukes p\xE5 flater som ligger opp\xE5 bakgrunnsfargene. Dette er den mest n\xF8ytrale surface fargen.",
|
|
52
|
+
short: "Standardfarge for overflater / komponenter."
|
|
53
|
+
},
|
|
54
|
+
luminance: {
|
|
55
|
+
light: 1,
|
|
56
|
+
dark: 0.021,
|
|
57
|
+
contrast: 0.015
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"surface-tinted": {
|
|
61
|
+
number: 4,
|
|
62
|
+
name: "surface-tinted",
|
|
63
|
+
group: "surface",
|
|
64
|
+
displayName: "Surface Tinted",
|
|
65
|
+
description: {
|
|
66
|
+
long: "Surface Tinted brukes p\xE5 flater som ligger opp\xE5 bakgrunnsfargene. Denne har et hint av farge i seg.",
|
|
67
|
+
short: "Overflater / komponenter med et hint av farge i seg."
|
|
68
|
+
},
|
|
69
|
+
luminance: {
|
|
70
|
+
light: 0.81,
|
|
71
|
+
dark: 0.027,
|
|
72
|
+
contrast: 0.015
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"surface-hover": {
|
|
76
|
+
number: 5,
|
|
77
|
+
name: "surface-hover",
|
|
78
|
+
group: "surface",
|
|
79
|
+
displayName: "Surface Hover",
|
|
80
|
+
description: {
|
|
81
|
+
long: "Surface Hover brukes p\xE5 interaktive flater som ligger opp\xE5 bakgrunnsfargene i en hover state.",
|
|
82
|
+
short: "Hover-farge til overflater / komponenter."
|
|
83
|
+
},
|
|
84
|
+
luminance: {
|
|
85
|
+
light: 0.7,
|
|
86
|
+
dark: 0.036,
|
|
87
|
+
contrast: 0.028
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"surface-active": {
|
|
91
|
+
number: 6,
|
|
92
|
+
name: "surface-active",
|
|
93
|
+
group: "surface",
|
|
94
|
+
displayName: "Surface Active",
|
|
95
|
+
description: {
|
|
96
|
+
long: "Surface Active brukes p\xE5 interaktive flater som ligger opp\xE5 bakgrunnsfargene i en active state.",
|
|
97
|
+
short: "Active-farge til overflater / komponenter."
|
|
98
|
+
},
|
|
99
|
+
luminance: {
|
|
100
|
+
light: 0.59,
|
|
101
|
+
dark: 0.056,
|
|
102
|
+
contrast: 0.045
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"border-subtle": {
|
|
106
|
+
number: 7,
|
|
107
|
+
name: "border-subtle",
|
|
108
|
+
group: "border",
|
|
109
|
+
displayName: "Border Subtle",
|
|
110
|
+
description: {
|
|
111
|
+
long: "Border Subtle er den lyseste border-fargen og brukes for \xE5 skille elementer fra hverandre.",
|
|
112
|
+
short: "Border-farge med lav kontrast til dekorativ bruk (skillelinjer)."
|
|
113
|
+
},
|
|
114
|
+
luminance: {
|
|
115
|
+
light: 0.5,
|
|
116
|
+
dark: 0.08,
|
|
117
|
+
contrast: 0.26
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"border-default": {
|
|
121
|
+
number: 8,
|
|
122
|
+
name: "border-default",
|
|
123
|
+
group: "border",
|
|
124
|
+
displayName: "Border Default",
|
|
125
|
+
description: {
|
|
126
|
+
long: "Border Default er en border-farge som brukes n\xE5r man \xF8nsker god kontrast mot bakgrunnsfargene.",
|
|
127
|
+
short: "Standard border-farge til skjemakomponenter og meningsb\xE6rende elementer."
|
|
128
|
+
},
|
|
129
|
+
luminance: {
|
|
130
|
+
light: 0.19,
|
|
131
|
+
dark: 0.22,
|
|
132
|
+
contrast: 0.4
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
"border-strong": {
|
|
136
|
+
number: 9,
|
|
137
|
+
name: "border-strong",
|
|
138
|
+
group: "border",
|
|
139
|
+
displayName: "Border Strong",
|
|
140
|
+
description: {
|
|
141
|
+
long: "Border Strong er den m\xF8rkeste border-fargen og brukes n\xE5r man \xF8nsker en veldig tydelig og sterk border.",
|
|
142
|
+
short: "Border-farge med h\xF8y kontrast for ekstra synlighet."
|
|
143
|
+
},
|
|
144
|
+
luminance: {
|
|
145
|
+
light: 0.11,
|
|
146
|
+
dark: 0.39,
|
|
147
|
+
contrast: 0.6
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"text-subtle": {
|
|
151
|
+
number: 10,
|
|
152
|
+
name: "text-subtle",
|
|
153
|
+
group: "text",
|
|
154
|
+
displayName: "Text Subtle",
|
|
155
|
+
description: {
|
|
156
|
+
long: "Text Subtle er den lyseste tekstfargen og brukes p\xE5 tekst som skal v\xE6re litt mindre synlig eller for \xE5 skape variasjon i typografien.",
|
|
157
|
+
short: "Tekst- og ikonfarge med lavere kontrast."
|
|
158
|
+
},
|
|
159
|
+
luminance: {
|
|
160
|
+
light: 0.11,
|
|
161
|
+
dark: 0.39,
|
|
162
|
+
contrast: 0.57
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"text-default": {
|
|
166
|
+
number: 11,
|
|
167
|
+
name: "text-default",
|
|
168
|
+
group: "text",
|
|
169
|
+
displayName: "Text Default",
|
|
170
|
+
description: {
|
|
171
|
+
long: "Text Default er den m\xF8rkeste tekstfargen og brukes p\xE5 tekst som skal v\xE6re mest synlig. Denne fargen b\xF8r brukes p\xE5 mesteparten av teksten p\xE5 en side.",
|
|
172
|
+
short: "Tekst- og ikonfarge med h\xF8y kontrast og god synlighet."
|
|
173
|
+
},
|
|
174
|
+
luminance: {
|
|
175
|
+
light: 0.0245,
|
|
176
|
+
dark: 0.84,
|
|
177
|
+
contrast: 0.86
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
"base-default": {
|
|
181
|
+
number: 12,
|
|
182
|
+
name: "base-default",
|
|
183
|
+
group: "base",
|
|
184
|
+
displayName: "Base Default",
|
|
185
|
+
description: {
|
|
186
|
+
long: "Base Default fargen f\xE5r den samme hex koden som fargen som er valgt i verkt\xF8yet. Brukes ofte som farge p\xE5 viktige elementer og p\xE5 flater som skal fange brukerens oppmerksomhet.",
|
|
187
|
+
short: "Standardfarge for solide bakgrunner."
|
|
188
|
+
},
|
|
189
|
+
luminance: {
|
|
190
|
+
light: 1,
|
|
191
|
+
dark: 1,
|
|
192
|
+
contrast: 1
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"base-hover": {
|
|
196
|
+
number: 13,
|
|
197
|
+
name: "base-hover",
|
|
198
|
+
group: "base",
|
|
199
|
+
displayName: "Base Hover",
|
|
200
|
+
description: {
|
|
201
|
+
long: "Base Hover brukes som hover farge p\xE5 elementer som bruker Base Default fargen.",
|
|
202
|
+
short: "Hover-farge for solide bakgrunner."
|
|
203
|
+
},
|
|
204
|
+
luminance: {
|
|
205
|
+
light: 1,
|
|
206
|
+
dark: 1,
|
|
207
|
+
contrast: 1
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
"base-active": {
|
|
211
|
+
number: 14,
|
|
212
|
+
name: "base-active",
|
|
213
|
+
group: "base",
|
|
214
|
+
displayName: "Base Active",
|
|
215
|
+
description: {
|
|
216
|
+
long: "Base Active brukes som active farge p\xE5 elementer som bruker Base Default fargen.",
|
|
217
|
+
short: "Active-farge for solide bakgrunner."
|
|
218
|
+
},
|
|
219
|
+
luminance: {
|
|
220
|
+
light: 1,
|
|
221
|
+
dark: 1,
|
|
222
|
+
contrast: 1
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
"base-contrast-subtle": {
|
|
226
|
+
number: 15,
|
|
227
|
+
name: "base-contrast-subtle",
|
|
228
|
+
group: "base",
|
|
229
|
+
displayName: "Contrast Subtle",
|
|
230
|
+
description: {
|
|
231
|
+
long: "Contrast Subtle brukes som en viktig meningsb\xE6rende farge opp\xE5 Base Default fargen.",
|
|
232
|
+
short: "Farge med god kontrast mot Base-default."
|
|
233
|
+
},
|
|
234
|
+
luminance: {
|
|
235
|
+
light: 1,
|
|
236
|
+
dark: 1,
|
|
237
|
+
contrast: 1
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
"base-contrast-default": {
|
|
241
|
+
number: 16,
|
|
242
|
+
name: "base-contrast-default",
|
|
243
|
+
group: "base",
|
|
244
|
+
displayName: "Contrast Default",
|
|
245
|
+
description: {
|
|
246
|
+
long: "Contrast Default brukes som en viktig meningsb\xE6rende farge opp\xE5 alle Base fargane.",
|
|
247
|
+
short: "Farge med god kontrast mot Base-default og Base-hover."
|
|
248
|
+
},
|
|
249
|
+
luminance: {
|
|
250
|
+
light: 1,
|
|
251
|
+
dark: 1,
|
|
252
|
+
contrast: 1
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var colorMetadataByNumber = R.indexBy((metadata) => metadata.number, Object.values(colorMetadata));
|
|
257
|
+
|
|
258
|
+
// src/colors/theme.ts
|
|
259
|
+
import chroma2 from "chroma-js";
|
|
260
|
+
import * as R2 from "ramda";
|
|
261
|
+
|
|
262
|
+
// src/colors/utils.ts
|
|
263
|
+
import chroma from "chroma-js";
|
|
264
|
+
import Colorjs from "colorjs.io";
|
|
265
|
+
import { Hsluv } from "hsluv";
|
|
266
|
+
var convertToHex = (color) => {
|
|
267
|
+
if (!color) {
|
|
268
|
+
return "#000000";
|
|
269
|
+
}
|
|
270
|
+
if (/^#[0-9A-Fa-f]{6}$/.test(color)) {
|
|
271
|
+
return color;
|
|
272
|
+
}
|
|
273
|
+
return chroma(color).hex();
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/colors/theme.ts
|
|
277
|
+
var RESERVED_COLORS = [
|
|
278
|
+
"neutral",
|
|
279
|
+
"success",
|
|
280
|
+
"warning",
|
|
281
|
+
"danger",
|
|
282
|
+
"info",
|
|
283
|
+
"blue",
|
|
284
|
+
"green",
|
|
285
|
+
"orange",
|
|
286
|
+
"purple",
|
|
287
|
+
"red"
|
|
288
|
+
];
|
|
289
|
+
|
|
290
|
+
// src/tokens/create/defaults.ts
|
|
291
|
+
import * as R3 from "ramda";
|
|
292
|
+
|
|
293
|
+
// src/tokens/create/generators/color.ts
|
|
294
|
+
import * as R4 from "ramda";
|
|
295
|
+
|
|
296
|
+
// src/tokens/create/generators/semantic.ts
|
|
297
|
+
import * as R5 from "ramda";
|
|
298
|
+
|
|
299
|
+
// src/tokens/create/generators/theme.ts
|
|
300
|
+
import * as R6 from "ramda";
|
|
301
|
+
|
|
302
|
+
// src/tokens/create.ts
|
|
303
|
+
var cliOptions = {
|
|
304
|
+
outDir: "out-dir",
|
|
305
|
+
clean: "clean",
|
|
306
|
+
tailwind: "tailwind",
|
|
307
|
+
theme: {
|
|
308
|
+
colors: {
|
|
309
|
+
main: "main-colors",
|
|
310
|
+
support: "support-colors",
|
|
311
|
+
neutral: "neutral-color"
|
|
312
|
+
},
|
|
313
|
+
typography: {
|
|
314
|
+
fontFamily: "font-family"
|
|
315
|
+
},
|
|
316
|
+
borderRadius: "border-radius"
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// src/config.ts
|
|
321
|
+
function mapPathToOptionName(path3) {
|
|
322
|
+
const normalisedPath = path3[0] === "themes" ? ["theme", ...R7.drop(2, path3)] : path3;
|
|
323
|
+
const option = R7.path(normalisedPath, cliOptions);
|
|
324
|
+
if (typeof option !== "string") {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
return option;
|
|
328
|
+
}
|
|
329
|
+
function makeFriendlyError(err) {
|
|
330
|
+
return fromError(err, {
|
|
331
|
+
messageBuilder: (issues) => issues.map((issue) => {
|
|
332
|
+
const issuePath = issue.path.join(".");
|
|
333
|
+
const optionName = mapPathToOptionName(issue.path);
|
|
334
|
+
const errorCode = `(error code: ${issue.code})`;
|
|
335
|
+
const optionMessage = optionName ? ` or CLI option --${optionName}` : "";
|
|
336
|
+
return ` - Error in JSON value ${chalk.red(issuePath)}${optionMessage}:
|
|
337
|
+
${issue.message} ${chalk.dim(errorCode)}`;
|
|
338
|
+
}).join("\n")
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function validateConfig(schema, unvalidatedConfig, configPath) {
|
|
342
|
+
try {
|
|
343
|
+
return schema.parse(unvalidatedConfig);
|
|
344
|
+
} catch (err) {
|
|
345
|
+
console.error(chalk.redBright(`Invalid config file at ${chalk.red(configPath)}`));
|
|
346
|
+
const validationError = makeFriendlyError(err);
|
|
347
|
+
console.error(validationError.toString());
|
|
348
|
+
process.exit(1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function parseConfig(schema, configFile, configPath) {
|
|
352
|
+
if (!configFile) {
|
|
353
|
+
return {};
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const parsedConfig = JSON.parse(configFile);
|
|
357
|
+
return schema.parse(parsedConfig);
|
|
358
|
+
} catch (err) {
|
|
359
|
+
console.error(chalk.redBright(`Failed parsing config file at ${chalk.red(configPath)}`));
|
|
360
|
+
const validationError = makeFriendlyError(err);
|
|
361
|
+
console.error(validationError.toString());
|
|
362
|
+
process.exit(1);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
var hexPatterns = [
|
|
366
|
+
// Hex colors: #000, #0000, #000000, #00000000
|
|
367
|
+
`#[0-9a-fA-F]{3}`,
|
|
368
|
+
`#[0-9a-fA-F]{4}`,
|
|
369
|
+
`#[0-9a-fA-F]{6}`,
|
|
370
|
+
`#[0-9a-fA-F]{8}`
|
|
371
|
+
];
|
|
372
|
+
var reservedColorsPattern = `^(?!(?:${RESERVED_COLORS.join("|")})$)`;
|
|
373
|
+
var colorRegex = new RegExp(`^${hexPatterns.join("|")}$`);
|
|
374
|
+
var colorSchema = z.string().regex(colorRegex).transform(convertToHex).describe(
|
|
375
|
+
`A hex color, which is used for creating a color scale. Invalid color names: ${RESERVED_COLORS.join(", ")}`
|
|
376
|
+
);
|
|
377
|
+
var colorCategorySchema = z.record(
|
|
378
|
+
z.string().regex(new RegExp(reservedColorsPattern, "i"), {
|
|
379
|
+
error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
|
|
380
|
+
}),
|
|
381
|
+
colorSchema,
|
|
382
|
+
{
|
|
383
|
+
error: "Color definitions must be hex color values"
|
|
384
|
+
}
|
|
385
|
+
).refine((colors) => !Object.keys(colors).some((key) => RESERVED_COLORS.includes(key.toLowerCase())), {
|
|
386
|
+
error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
|
|
387
|
+
}).describe("An object with one or more color definitions. The property name is used as the color name.");
|
|
388
|
+
var themeSchema = z.object({
|
|
389
|
+
colors: z.object({
|
|
390
|
+
main: colorCategorySchema,
|
|
391
|
+
support: colorCategorySchema.optional().default({}),
|
|
392
|
+
neutral: colorSchema
|
|
393
|
+
}).meta({ description: "Defines the colors for this theme" }),
|
|
394
|
+
typography: z.object({
|
|
395
|
+
fontFamily: z.string().meta({ description: "Sets the font-family for this theme" })
|
|
396
|
+
}).describe("Defines the typography for a given theme").optional(),
|
|
397
|
+
borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional()
|
|
398
|
+
}).meta({ description: "An object defining a theme. The property name holding the object becomes the theme name." });
|
|
399
|
+
var configFileBuildSchema = z.object({
|
|
400
|
+
clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional()
|
|
401
|
+
});
|
|
402
|
+
var configFileCreateSchema = z.object({
|
|
403
|
+
outDir: z.string().meta({ description: "Path to the output directory for the created design tokens" }),
|
|
404
|
+
clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional(),
|
|
405
|
+
themes: z.record(z.string(), themeSchema).meta({
|
|
406
|
+
description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
|
|
407
|
+
})
|
|
408
|
+
}).required();
|
|
409
|
+
var combinedConfigSchema = configFileCreateSchema.extend(configFileBuildSchema.shape);
|
|
410
|
+
|
|
411
|
+
// src/utils.ts
|
|
412
|
+
import fs from "fs/promises";
|
|
413
|
+
import chalk2 from "chalk";
|
|
414
|
+
var readFile = async (path3, dry, allowFileNotFound) => {
|
|
415
|
+
if (dry) {
|
|
416
|
+
console.log(`${chalk2.blue("readFile")} ${path3}`);
|
|
417
|
+
return Promise.resolve("");
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
return await fs.readFile(path3, "utf-8");
|
|
421
|
+
} catch (error) {
|
|
422
|
+
if (allowFileNotFound && error.code === "ENOENT") {
|
|
423
|
+
return "";
|
|
424
|
+
}
|
|
425
|
+
throw error;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// bin/options.ts
|
|
430
|
+
var getOptionIfMatchingSource = (...sources) => (command, option) => {
|
|
431
|
+
const source = command.getOptionValueSource(option);
|
|
432
|
+
if (sources.includes(source)) {
|
|
433
|
+
return command.getOptionValue(option);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var getSuppliedCliOption = getOptionIfMatchingSource("cli");
|
|
437
|
+
var getDefaultCliOption = getOptionIfMatchingSource("default");
|
|
438
|
+
var getCliOption = getOptionIfMatchingSource("cli", "default");
|
|
439
|
+
|
|
440
|
+
// bin/config.ts
|
|
441
|
+
async function readConfigFile(configPath, allowFileNotFound = true) {
|
|
442
|
+
const resolvedPath = path2.resolve(process.cwd(), configPath);
|
|
443
|
+
let configFile;
|
|
444
|
+
try {
|
|
445
|
+
configFile = await readFile(resolvedPath, false, allowFileNotFound);
|
|
446
|
+
} catch (err) {
|
|
447
|
+
if (allowFileNotFound) {
|
|
448
|
+
return "";
|
|
449
|
+
}
|
|
450
|
+
console.error(chalk3.redBright(`Could not read config file at ${chalk3.blue(resolvedPath)}`));
|
|
451
|
+
throw err;
|
|
452
|
+
}
|
|
453
|
+
if (configFile) {
|
|
454
|
+
console.log(`Found config file: ${chalk3.green(resolvedPath)}`);
|
|
455
|
+
}
|
|
456
|
+
return configFile;
|
|
457
|
+
}
|
|
458
|
+
async function parseCreateConfig(configFile, options) {
|
|
459
|
+
const { cmd, theme = "theme", configPath } = options;
|
|
460
|
+
const configParsed = parseConfig(
|
|
461
|
+
configFileCreateSchema,
|
|
462
|
+
configFile,
|
|
463
|
+
configPath
|
|
464
|
+
);
|
|
465
|
+
const themeColors = Object.values(configParsed?.themes ?? {}).map(
|
|
466
|
+
(x) => /* @__PURE__ */ new Set([...R8.keys(x.colors.main), ...R8.keys(x.colors.support)])
|
|
467
|
+
);
|
|
468
|
+
if (!R8.all(R8.equals(R8.__, themeColors[0]), themeColors)) {
|
|
469
|
+
console.error(chalk3.redBright(`In config, all themes must have the same custom color names, but we found:`));
|
|
470
|
+
const themeNames = R8.keys(configParsed.themes ?? {});
|
|
471
|
+
themeColors.forEach((colors, index) => {
|
|
472
|
+
const colorNames = Array.from(colors);
|
|
473
|
+
console.log(` - ${themeNames[index]}: ${colorNames.join(", ")}`);
|
|
474
|
+
});
|
|
475
|
+
console.log();
|
|
476
|
+
process.exit(1);
|
|
477
|
+
}
|
|
478
|
+
const noUndefined = R8.reject(R8.isNil);
|
|
479
|
+
const getThemeOptions = (optionGetter) => noUndefined({
|
|
480
|
+
colors: noUndefined({
|
|
481
|
+
main: optionGetter(cmd, "mainColors"),
|
|
482
|
+
support: optionGetter(cmd, "supportColors"),
|
|
483
|
+
neutral: optionGetter(cmd, "neutralColor")
|
|
484
|
+
}),
|
|
485
|
+
typography: noUndefined({
|
|
486
|
+
fontFamily: optionGetter(cmd, "fontFamily")
|
|
487
|
+
}),
|
|
488
|
+
borderRadius: optionGetter(cmd, "borderRadius"),
|
|
489
|
+
defaultColor: optionGetter(cmd, "defaultColor")
|
|
490
|
+
});
|
|
491
|
+
const unvalidatedConfig = noUndefined({
|
|
492
|
+
outDir: configParsed?.outDir ?? getCliOption(cmd, "outDir"),
|
|
493
|
+
clean: configParsed?.clean ?? getCliOption(cmd, "clean"),
|
|
494
|
+
themes: configParsed?.themes ? R8.map((jsonThemeValues) => {
|
|
495
|
+
const defaultThemeValues = getThemeOptions(getDefaultCliOption);
|
|
496
|
+
const cliThemeValues = getThemeOptions(getSuppliedCliOption);
|
|
497
|
+
const mergedConfigs = R8.mergeDeepRight(defaultThemeValues, R8.mergeDeepRight(jsonThemeValues, cliThemeValues));
|
|
498
|
+
return mergedConfigs;
|
|
499
|
+
}, configParsed.themes) : (
|
|
500
|
+
// If there are no themes specified in the JSON config, we use both explicit
|
|
501
|
+
// and default theme options from the CLI.
|
|
502
|
+
{
|
|
503
|
+
[theme]: getThemeOptions(getCliOption)
|
|
504
|
+
}
|
|
505
|
+
)
|
|
506
|
+
});
|
|
507
|
+
return validateConfig(configFileCreateSchema, unvalidatedConfig, configPath);
|
|
508
|
+
}
|
|
509
|
+
async function parseBuildConfig(configFile, { configPath }) {
|
|
510
|
+
const configParsed = parseConfig(configFileBuildSchema, configFile, configPath);
|
|
511
|
+
return validateConfig(configFileBuildSchema, configParsed, configPath);
|
|
512
|
+
}
|
|
513
|
+
export {
|
|
514
|
+
parseBuildConfig,
|
|
515
|
+
parseCreateConfig,
|
|
516
|
+
readConfigFile
|
|
517
|
+
};
|