@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.
Files changed (50) hide show
  1. package/configs/digdir.config.json +59 -0
  2. package/configs/test-tokens.config.json +45 -0
  3. package/dist/bin/config.d.ts +12 -0
  4. package/dist/bin/config.d.ts.map +1 -0
  5. package/dist/bin/config.js +516 -0
  6. package/dist/bin/designsystemet.js +3389 -3337
  7. package/dist/config.schema.json +39 -27
  8. package/dist/src/config.d.ts +46 -187
  9. package/dist/src/config.d.ts.map +1 -1
  10. package/dist/src/config.js +69 -36
  11. package/dist/src/index.js +60 -36
  12. package/dist/src/migrations/beta-to-v1.js +11 -4
  13. package/dist/src/migrations/codemods/css/run.js +11 -4
  14. package/dist/src/migrations/color-rename-next49.js +11 -4
  15. package/dist/src/migrations/index.js +11 -4
  16. package/dist/src/scripts/createJsonSchema.js +40 -1295
  17. package/dist/src/scripts/update-design-tokens.js +4 -4
  18. package/dist/src/scripts/update-template.js +16 -9
  19. package/dist/src/tokens/build.d.ts +1 -1
  20. package/dist/src/tokens/build.d.ts.map +1 -1
  21. package/dist/src/tokens/build.js +72 -53
  22. package/dist/src/tokens/create/generators/$designsystemet.js +18 -18
  23. package/dist/src/tokens/create/write.js +29 -22
  24. package/dist/src/tokens/format.d.ts +1 -1
  25. package/dist/src/tokens/format.d.ts.map +1 -1
  26. package/dist/src/tokens/format.js +60 -36
  27. package/dist/src/tokens/index.js +60 -36
  28. package/dist/src/tokens/process/configs/color.js +12 -10
  29. package/dist/src/tokens/process/configs/semantic.js +11 -9
  30. package/dist/src/tokens/process/configs/storefront.js +11 -1
  31. package/dist/src/tokens/process/configs/typography.js +11 -9
  32. package/dist/src/tokens/process/configs.js +13 -26
  33. package/dist/src/tokens/process/formats/css/color.js +3 -1
  34. package/dist/src/tokens/process/formats/css.js +3 -1
  35. package/dist/src/tokens/process/formats/js-tokens.js +11 -1
  36. package/dist/src/tokens/process/platform.d.ts +3 -5
  37. package/dist/src/tokens/process/platform.d.ts.map +1 -1
  38. package/dist/src/tokens/process/platform.js +41 -14
  39. package/dist/src/tokens/process/theme.d.ts.map +1 -1
  40. package/dist/src/tokens/process/theme.js +18 -21
  41. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +5 -4
  42. package/dist/src/tokens/types.d.ts +2 -2
  43. package/dist/src/tokens/types.d.ts.map +1 -1
  44. package/dist/src/tokens/utils.d.ts +2 -2
  45. package/dist/src/tokens/utils.d.ts.map +1 -1
  46. package/dist/src/tokens/utils.js +11 -1
  47. package/dist/src/utils.d.ts +1 -1
  48. package/dist/src/utils.d.ts.map +1 -1
  49. package/dist/src/utils.js +10 -3
  50. package/package.json +18 -18
package/dist/src/index.js CHANGED
@@ -2615,7 +2615,9 @@ function isGlobalColorToken(token) {
2615
2615
  }
2616
2616
  function isColorCategoryToken(token, category) {
2617
2617
  if (!category) {
2618
- return ["main", "support"].some((c) => isColorCategoryToken(token, c));
2618
+ return Object.keys(colorCategories).some(
2619
+ (colorCategory2) => isColorCategoryToken(token, colorCategory2)
2620
+ );
2619
2621
  }
2620
2622
  return R7.startsWith(["color", category], token.path);
2621
2623
  }
@@ -2952,7 +2954,7 @@ var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, .
2952
2954
  );
2953
2955
  }
2954
2956
  const layer = `ds.theme.color`;
2955
- const isRootColor = color === buildOptions?.rootColor;
2957
+ const isRootColor = color === buildOptions?.defaultColor;
2956
2958
  const selector = isRootColor ? `:root, [data-color-scheme], [data-color="${color}"]` : `[data-color="${color}"], [data-color-scheme][data-color="${color}"]`;
2957
2959
  const config = {
2958
2960
  preprocessors: ["tokens-studio"],
@@ -3196,8 +3198,7 @@ function processThemeObject(theme) {
3196
3198
  }
3197
3199
  function groupThemes(themes) {
3198
3200
  const groups = {};
3199
- for (const rawTheme of themes) {
3200
- const theme = processThemeObject(rawTheme);
3201
+ for (const theme of themes) {
3201
3202
  if (theme.group) {
3202
3203
  const groupKey = theme.group;
3203
3204
  groups[groupKey] = [...groups[groupKey] ?? [], theme];
@@ -3348,9 +3349,12 @@ var initResult = {
3348
3349
  };
3349
3350
  var buildOptions;
3350
3351
  var sd = new StyleDictionary2();
3351
- var getCustomColors = (processed$themes) => processed$themes.filter(
3352
- (x) => x.group && [colorCategories.main, colorCategories.support].map((c) => `${c}-color`).includes(x.group)
3353
- ).map((x) => x.name);
3352
+ var getCustomColors = (processed$themes, colorGroups) => processed$themes.filter((x) => {
3353
+ if (!x.group) {
3354
+ return false;
3355
+ }
3356
+ return colorGroups.includes(x.group);
3357
+ }).map((x) => x.name);
3354
3358
  var buildConfigs = {
3355
3359
  typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
3356
3360
  "color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
@@ -3391,17 +3395,40 @@ var buildConfigs = {
3391
3395
  // },
3392
3396
  };
3393
3397
  async function processPlatform(options) {
3394
- const { process, $themes } = options;
3398
+ const { type, $themes } = options;
3395
3399
  const platform = "css";
3396
- const tokenSets = process === "format" ? options.tokenSets : void 0;
3397
- const tokensDir = process === "build" ? options.tokensDir : void 0;
3400
+ const tokenSets = type === "format" ? options.tokenSets : void 0;
3401
+ const tokensDir = type === "build" ? options.tokensDir : void 0;
3402
+ const UNSAFE_DEFAULT_COLOR = process.env.UNSAFE_DEFAULT_COLOR ?? "";
3403
+ if (UNSAFE_DEFAULT_COLOR) {
3404
+ console.warn(
3405
+ chalk2.yellow(
3406
+ `
3407
+ \u26A0\uFE0F UNSAFE_DEFAULT_COLOR is set to ${chalk2.blue(UNSAFE_DEFAULT_COLOR)}. This will override the default color.`
3408
+ )
3409
+ );
3410
+ }
3411
+ const UNSAFE_COLOR_GROUPS = Array.from(process.env.UNSAFE_COLOR_GROUPS?.split(",") ?? []);
3412
+ if (UNSAFE_COLOR_GROUPS.length > 0) {
3413
+ console.warn(
3414
+ chalk2.yellow(
3415
+ `
3416
+ \u26A0\uFE0F UNSAFE_COLOR_GROUPS is set to ${chalk2.blue(`[${UNSAFE_COLOR_GROUPS.join(", ")}]`)}. This will override the default color groups.`
3417
+ )
3418
+ );
3419
+ }
3420
+ const colorGroups = UNSAFE_COLOR_GROUPS.length > 0 ? UNSAFE_COLOR_GROUPS : [colorCategories.main, colorCategories.support].map((c) => `${c}-color`);
3398
3421
  buildOptions = options;
3422
+ buildOptions.defaultColor = UNSAFE_DEFAULT_COLOR;
3399
3423
  const processed$themes = $themes.map(processThemeObject).filter((theme) => R18.not(theme.group === "size" && theme.name !== "medium"));
3400
- const customColors = getCustomColors(processed$themes);
3401
- if (!buildOptions.rootColor) {
3424
+ const customColors = getCustomColors(processed$themes, colorGroups);
3425
+ if (!buildOptions.defaultColor) {
3402
3426
  const firstMainColor = R18.head(customColors);
3403
- buildOptions.rootColor = firstMainColor;
3404
- console.log(`Using first main color; ${chalk2.blue(firstMainColor)}, as ${chalk2.green(`":root"`)} color`);
3427
+ buildOptions.defaultColor = firstMainColor;
3428
+ }
3429
+ if (buildOptions.defaultColor) {
3430
+ console.log(`
3431
+ \u{1F3A8} Using ${chalk2.blue(buildOptions.defaultColor)} as default color`);
3405
3432
  }
3406
3433
  const buildAndSdConfigs = R18.map((buildConfig) => {
3407
3434
  const sdConfigs = getConfigsForThemeDimensions(buildConfig.getConfig, processed$themes, buildConfig.dimensions, {
@@ -3499,11 +3526,11 @@ import chalk3 from "chalk";
3499
3526
  // package.json
3500
3527
  var package_default = {
3501
3528
  name: "@digdir/designsystemet",
3502
- version: "1.0.6",
3529
+ version: "1.0.8",
3503
3530
  description: "CLI for Designsystemet",
3504
3531
  author: "Designsystemet team",
3505
3532
  engines: {
3506
- node: ">=22.15.0"
3533
+ node: ">=22.16.0"
3507
3534
  },
3508
3535
  repository: {
3509
3536
  type: "git",
@@ -3514,7 +3541,8 @@ var package_default = {
3514
3541
  type: "module",
3515
3542
  main: "./dist/src/index.js",
3516
3543
  files: [
3517
- "./dist/**"
3544
+ "./dist/**",
3545
+ "./configs/**"
3518
3546
  ],
3519
3547
  bin: "dist/bin/designsystemet.js",
3520
3548
  exports: {
@@ -3533,23 +3561,23 @@ var package_default = {
3533
3561
  },
3534
3562
  scripts: {
3535
3563
  designsystemet: "tsx ./bin/designsystemet.ts",
3536
- "build:tokens": "pnpm run designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
3537
- "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
3564
+ "build:tokens": "pnpm run designsystemet tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
3565
+ "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
3538
3566
  build: "tsup && pnpm build:types && pnpm build:json-schema",
3539
3567
  "build:types": "tsc --emitDeclarationOnly --declaration",
3540
3568
  "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
3541
3569
  types: "tsc --noEmit",
3542
- "test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./test-tokens/options --theme options --clean',
3543
- "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./test/test-tokens.config.json",
3544
- "test:tokens-build": "pnpm run designsystemet tokens build -t ./test-tokens/options -o ./test-tokens/options-build --clean",
3545
- "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./test-tokens/config -o ./test-tokens/config-build --clean",
3570
+ "test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
3571
+ "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
3572
+ "test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
3573
+ "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
3546
3574
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
3547
3575
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
3548
3576
  test: "pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
3549
- "internal:tokens-create": "pnpm run designsystemet tokens create --config ./internal.config.json",
3577
+ "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
3550
3578
  "update:template": "tsx ./src/scripts/update-template.ts",
3551
- "update:design-tokens": "pnpm internal:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
3552
- verify: "pnpm test && pnpm update:template && pnpm update:design-tokens"
3579
+ "update:theme-digdir": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
3580
+ verify: "pnpm test && pnpm update:template && pnpm update:theme-digdir && pnpm build:tokens"
3553
3581
  },
3554
3582
  dependencies: {
3555
3583
  "@commander-js/extra-typings": "^13.1.0",
@@ -3566,8 +3594,8 @@ var package_default = {
3566
3594
  postcss: "^8.5.3",
3567
3595
  ramda: "^0.30.1",
3568
3596
  "style-dictionary": "^4.4.0",
3569
- zod: "^3.24.4",
3570
- "zod-validation-error": "^3.4.0"
3597
+ zod: "^3.25.30",
3598
+ "zod-validation-error": "^3.4.1"
3571
3599
  },
3572
3600
  devDependencies: {
3573
3601
  "@tokens-studio/types": "0.5.2",
@@ -3576,16 +3604,15 @@ var package_default = {
3576
3604
  "@types/fs-extra": "^11.0.4",
3577
3605
  "@types/glob": "^8.1.0",
3578
3606
  "@types/jscodeshift": "^0.12.0",
3579
- "@types/node": "^22.15.3",
3607
+ "@types/node": "^22.15.21",
3580
3608
  "@types/object-hash": "^3.0.6",
3581
3609
  "@types/ramda": "^0.30.2",
3582
3610
  "fs-extra": "^11.3.0",
3583
3611
  "ts-toolbelt": "^9.6.0",
3584
3612
  tslib: "^2.8.1",
3585
- tsup: "^8.4.0",
3613
+ tsup: "^8.5.0",
3586
3614
  tsx: "^4.19.4",
3587
- typescript: "^5.8.3",
3588
- "zod-to-json-schema": "^3.24.5"
3615
+ typescript: "^5.8.3"
3589
3616
  }
3590
3617
  };
3591
3618
 
@@ -3639,9 +3666,6 @@ order may change due to nondeterminism.`.trim()
3639
3666
  return sortIndex;
3640
3667
  });
3641
3668
  const header = `@charset "UTF-8";
3642
-
3643
- @layer ds.theme, ds.base, ds.utilities, ds.components;
3644
-
3645
3669
  /*
3646
3670
  ${fileHeader2}
3647
3671
  */
@@ -3666,7 +3690,7 @@ ${fileHeader2}
3666
3690
  // src/tokens/format.ts
3667
3691
  var formatTokens = async (options) => {
3668
3692
  const processedBuilds = await processPlatform({
3669
- process: "format",
3693
+ type: "format",
3670
3694
  ...options
3671
3695
  });
3672
3696
  return processedBuilds;
@@ -42,19 +42,26 @@ var cssVarRename = (dictionary) => ({
42
42
  });
43
43
 
44
44
  // src/migrations/codemods/css/run.ts
45
- import fs2 from "node:fs";
45
+ import fs2 from "fs";
46
46
  import glob from "fast-glob";
47
47
  import postcss from "postcss";
48
48
 
49
49
  // src/utils.ts
50
- import fs from "node:fs/promises";
50
+ import fs from "fs/promises";
51
51
  import chalk2 from "chalk";
52
- var readFile = async (path, dry) => {
52
+ var readFile = async (path, dry, allowFileNotFound) => {
53
53
  if (dry) {
54
54
  console.log(`${chalk2.blue("readFile")} ${path}`);
55
55
  return Promise.resolve("");
56
56
  }
57
- return fs.readFile(path, "utf-8");
57
+ try {
58
+ return await fs.readFile(path, "utf-8");
59
+ } catch (error) {
60
+ if (allowFileNotFound && error.code === "ENOENT") {
61
+ return "";
62
+ }
63
+ throw error;
64
+ }
58
65
  };
59
66
 
60
67
  // src/migrations/codemods/css/run.ts
@@ -1,17 +1,24 @@
1
1
  // src/migrations/codemods/css/run.ts
2
- import fs2 from "node:fs";
2
+ import fs2 from "fs";
3
3
  import glob from "fast-glob";
4
4
  import postcss from "postcss";
5
5
 
6
6
  // src/utils.ts
7
- import fs from "node:fs/promises";
7
+ import fs from "fs/promises";
8
8
  import chalk from "chalk";
9
- var readFile = async (path, dry) => {
9
+ var readFile = async (path, dry, allowFileNotFound) => {
10
10
  if (dry) {
11
11
  console.log(`${chalk.blue("readFile")} ${path}`);
12
12
  return Promise.resolve("");
13
13
  }
14
- return fs.readFile(path, "utf-8");
14
+ try {
15
+ return await fs.readFile(path, "utf-8");
16
+ } catch (error) {
17
+ if (allowFileNotFound && error.code === "ENOENT") {
18
+ return "";
19
+ }
20
+ throw error;
21
+ }
15
22
  };
16
23
 
17
24
  // src/migrations/codemods/css/run.ts
@@ -33,19 +33,26 @@ var cssVarRename = (dictionary) => ({
33
33
  });
34
34
 
35
35
  // src/migrations/codemods/css/run.ts
36
- import fs2 from "node:fs";
36
+ import fs2 from "fs";
37
37
  import glob from "fast-glob";
38
38
  import postcss from "postcss";
39
39
 
40
40
  // src/utils.ts
41
- import fs from "node:fs/promises";
41
+ import fs from "fs/promises";
42
42
  import chalk2 from "chalk";
43
- var readFile = async (path, dry) => {
43
+ var readFile = async (path, dry, allowFileNotFound) => {
44
44
  if (dry) {
45
45
  console.log(`${chalk2.blue("readFile")} ${path}`);
46
46
  return Promise.resolve("");
47
47
  }
48
- return fs.readFile(path, "utf-8");
48
+ try {
49
+ return await fs.readFile(path, "utf-8");
50
+ } catch (error) {
51
+ if (allowFileNotFound && error.code === "ENOENT") {
52
+ return "";
53
+ }
54
+ throw error;
55
+ }
49
56
  };
50
57
 
51
58
  // src/migrations/codemods/css/run.ts
@@ -42,19 +42,26 @@ var cssVarRename = (dictionary) => ({
42
42
  });
43
43
 
44
44
  // src/migrations/codemods/css/run.ts
45
- import fs2 from "node:fs";
45
+ import fs2 from "fs";
46
46
  import glob from "fast-glob";
47
47
  import postcss from "postcss";
48
48
 
49
49
  // src/utils.ts
50
- import fs from "node:fs/promises";
50
+ import fs from "fs/promises";
51
51
  import chalk2 from "chalk";
52
- var readFile = async (path, dry) => {
52
+ var readFile = async (path, dry, allowFileNotFound) => {
53
53
  if (dry) {
54
54
  console.log(`${chalk2.blue("readFile")} ${path}`);
55
55
  return Promise.resolve("");
56
56
  }
57
- return fs.readFile(path, "utf-8");
57
+ try {
58
+ return await fs.readFile(path, "utf-8");
59
+ } catch (error) {
60
+ if (allowFileNotFound && error.code === "ENOENT") {
61
+ return "";
62
+ }
63
+ throw error;
64
+ }
58
65
  };
59
66
 
60
67
  // src/migrations/codemods/css/run.ts