@digdir/designsystemet 1.1.0 → 1.1.2
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 +3 -3
- package/dist/bin/config.d.ts.map +1 -1
- package/dist/bin/config.js +26 -27
- package/dist/bin/designsystemet.js +393 -376
- package/dist/config.schema.json +4 -4
- package/dist/src/config.d.ts +6 -21
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +24 -22
- package/dist/src/index.js +34 -46
- package/dist/src/scripts/createJsonSchema.js +5 -6
- 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 +349 -331
- package/dist/src/tokens/create/generators/$designsystemet.js +9 -7
- package/dist/src/tokens/create/write.js +9 -7
- package/dist/src/tokens/format.d.ts.map +1 -1
- package/dist/src/tokens/format.js +34 -46
- package/dist/src/tokens/index.js +34 -46
- package/dist/src/tokens/process/output/declarations.d.ts +4 -0
- package/dist/src/tokens/process/output/declarations.d.ts.map +1 -0
- package/dist/src/tokens/process/output/declarations.js +860 -0
- package/dist/src/tokens/process/output/theme.js +10 -8
- package/dist/src/tokens/process/platform.d.ts +5 -3
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/process/platform.js +22 -51
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -1
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +7 -0
- package/package.json +9 -7
package/dist/bin/config.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Command, OptionValues } from '@commander-js/extra-typings';
|
|
2
|
-
import { type
|
|
2
|
+
import { type BuildConfigSchema, type CreateConfigSchema } from '../src/config.js';
|
|
3
3
|
export declare function readConfigFile(configPath: string, allowFileNotFound?: boolean): Promise<string>;
|
|
4
4
|
export declare function parseCreateConfig(configFile: string, options: {
|
|
5
5
|
theme: string;
|
|
6
6
|
cmd: Command<unknown[], OptionValues>;
|
|
7
7
|
configPath: string;
|
|
8
|
-
}): Promise<
|
|
8
|
+
}): Promise<CreateConfigSchema>;
|
|
9
9
|
export declare function parseBuildConfig(configFile: string, { configPath }: {
|
|
10
10
|
configPath: string;
|
|
11
|
-
}): Promise<
|
|
11
|
+
}): Promise<BuildConfigSchema>;
|
|
12
12
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/bin/config.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,CAiE7B;AAED,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GACrC,OAAO,CAAC,iBAAiB,CAAC,CAI5B"}
|
package/dist/bin/config.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as R8 from "ramda";
|
|
|
7
7
|
import chalk from "chalk";
|
|
8
8
|
import * as R7 from "ramda";
|
|
9
9
|
import { z } from "zod/v4";
|
|
10
|
-
import { fromError } from "zod-validation-error";
|
|
10
|
+
import { fromError } from "zod-validation-error/v4";
|
|
11
11
|
|
|
12
12
|
// src/colors/colorMetadata.ts
|
|
13
13
|
import * as R from "ramda";
|
|
@@ -327,16 +327,21 @@ function mapPathToOptionName(path3) {
|
|
|
327
327
|
return option;
|
|
328
328
|
}
|
|
329
329
|
function makeFriendlyError(err) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
330
|
+
try {
|
|
331
|
+
return fromError(err, {
|
|
332
|
+
messageBuilder: (issues) => issues.map((issue) => {
|
|
333
|
+
const issuePath = issue.path.join(".");
|
|
334
|
+
const optionName = mapPathToOptionName(issue.path);
|
|
335
|
+
const errorCode = `(error code: ${issue.code})`;
|
|
336
|
+
const optionMessage = optionName ? ` or CLI option --${optionName}` : "";
|
|
337
|
+
return ` - Error in JSON value ${chalk.red(issuePath)}${optionMessage}:
|
|
338
|
+
${issue.message} ${chalk.dim(errorCode)}`;
|
|
339
|
+
}).join("\n")
|
|
340
|
+
});
|
|
341
|
+
} catch (_err2) {
|
|
342
|
+
console.error(chalk.red(err instanceof Error ? err.message : "Unknown error occurred while parsing config file"));
|
|
343
|
+
console.error(err instanceof Error ? err.stack : "No stack trace available");
|
|
344
|
+
}
|
|
340
345
|
}
|
|
341
346
|
function validateConfig(schema, unvalidatedConfig, configPath) {
|
|
342
347
|
try {
|
|
@@ -344,21 +349,20 @@ function validateConfig(schema, unvalidatedConfig, configPath) {
|
|
|
344
349
|
} catch (err) {
|
|
345
350
|
console.error(chalk.redBright(`Invalid config file at ${chalk.red(configPath)}`));
|
|
346
351
|
const validationError = makeFriendlyError(err);
|
|
347
|
-
console.error(validationError
|
|
352
|
+
console.error(validationError?.toString());
|
|
348
353
|
process.exit(1);
|
|
349
354
|
}
|
|
350
355
|
}
|
|
351
|
-
function parseConfig(
|
|
356
|
+
function parseConfig(configFile, configPath) {
|
|
352
357
|
if (!configFile) {
|
|
353
358
|
return {};
|
|
354
359
|
}
|
|
355
360
|
try {
|
|
356
|
-
|
|
357
|
-
return schema.parse(parsedConfig);
|
|
361
|
+
return JSON.parse(configFile);
|
|
358
362
|
} catch (err) {
|
|
359
363
|
console.error(chalk.redBright(`Failed parsing config file at ${chalk.red(configPath)}`));
|
|
360
364
|
const validationError = makeFriendlyError(err);
|
|
361
|
-
console.error(validationError
|
|
365
|
+
console.error(validationError?.toString());
|
|
362
366
|
process.exit(1);
|
|
363
367
|
}
|
|
364
368
|
}
|
|
@@ -396,17 +400,16 @@ var themeSchema = z.object({
|
|
|
396
400
|
}).describe("Defines the typography for a given theme").optional(),
|
|
397
401
|
borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional()
|
|
398
402
|
}).meta({ description: "An object defining a theme. The property name holding the object becomes the theme name." });
|
|
399
|
-
var
|
|
403
|
+
var commonConfig = z.object({
|
|
400
404
|
clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional()
|
|
401
405
|
});
|
|
402
|
-
var
|
|
406
|
+
var _configFileCreateSchema = z.object({
|
|
403
407
|
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
408
|
themes: z.record(z.string(), themeSchema).meta({
|
|
406
409
|
description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
|
|
407
410
|
})
|
|
408
411
|
}).required();
|
|
409
|
-
var
|
|
412
|
+
var configFileCreateSchema = _configFileCreateSchema.extend(commonConfig.shape);
|
|
410
413
|
|
|
411
414
|
// src/utils.ts
|
|
412
415
|
import fs from "fs/promises";
|
|
@@ -457,11 +460,7 @@ async function readConfigFile(configPath, allowFileNotFound = true) {
|
|
|
457
460
|
}
|
|
458
461
|
async function parseCreateConfig(configFile, options) {
|
|
459
462
|
const { cmd, theme = "theme", configPath } = options;
|
|
460
|
-
const configParsed = parseConfig(
|
|
461
|
-
configFileCreateSchema,
|
|
462
|
-
configFile,
|
|
463
|
-
configPath
|
|
464
|
-
);
|
|
463
|
+
const configParsed = parseConfig(configFile, configPath);
|
|
465
464
|
const themeColors = Object.values(configParsed?.themes ?? {}).map(
|
|
466
465
|
(x) => /* @__PURE__ */ new Set([...R8.keys(x.colors.main), ...R8.keys(x.colors.support)])
|
|
467
466
|
);
|
|
@@ -507,8 +506,8 @@ async function parseCreateConfig(configFile, options) {
|
|
|
507
506
|
return validateConfig(configFileCreateSchema, unvalidatedConfig, configPath);
|
|
508
507
|
}
|
|
509
508
|
async function parseBuildConfig(configFile, { configPath }) {
|
|
510
|
-
const configParsed = parseConfig(
|
|
511
|
-
return validateConfig(
|
|
509
|
+
const configParsed = parseConfig(configFile, configPath);
|
|
510
|
+
return validateConfig(commonConfig, configParsed, configPath);
|
|
512
511
|
}
|
|
513
512
|
export {
|
|
514
513
|
parseBuildConfig,
|