@digdir/designsystemet 1.0.6 → 1.0.8
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/configs/digdir.config.json +59 -0
- package/configs/test-tokens.config.json +45 -0
- package/dist/bin/config.d.ts +12 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +516 -0
- package/dist/bin/designsystemet.js +3389 -3337
- package/dist/config.schema.json +39 -27
- package/dist/src/config.d.ts +46 -187
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +69 -36
- package/dist/src/index.js +60 -36
- package/dist/src/migrations/beta-to-v1.js +11 -4
- package/dist/src/migrations/codemods/css/run.js +11 -4
- package/dist/src/migrations/color-rename-next49.js +11 -4
- package/dist/src/migrations/index.js +11 -4
- package/dist/src/scripts/createJsonSchema.js +40 -1295
- package/dist/src/scripts/update-design-tokens.js +4 -4
- package/dist/src/scripts/update-template.js +16 -9
- 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 +72 -53
- package/dist/src/tokens/create/generators/$designsystemet.js +18 -18
- package/dist/src/tokens/create/write.js +29 -22
- 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 +60 -36
- package/dist/src/tokens/index.js +60 -36
- package/dist/src/tokens/process/configs/color.js +12 -10
- package/dist/src/tokens/process/configs/semantic.js +11 -9
- package/dist/src/tokens/process/configs/storefront.js +11 -1
- package/dist/src/tokens/process/configs/typography.js +11 -9
- package/dist/src/tokens/process/configs.js +13 -26
- package/dist/src/tokens/process/formats/css/color.js +3 -1
- package/dist/src/tokens/process/formats/css.js +3 -1
- package/dist/src/tokens/process/formats/js-tokens.js +11 -1
- package/dist/src/tokens/process/platform.d.ts +3 -5
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/process/platform.js +41 -14
- package/dist/src/tokens/process/theme.d.ts.map +1 -1
- package/dist/src/tokens/process/theme.js +18 -21
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +5 -4
- package/dist/src/tokens/types.d.ts +2 -2
- 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 +10 -3
- package/package.json +18 -18
package/dist/config.schema.json
CHANGED
|
@@ -1,83 +1,95 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2
3
|
"type": "object",
|
|
3
4
|
"properties": {
|
|
4
5
|
"$schema": {
|
|
5
6
|
"type": "string"
|
|
6
7
|
},
|
|
7
8
|
"outDir": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
9
|
+
"description": "Path to the output directory for the created design tokens",
|
|
10
|
+
"type": "string"
|
|
10
11
|
},
|
|
11
12
|
"clean": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
13
|
+
"description": "Delete the output directory before building or creating tokens",
|
|
14
|
+
"type": "boolean"
|
|
14
15
|
},
|
|
15
16
|
"themes": {
|
|
17
|
+
"description": "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name.",
|
|
16
18
|
"type": "object",
|
|
19
|
+
"propertyNames": {
|
|
20
|
+
"type": "string"
|
|
21
|
+
},
|
|
17
22
|
"additionalProperties": {
|
|
23
|
+
"description": "An object defining a theme. The property name holding the object becomes the theme name.",
|
|
18
24
|
"type": "object",
|
|
19
25
|
"properties": {
|
|
20
26
|
"colors": {
|
|
27
|
+
"description": "Defines the colors for this theme",
|
|
21
28
|
"type": "object",
|
|
22
29
|
"properties": {
|
|
23
30
|
"main": {
|
|
31
|
+
"description": "An object with one or more color definitions. The property name is used as the color name.",
|
|
24
32
|
"type": "object",
|
|
25
|
-
"additionalProperties": {
|
|
26
|
-
"type": "string",
|
|
27
|
-
"pattern": "^#[0-9a-fA-F]{3}|#[0-9a-fA-F]{4}|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{8}$",
|
|
28
|
-
"description": "A hex color, which is used for creating a color scale. Invalid color names: neutral, success, warning, danger, info, blue, green, orange, purple, red"
|
|
29
|
-
},
|
|
30
33
|
"propertyNames": {
|
|
34
|
+
"type": "string",
|
|
31
35
|
"pattern": "^(?!(?:neutral|success|warning|danger|info|blue|green|orange|purple|red)$)"
|
|
32
36
|
},
|
|
33
|
-
"
|
|
37
|
+
"additionalProperties": {
|
|
38
|
+
"description": "A hex color, which is used for creating a color scale. Invalid color names: neutral, success, warning, danger, info, blue, green, orange, purple, red"
|
|
39
|
+
}
|
|
34
40
|
},
|
|
35
41
|
"support": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
42
|
+
"default": {},
|
|
43
|
+
"description": "An object with one or more color definitions. The property name is used as the color name.",
|
|
44
|
+
"type": "object",
|
|
45
|
+
"propertyNames": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"pattern": "^(?!(?:neutral|success|warning|danger|info|blue|green|orange|purple|red)$)"
|
|
48
|
+
},
|
|
49
|
+
"additionalProperties": {
|
|
50
|
+
"description": "A hex color, which is used for creating a color scale. Invalid color names: neutral, success, warning, danger, info, blue, green, orange, purple, red"
|
|
51
|
+
}
|
|
38
52
|
},
|
|
39
53
|
"neutral": {
|
|
40
|
-
"
|
|
54
|
+
"description": "A hex color, which is used for creating a color scale. Invalid color names: neutral, success, warning, danger, info, blue, green, orange, purple, red"
|
|
41
55
|
}
|
|
42
56
|
},
|
|
43
57
|
"required": [
|
|
44
58
|
"main",
|
|
59
|
+
"support",
|
|
45
60
|
"neutral"
|
|
46
61
|
],
|
|
47
|
-
"additionalProperties": false
|
|
48
|
-
"description": "Defines the colors for this theme"
|
|
62
|
+
"additionalProperties": false
|
|
49
63
|
},
|
|
50
64
|
"typography": {
|
|
65
|
+
"description": "Defines the typography for a given theme",
|
|
51
66
|
"type": "object",
|
|
52
67
|
"properties": {
|
|
53
68
|
"fontFamily": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
69
|
+
"description": "Sets the font-family for this theme",
|
|
70
|
+
"type": "string"
|
|
56
71
|
}
|
|
57
72
|
},
|
|
58
73
|
"required": [
|
|
59
74
|
"fontFamily"
|
|
60
75
|
],
|
|
61
|
-
"additionalProperties": false
|
|
62
|
-
"description": "Defines the typography for a given theme"
|
|
76
|
+
"additionalProperties": false
|
|
63
77
|
},
|
|
64
78
|
"borderRadius": {
|
|
65
|
-
"
|
|
66
|
-
"
|
|
79
|
+
"description": "Defines the border-radius for this theme",
|
|
80
|
+
"type": "number"
|
|
67
81
|
}
|
|
68
82
|
},
|
|
69
83
|
"required": [
|
|
70
84
|
"colors"
|
|
71
85
|
],
|
|
72
|
-
"additionalProperties": false
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
"description": "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
|
|
86
|
+
"additionalProperties": false
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
},
|
|
78
90
|
"required": [
|
|
91
|
+
"outDir",
|
|
79
92
|
"themes"
|
|
80
93
|
],
|
|
81
|
-
"additionalProperties": false
|
|
82
|
-
"$schema": "http://json-schema.org/draft-07/schema#"
|
|
94
|
+
"additionalProperties": false
|
|
83
95
|
}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,207 +1,66 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a configuration object against a provided Zod schema.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the validated configuration.
|
|
6
|
+
* @param schema - A Zod schema used to validate the configuration object.
|
|
7
|
+
* @param unvalidatedConfig - The configuration object to validate.
|
|
8
|
+
* @returns The validated configuration object, typed as T.
|
|
9
|
+
* @throws Exits the process with code 1 if validation fails, after logging a friendly error message.
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateConfig<T>(schema: z.ZodType<T>, unvalidatedConfig: Record<string, unknown>, configPath: string): T;
|
|
12
|
+
export declare function parseConfig<T>(schema: z.ZodType<T>, configFile: string, configPath: string): T;
|
|
3
13
|
export declare const colorRegex: RegExp;
|
|
4
14
|
declare const themeSchema: z.ZodObject<{
|
|
5
15
|
colors: z.ZodObject<{
|
|
6
|
-
main: z.
|
|
7
|
-
support: z.ZodDefault<z.ZodOptional<z.
|
|
8
|
-
neutral: z.
|
|
9
|
-
},
|
|
10
|
-
neutral: `#${string}`;
|
|
11
|
-
main: Record<string, `#${string}`>;
|
|
12
|
-
support: Record<string, `#${string}`>;
|
|
13
|
-
}, {
|
|
14
|
-
neutral: string;
|
|
15
|
-
main: Record<string, string>;
|
|
16
|
-
support?: Record<string, string> | undefined;
|
|
17
|
-
}>;
|
|
16
|
+
main: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>>;
|
|
17
|
+
support: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>>>>;
|
|
18
|
+
neutral: z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>;
|
|
19
|
+
}, z.core.$strip>;
|
|
18
20
|
typography: z.ZodOptional<z.ZodObject<{
|
|
19
21
|
fontFamily: z.ZodString;
|
|
20
|
-
},
|
|
21
|
-
fontFamily: string;
|
|
22
|
-
}, {
|
|
23
|
-
fontFamily: string;
|
|
24
|
-
}>>;
|
|
22
|
+
}, z.core.$strip>>;
|
|
25
23
|
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
neutral: `#${string}`;
|
|
29
|
-
main: Record<string, `#${string}`>;
|
|
30
|
-
support: Record<string, `#${string}`>;
|
|
31
|
-
};
|
|
32
|
-
typography?: {
|
|
33
|
-
fontFamily: string;
|
|
34
|
-
} | undefined;
|
|
35
|
-
borderRadius?: number | undefined;
|
|
36
|
-
}, {
|
|
37
|
-
colors: {
|
|
38
|
-
neutral: string;
|
|
39
|
-
main: Record<string, string>;
|
|
40
|
-
support?: Record<string, string> | undefined;
|
|
41
|
-
};
|
|
42
|
-
typography?: {
|
|
43
|
-
fontFamily: string;
|
|
44
|
-
} | undefined;
|
|
45
|
-
borderRadius?: number | undefined;
|
|
46
|
-
}>;
|
|
47
|
-
/**
|
|
48
|
-
* This defines the structure of the JSON config file
|
|
49
|
-
*/
|
|
50
|
-
export declare const configFileSchema: z.ZodObject<{
|
|
51
|
-
outDir: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export declare const configFileBuildSchema: z.ZodObject<{
|
|
52
26
|
clean: z.ZodOptional<z.ZodBoolean>;
|
|
53
|
-
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export declare const configFileCreateSchema: z.ZodObject<{
|
|
29
|
+
outDir: z.ZodNonOptional<z.ZodString>;
|
|
30
|
+
clean: z.ZodNonOptional<z.ZodOptional<z.ZodBoolean>>;
|
|
31
|
+
themes: z.ZodNonOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
54
32
|
colors: z.ZodObject<{
|
|
55
|
-
main: z.
|
|
56
|
-
support: z.ZodDefault<z.ZodOptional<z.
|
|
57
|
-
neutral: z.
|
|
58
|
-
},
|
|
59
|
-
neutral: `#${string}`;
|
|
60
|
-
main: Record<string, `#${string}`>;
|
|
61
|
-
support: Record<string, `#${string}`>;
|
|
62
|
-
}, {
|
|
63
|
-
neutral: string;
|
|
64
|
-
main: Record<string, string>;
|
|
65
|
-
support?: Record<string, string> | undefined;
|
|
66
|
-
}>;
|
|
33
|
+
main: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>>;
|
|
34
|
+
support: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>>>>;
|
|
35
|
+
neutral: z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>;
|
|
36
|
+
}, z.core.$strip>;
|
|
67
37
|
typography: z.ZodOptional<z.ZodObject<{
|
|
68
38
|
fontFamily: z.ZodString;
|
|
69
|
-
},
|
|
70
|
-
fontFamily: string;
|
|
71
|
-
}, {
|
|
72
|
-
fontFamily: string;
|
|
73
|
-
}>>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
74
40
|
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
neutral: `#${string}`;
|
|
78
|
-
main: Record<string, `#${string}`>;
|
|
79
|
-
support: Record<string, `#${string}`>;
|
|
80
|
-
};
|
|
81
|
-
typography?: {
|
|
82
|
-
fontFamily: string;
|
|
83
|
-
} | undefined;
|
|
84
|
-
borderRadius?: number | undefined;
|
|
85
|
-
}, {
|
|
86
|
-
colors: {
|
|
87
|
-
neutral: string;
|
|
88
|
-
main: Record<string, string>;
|
|
89
|
-
support?: Record<string, string> | undefined;
|
|
90
|
-
};
|
|
91
|
-
typography?: {
|
|
92
|
-
fontFamily: string;
|
|
93
|
-
} | undefined;
|
|
94
|
-
borderRadius?: number | undefined;
|
|
95
|
-
}>>;
|
|
96
|
-
}, "strip", z.ZodTypeAny, {
|
|
97
|
-
themes: Record<string, {
|
|
98
|
-
colors: {
|
|
99
|
-
neutral: `#${string}`;
|
|
100
|
-
main: Record<string, `#${string}`>;
|
|
101
|
-
support: Record<string, `#${string}`>;
|
|
102
|
-
};
|
|
103
|
-
typography?: {
|
|
104
|
-
fontFamily: string;
|
|
105
|
-
} | undefined;
|
|
106
|
-
borderRadius?: number | undefined;
|
|
107
|
-
}>;
|
|
108
|
-
clean?: boolean | undefined;
|
|
109
|
-
outDir?: string | undefined;
|
|
110
|
-
}, {
|
|
111
|
-
themes: Record<string, {
|
|
112
|
-
colors: {
|
|
113
|
-
neutral: string;
|
|
114
|
-
main: Record<string, string>;
|
|
115
|
-
support?: Record<string, string> | undefined;
|
|
116
|
-
};
|
|
117
|
-
typography?: {
|
|
118
|
-
fontFamily: string;
|
|
119
|
-
} | undefined;
|
|
120
|
-
borderRadius?: number | undefined;
|
|
121
|
-
}>;
|
|
122
|
-
clean?: boolean | undefined;
|
|
123
|
-
outDir?: string | undefined;
|
|
124
|
-
}>;
|
|
41
|
+
}, z.core.$strip>>>;
|
|
42
|
+
}, z.core.$strip>;
|
|
125
43
|
/**
|
|
126
|
-
* This defines the structure of the final configuration
|
|
127
|
-
* command-line options and default values.
|
|
44
|
+
* This defines the structure of the final configuration file
|
|
128
45
|
*/
|
|
129
46
|
export declare const combinedConfigSchema: z.ZodObject<{
|
|
130
|
-
outDir: z.ZodString
|
|
131
|
-
|
|
132
|
-
themes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
47
|
+
outDir: z.ZodNonOptional<z.ZodString>;
|
|
48
|
+
themes: z.ZodNonOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
133
49
|
colors: z.ZodObject<{
|
|
134
|
-
main: z.
|
|
135
|
-
support: z.ZodDefault<z.ZodOptional<z.
|
|
136
|
-
neutral: z.
|
|
137
|
-
},
|
|
138
|
-
neutral: `#${string}`;
|
|
139
|
-
main: Record<string, `#${string}`>;
|
|
140
|
-
support: Record<string, `#${string}`>;
|
|
141
|
-
}, {
|
|
142
|
-
neutral: string;
|
|
143
|
-
main: Record<string, string>;
|
|
144
|
-
support?: Record<string, string> | undefined;
|
|
145
|
-
}>;
|
|
50
|
+
main: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>>;
|
|
51
|
+
support: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>>>>;
|
|
52
|
+
neutral: z.ZodPipe<z.ZodString, z.ZodTransform<`#${string}`, string>>;
|
|
53
|
+
}, z.core.$strip>;
|
|
146
54
|
typography: z.ZodOptional<z.ZodObject<{
|
|
147
55
|
fontFamily: z.ZodString;
|
|
148
|
-
},
|
|
149
|
-
fontFamily: string;
|
|
150
|
-
}, {
|
|
151
|
-
fontFamily: string;
|
|
152
|
-
}>>;
|
|
56
|
+
}, z.core.$strip>>;
|
|
153
57
|
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
fontFamily: string;
|
|
162
|
-
} | undefined;
|
|
163
|
-
borderRadius?: number | undefined;
|
|
164
|
-
}, {
|
|
165
|
-
colors: {
|
|
166
|
-
neutral: string;
|
|
167
|
-
main: Record<string, string>;
|
|
168
|
-
support?: Record<string, string> | undefined;
|
|
169
|
-
};
|
|
170
|
-
typography?: {
|
|
171
|
-
fontFamily: string;
|
|
172
|
-
} | undefined;
|
|
173
|
-
borderRadius?: number | undefined;
|
|
174
|
-
}>>;
|
|
175
|
-
}, "strip", z.ZodTypeAny, {
|
|
176
|
-
clean: boolean;
|
|
177
|
-
themes: Record<string, {
|
|
178
|
-
colors: {
|
|
179
|
-
neutral: `#${string}`;
|
|
180
|
-
main: Record<string, `#${string}`>;
|
|
181
|
-
support: Record<string, `#${string}`>;
|
|
182
|
-
};
|
|
183
|
-
typography?: {
|
|
184
|
-
fontFamily: string;
|
|
185
|
-
} | undefined;
|
|
186
|
-
borderRadius?: number | undefined;
|
|
187
|
-
}>;
|
|
188
|
-
outDir: string;
|
|
189
|
-
}, {
|
|
190
|
-
clean: boolean;
|
|
191
|
-
themes: Record<string, {
|
|
192
|
-
colors: {
|
|
193
|
-
neutral: string;
|
|
194
|
-
main: Record<string, string>;
|
|
195
|
-
support?: Record<string, string> | undefined;
|
|
196
|
-
};
|
|
197
|
-
typography?: {
|
|
198
|
-
fontFamily: string;
|
|
199
|
-
} | undefined;
|
|
200
|
-
borderRadius?: number | undefined;
|
|
201
|
-
}>;
|
|
202
|
-
outDir: string;
|
|
203
|
-
}>;
|
|
204
|
-
export type Config = z.infer<typeof combinedConfigSchema>;
|
|
205
|
-
export type ThemeConfig = z.infer<typeof themeSchema>;
|
|
58
|
+
}, z.core.$strip>>>;
|
|
59
|
+
clean: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
export type ConfigSchema = z.infer<typeof combinedConfigSchema>;
|
|
62
|
+
export type ConfigSchemaBuild = z.infer<typeof configFileBuildSchema>;
|
|
63
|
+
export type ConfigSchemaCreate = z.infer<typeof configFileCreateSchema>;
|
|
64
|
+
export type ConfigSchemaTheme = z.infer<typeof themeSchema>;
|
|
206
65
|
export {};
|
|
207
66
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAgC3B;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EACpB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,UAAU,EAAE,MAAM,GACjB,CAAC,CASH;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC,CAc9F;AAWD,eAAO,MAAM,UAAU,QAA2C,CAAC;AAyBnE,QAAA,MAAM,WAAW;;;;;;;;;;iBAiBmG,CAAC;AAErH,eAAO,MAAM,qBAAqB;;iBAEhC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;iBAYtB,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;iBAA6D,CAAC;AAC/F,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAChE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACtE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACxE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
package/dist/src/config.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/config.ts
|
|
2
|
+
import chalk from "chalk";
|
|
2
3
|
import * as R7 from "ramda";
|
|
3
|
-
import {
|
|
4
|
+
import { fromError } from "zod-validation-error";
|
|
5
|
+
import { z } from "zod/v4";
|
|
4
6
|
|
|
5
7
|
// src/colors/utils.ts
|
|
6
8
|
import chroma from "chroma-js";
|
|
@@ -318,6 +320,42 @@ function mapPathToOptionName(path2) {
|
|
|
318
320
|
}
|
|
319
321
|
return option;
|
|
320
322
|
}
|
|
323
|
+
function makeFriendlyError(err) {
|
|
324
|
+
return fromError(err, {
|
|
325
|
+
messageBuilder: (issues) => issues.map((issue) => {
|
|
326
|
+
const issuePath = issue.path.join(".");
|
|
327
|
+
const optionName = mapPathToOptionName(issue.path);
|
|
328
|
+
const errorCode = `(error code: ${issue.code})`;
|
|
329
|
+
const optionMessage = optionName ? ` or CLI option --${optionName}` : "";
|
|
330
|
+
return ` - Error in JSON value ${chalk.red(issuePath)}${optionMessage}:
|
|
331
|
+
${issue.message} ${chalk.dim(errorCode)}`;
|
|
332
|
+
}).join("\n")
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function validateConfig(schema, unvalidatedConfig, configPath) {
|
|
336
|
+
try {
|
|
337
|
+
return schema.parse(unvalidatedConfig);
|
|
338
|
+
} catch (err) {
|
|
339
|
+
console.error(chalk.redBright(`Invalid config file at ${chalk.red(configPath)}`));
|
|
340
|
+
const validationError = makeFriendlyError(err);
|
|
341
|
+
console.error(validationError.toString());
|
|
342
|
+
process.exit(1);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function parseConfig(schema, configFile, configPath) {
|
|
346
|
+
if (!configFile) {
|
|
347
|
+
return {};
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
const parsedConfig = JSON.parse(configFile);
|
|
351
|
+
return schema.parse(parsedConfig);
|
|
352
|
+
} catch (err) {
|
|
353
|
+
console.error(chalk.redBright(`Failed parsing config file at ${chalk.red(configPath)}`));
|
|
354
|
+
const validationError = makeFriendlyError(err);
|
|
355
|
+
console.error(validationError.toString());
|
|
356
|
+
process.exit(1);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
321
359
|
var hexPatterns = [
|
|
322
360
|
// Hex colors: #000, #0000, #000000, #00000000
|
|
323
361
|
`#[0-9a-fA-F]{3}`,
|
|
@@ -327,52 +365,47 @@ var hexPatterns = [
|
|
|
327
365
|
];
|
|
328
366
|
var reservedColorsPattern = `^(?!(?:${RESERVED_COLORS.join("|")})$)`;
|
|
329
367
|
var colorRegex = new RegExp(`^${hexPatterns.join("|")}$`);
|
|
330
|
-
var colorSchema = z.string(
|
|
331
|
-
|
|
332
|
-
|
|
368
|
+
var colorSchema = z.string().regex(colorRegex).transform(convertToHex).describe(
|
|
369
|
+
`A hex color, which is used for creating a color scale. Invalid color names: ${RESERVED_COLORS.join(", ")}`
|
|
370
|
+
);
|
|
333
371
|
var colorCategorySchema = z.record(
|
|
334
372
|
z.string().regex(new RegExp(reservedColorsPattern, "i"), {
|
|
335
|
-
|
|
373
|
+
error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
|
|
336
374
|
}),
|
|
337
375
|
colorSchema,
|
|
338
376
|
{
|
|
339
|
-
|
|
340
|
-
invalid_type_error: "Color definitions must be hex color values"
|
|
377
|
+
error: "Color definitions must be hex color values"
|
|
341
378
|
}
|
|
342
379
|
).refine((colors) => !Object.keys(colors).some((key) => RESERVED_COLORS.includes(key.toLowerCase())), {
|
|
343
|
-
|
|
380
|
+
error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
|
|
381
|
+
}).describe("An object with one or more color definitions. The property name is used as the color name.");
|
|
382
|
+
var themeSchema = z.object({
|
|
383
|
+
colors: z.object({
|
|
384
|
+
main: colorCategorySchema,
|
|
385
|
+
support: colorCategorySchema.optional().default({}),
|
|
386
|
+
neutral: colorSchema
|
|
387
|
+
}).meta({ description: "Defines the colors for this theme" }),
|
|
388
|
+
typography: z.object({
|
|
389
|
+
fontFamily: z.string().meta({ description: "Sets the font-family for this theme" })
|
|
390
|
+
}).describe("Defines the typography for a given theme").optional(),
|
|
391
|
+
borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional()
|
|
392
|
+
}).meta({ description: "An object defining a theme. The property name holding the object becomes the theme name." });
|
|
393
|
+
var configFileBuildSchema = z.object({
|
|
394
|
+
clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional()
|
|
344
395
|
});
|
|
345
|
-
var
|
|
346
|
-
{
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
main: colorCategorySchema,
|
|
350
|
-
support: colorCategorySchema.optional().default({}),
|
|
351
|
-
neutral: colorSchema
|
|
352
|
-
},
|
|
353
|
-
{ description: "Defines the colors for this theme" }
|
|
354
|
-
),
|
|
355
|
-
typography: z.object(
|
|
356
|
-
{
|
|
357
|
-
fontFamily: z.string({ description: "Sets the font-family for this theme" })
|
|
358
|
-
},
|
|
359
|
-
{ description: "Defines the typography for a given theme" }
|
|
360
|
-
).optional(),
|
|
361
|
-
borderRadius: z.number({ description: "Defines the border-radius for this theme" }).optional()
|
|
362
|
-
},
|
|
363
|
-
{ description: "An object defining a theme. The property name holding the object becomes the theme name." }
|
|
364
|
-
);
|
|
365
|
-
var configFileSchema = z.object({
|
|
366
|
-
outDir: z.string({ description: "Path to the output directory for the created design tokens" }).optional(),
|
|
367
|
-
clean: z.boolean({ description: "Delete the output directory before building or creating tokens" }).optional(),
|
|
368
|
-
themes: z.record(themeSchema, {
|
|
396
|
+
var configFileCreateSchema = z.object({
|
|
397
|
+
outDir: z.string().meta({ description: "Path to the output directory for the created design tokens" }),
|
|
398
|
+
clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional(),
|
|
399
|
+
themes: z.record(z.string(), themeSchema).meta({
|
|
369
400
|
description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
|
|
370
401
|
})
|
|
371
|
-
});
|
|
372
|
-
var combinedConfigSchema =
|
|
402
|
+
}).required();
|
|
403
|
+
var combinedConfigSchema = configFileCreateSchema.extend(configFileBuildSchema.shape);
|
|
373
404
|
export {
|
|
374
405
|
colorRegex,
|
|
375
406
|
combinedConfigSchema,
|
|
376
|
-
|
|
377
|
-
|
|
407
|
+
configFileBuildSchema,
|
|
408
|
+
configFileCreateSchema,
|
|
409
|
+
parseConfig,
|
|
410
|
+
validateConfig
|
|
378
411
|
};
|