@digdir/designsystemet 1.13.0 → 1.13.1

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.
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // bin/designsystemet.ts
4
- import path5 from "path";
4
+ import path4 from "path";
5
5
  import { Argument, createCommand, program } from "@commander-js/extra-typings";
6
- import pc12 from "picocolors";
7
- import * as R29 from "ramda";
6
+ import pc11 from "picocolors";
7
+ import * as R28 from "ramda";
8
8
 
9
9
  // src/colors/colorMetadata.ts
10
10
  import * as R from "ramda";
@@ -393,7 +393,7 @@ var cssClassRename = (dictionary) => ({
393
393
  var cssVarRename = (dictionary) => ({
394
394
  postcssPlugin: `Replaces CSS variables ${hash(dictionary)}`,
395
395
  Declaration(decl) {
396
- const { value, prop: prop4 } = decl;
396
+ const { value, prop: prop3 } = decl;
397
397
  const deleted = /* @__PURE__ */ new Set();
398
398
  for (const [from, to] of Object.entries(dictionary)) {
399
399
  if (R4.isNotEmpty(to)) {
@@ -404,8 +404,8 @@ var cssVarRename = (dictionary) => ({
404
404
  decl.value = value.replace(from, to);
405
405
  continue;
406
406
  }
407
- if (R4.includes(from, prop4) && decl.variable) {
408
- decl.prop = prop4.replace(from, to);
407
+ if (R4.includes(from, prop3) && decl.variable) {
408
+ decl.prop = prop3.replace(from, to);
409
409
  }
410
410
  }
411
411
  }
@@ -468,23 +468,23 @@ var FileSystem = class {
468
468
  }
469
469
  return fs.mkdir(dir, { recursive: true });
470
470
  };
471
- writeFile = async (path6, data) => {
471
+ writeFile = async (path5, data) => {
472
472
  if (this.dry) {
473
- console.log(`${pc2.blue("writeFile")} ${path6}`);
473
+ console.log(`${pc2.blue("writeFile")} ${path5}`);
474
474
  return Promise.resolve();
475
475
  }
476
- return fs.writeFile(path6, data, { encoding: "utf-8" }).catch((error) => {
477
- console.error(pc2.red(`Error writing file: ${path6}`));
476
+ return fs.writeFile(path5, data, { encoding: "utf-8" }).catch((error) => {
477
+ console.error(pc2.red(`Error writing file: ${path5}`));
478
478
  console.error(pc2.red(error));
479
479
  throw error;
480
480
  });
481
481
  };
482
- cp = async (src, dest, filter2) => {
482
+ cp = async (src, dest, filter) => {
483
483
  if (this.dry) {
484
484
  console.log(`${pc2.blue("cp")} ${src} ${dest}`);
485
485
  return Promise.resolve();
486
486
  }
487
- return fs.cp(src, dest, { recursive: true, filter: filter2 });
487
+ return fs.cp(src, dest, { recursive: true, filter });
488
488
  };
489
489
  copyFile = async (src, dest) => {
490
490
  if (this.dry) {
@@ -502,12 +502,12 @@ var FileSystem = class {
502
502
  \u{1F525} Cleaning dir ${pc2.red(`${dir.trim()}`)} `);
503
503
  return fs.rm(dir, { recursive: true, force: true });
504
504
  };
505
- readFile = async (path6, allowFileNotFound) => {
505
+ readFile = async (path5, allowFileNotFound) => {
506
506
  if (this.dry) {
507
- console.log(`${pc2.blue("readFile")} ${path6}`);
507
+ console.log(`${pc2.blue("readFile")} ${path5}`);
508
508
  }
509
509
  try {
510
- return await fs.readFile(path6, "utf-8");
510
+ return await fs.readFile(path5, "utf-8");
511
511
  } catch (error) {
512
512
  if (allowFileNotFound && error.code === "ENOENT") {
513
513
  return "";
@@ -515,12 +515,12 @@ var FileSystem = class {
515
515
  throw error;
516
516
  }
517
517
  };
518
- readdir = async (path6) => {
518
+ readdir = async (path5) => {
519
519
  if (this.dry) {
520
- console.log(`${pc2.blue("readdir")} ${path6}`);
520
+ console.log(`${pc2.blue("readdir")} ${path5}`);
521
521
  }
522
522
  try {
523
- return await fs.readdir(path6);
523
+ return await fs.readdir(path5);
524
524
  } catch (error) {
525
525
  if (error.code === "ENOENT") {
526
526
  return [];
@@ -959,7 +959,7 @@ import pc5 from "picocolors";
959
959
  // package.json
960
960
  var package_default = {
961
961
  name: "@digdir/designsystemet",
962
- version: "1.13.0",
962
+ version: "1.13.1",
963
963
  description: "CLI for Designsystemet",
964
964
  author: "Designsystemet team",
965
965
  engines: {
@@ -1082,8 +1082,8 @@ var pathStartsWithOneOf = R6.curry(
1082
1082
  }
1083
1083
  const tokenPath = mapToLowerCase(token.path);
1084
1084
  const matchPathsStartingWith = R6.map((pathOrString) => {
1085
- const path6 = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
1086
- return R6.startsWith(mapToLowerCase(path6), tokenPath);
1085
+ const path5 = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
1086
+ return R6.startsWith(mapToLowerCase(path5), tokenPath);
1087
1087
  }, paths);
1088
1088
  return hasAnyTruth(matchPathsStartingWith);
1089
1089
  }
@@ -1108,11 +1108,11 @@ function isColorCategoryToken(token, category) {
1108
1108
  var isDigit = (s) => /^\d+$/.test(s);
1109
1109
  function traverseObj(obj, fn) {
1110
1110
  for (const key in obj) {
1111
- const prop4 = obj[key];
1112
- if (prop4 != null) {
1113
- fn.apply(null, [obj, key, prop4]);
1114
- if (typeof prop4 === "object") {
1115
- traverseObj(prop4, fn);
1111
+ const prop3 = obj[key];
1112
+ if (prop3 != null) {
1113
+ fn.apply(null, [obj, key, prop3]);
1114
+ if (typeof prop3 === "object") {
1115
+ traverseObj(prop3, fn);
1116
1116
  }
1117
1117
  }
1118
1118
  }
@@ -2524,8 +2524,8 @@ ${dynamicColors}`;
2524
2524
  import pc6 from "picocolors";
2525
2525
  import * as R21 from "ramda";
2526
2526
  var defaultFileHeader2 = `build: v${package_default.version}`;
2527
- var getFileNameWithoutExtension = (path6) => {
2528
- const pathSegments = path6.split("/");
2527
+ var getFileNameWithoutExtension = (path5) => {
2528
+ const pathSegments = path5.split("/");
2529
2529
  return pathSegments[pathSegments.length - 1].split(".").slice(0, -1).join(".");
2530
2530
  };
2531
2531
  var createThemeCSSFiles = ({
@@ -2640,11 +2640,6 @@ design-tokens: v${$designsystemet.version}` : ""
2640
2640
  return files;
2641
2641
  };
2642
2642
 
2643
- // src/tokens/create/files.ts
2644
- import path2 from "path";
2645
- import pc8 from "picocolors";
2646
- import * as R23 from "ramda";
2647
-
2648
2643
  // src/tokens/create/generators/$designsystemet.ts
2649
2644
  function generate$Designsystemet() {
2650
2645
  return {
@@ -2846,33 +2841,16 @@ var createTokenFiles = async (options) => {
2846
2841
  const {
2847
2842
  outDir,
2848
2843
  tokenSets,
2849
- theme: { name: themeName, colors: colors2 }
2844
+ theme: { colors: colors2 },
2845
+ themeNames
2850
2846
  } = options;
2851
2847
  const $themesPath = "$themes.json";
2852
2848
  const $metadataPath = "$metadata.json";
2853
2849
  const $designsystemetPath = "$designsystemet.jsonc";
2854
- let themeObjects = [];
2855
2850
  const sizeModes2 = ["small", "medium", "large"];
2856
2851
  await dsfs.mkdir(outDir);
2857
- try {
2858
- const $themes2 = await dsfs.readFile(path2.join(outDir, $themesPath));
2859
- if ($themes2) {
2860
- themeObjects = JSON.parse($themes2);
2861
- }
2862
- } catch (_error) {
2863
- }
2864
- const concatThemeNames = R23.pipe(
2865
- R23.filter((obj) => R23.toLower(obj.group || "") === "theme"),
2866
- R23.map(R23.prop("name")),
2867
- // New theme is added to the end of the list so we keep the same order from config and Token Studio
2868
- R23.append(themeName),
2869
- R23.uniq
2870
- );
2871
- const themes = concatThemeNames(themeObjects);
2872
- console.log(`
2873
- Themes: ${pc8.blue(themes.join(", "))}`);
2874
- const $themes = await generate$Themes(["dark", "light"], themes, colors2, sizeModes2);
2875
- const $metadata = generate$Metadata(["dark", "light"], themes, colors2, sizeModes2);
2852
+ const $themes = await generate$Themes(["dark", "light"], themeNames, colors2, sizeModes2);
2853
+ const $metadata = generate$Metadata(["dark", "light"], themeNames, colors2, sizeModes2);
2876
2854
  const $designsystemet = generate$Designsystemet();
2877
2855
  const files = [];
2878
2856
  files.push({ destination: $themesPath, output: stringify($themes) });
@@ -2886,7 +2864,7 @@ Themes: ${pc8.blue(themes.join(", "))}`);
2886
2864
  };
2887
2865
 
2888
2866
  // src/tokens/create/generators/primitives/color-scheme.ts
2889
- import * as R24 from "ramda";
2867
+ import * as R23 from "ramda";
2890
2868
  var generateColor = (colorArray, overrides) => {
2891
2869
  const obj = {};
2892
2870
  const $type = "color";
@@ -2923,11 +2901,11 @@ var generateColorScheme = (themeName, colorScheme2, colors2, overrides) => {
2923
2901
  });
2924
2902
  return Object.keys(positionOverrides).length > 0 ? positionOverrides : void 0;
2925
2903
  };
2926
- const main = R24.mapObjIndexed(
2904
+ const main = R23.mapObjIndexed(
2927
2905
  (color, colorName) => generateColor(generateColorScale(color, colorScheme2), createColorOverrides(colorName)),
2928
2906
  colors2.main
2929
2907
  );
2930
- const support = R24.mapObjIndexed(
2908
+ const support = R23.mapObjIndexed(
2931
2909
  (color, colorName) => generateColor(generateColorScale(color, colorScheme2), createColorOverrides(colorName)),
2932
2910
  colors2.support
2933
2911
  );
@@ -2937,7 +2915,7 @@ var generateColorScheme = (themeName, colorScheme2, colors2, overrides) => {
2937
2915
  ...baseColors,
2938
2916
  ...overrides?.severity
2939
2917
  };
2940
- const globalColors = R24.mapObjIndexed(
2918
+ const globalColors = R23.mapObjIndexed(
2941
2919
  (color, colorName) => generateColor(generateColorScale(color, colorScheme2), createColorOverrides(colorName)),
2942
2920
  baseColorsWithOverrides
2943
2921
  );
@@ -3489,7 +3467,7 @@ var fontSizes = {
3489
3467
  };
3490
3468
 
3491
3469
  // src/tokens/create/generators/semantic/color.ts
3492
- import * as R25 from "ramda";
3470
+ import * as R24 from "ramda";
3493
3471
  var generateSemanticColors = (colors2, _themeName) => {
3494
3472
  const mainColorNames = Object.keys(colors2.main);
3495
3473
  const supportColorNames = Object.keys(colors2.support);
@@ -3528,7 +3506,7 @@ var baseColorTemplate = {
3528
3506
  };
3529
3507
  var generateColorScaleTokens = (colorName) => {
3530
3508
  const colorScale = {};
3531
- for (const [colorSemantic, colorNumber] of R25.toPairs(semanticColorMap)) {
3509
+ for (const [colorSemantic, colorNumber] of R24.toPairs(semanticColorMap)) {
3532
3510
  colorScale[colorSemantic] = {
3533
3511
  $type: "color",
3534
3512
  $value: `{color.${colorName}.${colorNumber}}`
@@ -3956,7 +3934,7 @@ function generateSemanticStyle() {
3956
3934
  }
3957
3935
 
3958
3936
  // src/tokens/create/generators/themes/theme.ts
3959
- import * as R26 from "ramda";
3937
+ import * as R25 from "ramda";
3960
3938
  var generateTheme = (colors2, themeName, borderRadius) => {
3961
3939
  const mainColorNames = Object.keys(colors2.main);
3962
3940
  const supportColorNames = Object.keys(colors2.support);
@@ -3988,8 +3966,8 @@ var generateTheme = (colors2, themeName, borderRadius) => {
3988
3966
  },
3989
3967
  ...remainingThemeFile
3990
3968
  };
3991
- const baseBorderRadius = R26.lensPath(["border-radius", "base", "$value"]);
3992
- const updatedThemeFile = R26.set(baseBorderRadius, String(borderRadius), themeFile);
3969
+ const baseBorderRadius = R25.lensPath(["border-radius", "base", "$value"]);
3970
+ const updatedThemeFile = R25.set(baseBorderRadius, String(borderRadius), themeFile);
3993
3971
  const token = JSON.parse(
3994
3972
  JSON.stringify(
3995
3973
  updatedThemeFile,
@@ -4061,7 +4039,7 @@ var generateBase = (themeName) => ({
4061
4039
  });
4062
4040
  var generateColorScaleTokens3 = (colorName, themeName) => {
4063
4041
  const colorScale = {};
4064
- for (const [_, colorNumber] of R26.toPairs(semanticColorMap)) {
4042
+ for (const [_, colorNumber] of R25.toPairs(semanticColorMap)) {
4065
4043
  colorScale[colorNumber] = {
4066
4044
  $type: "color",
4067
4045
  $value: `{${themeName}.${colorName}.${colorNumber}}`
@@ -4116,8 +4094,8 @@ var createTokens = async (theme) => {
4116
4094
  };
4117
4095
 
4118
4096
  // src/tokens/generate-config.ts
4119
- import path3 from "path";
4120
- import pc9 from "picocolors";
4097
+ import path2 from "path";
4098
+ import pc8 from "picocolors";
4121
4099
  async function readJsonFile(filePath) {
4122
4100
  try {
4123
4101
  const content = await dsfs.readFile(filePath);
@@ -4136,21 +4114,21 @@ function extractBaseColor(colorScale) {
4136
4114
  return null;
4137
4115
  }
4138
4116
  async function discoverThemes(tokensDir) {
4139
- const lightModePath = path3.join(tokensDir, "themes");
4117
+ const lightModePath = path2.join(tokensDir, "themes");
4140
4118
  try {
4141
4119
  const files = await dsfs.readdir(lightModePath);
4142
4120
  const themes = files.filter((file) => file.endsWith(".json")).map((file) => file.replace(".json", ""));
4143
4121
  return themes;
4144
4122
  } catch {
4145
- throw new Error(`Could not find themes. Make sure ${pc9.blue(lightModePath)} exists and contains theme JSON files.`);
4123
+ throw new Error(`Could not find themes. Make sure ${pc8.blue(lightModePath)} exists and contains theme JSON files.`);
4146
4124
  }
4147
4125
  }
4148
4126
  async function readThemeTokens(tokensDir, themeName) {
4149
- const themePath = path3.join(tokensDir, "primitives", "modes", "color-scheme", "light", `${themeName}.json`);
4127
+ const themePath = path2.join(tokensDir, "primitives", "modes", "color-scheme", "light", `${themeName}.json`);
4150
4128
  return readJsonFile(themePath);
4151
4129
  }
4152
4130
  async function readThemeConfig(tokensDir, themeName) {
4153
- const themeConfigPath = path3.join(tokensDir, "themes", `${themeName}.json`);
4131
+ const themeConfigPath = path2.join(tokensDir, "themes", `${themeName}.json`);
4154
4132
  try {
4155
4133
  return await readJsonFile(themeConfigPath);
4156
4134
  } catch {
@@ -4184,7 +4162,7 @@ function extractFontFamily(themeConfig) {
4184
4162
  return void 0;
4185
4163
  }
4186
4164
  async function readTypographyConfig(tokensDir, themeName) {
4187
- const typographyConfigPath = path3.join(
4165
+ const typographyConfigPath = path2.join(
4188
4166
  tokensDir,
4189
4167
  "primitives",
4190
4168
  "modes",
@@ -4246,31 +4224,31 @@ function categorizeColors(themeTokens, themeName) {
4246
4224
  async function generateConfigFromTokens(options) {
4247
4225
  const { tokensDir } = options;
4248
4226
  console.log(`
4249
- Reading tokens from ${pc9.blue(tokensDir)}`);
4227
+ Reading tokens from ${pc8.blue(tokensDir)}`);
4250
4228
  const themes = await discoverThemes(tokensDir);
4251
4229
  if (themes.length === 0) {
4252
4230
  throw new Error(`
4253
- No themes found in ${pc9.blue(tokensDir)}`);
4231
+ No themes found in ${pc8.blue(tokensDir)}`);
4254
4232
  }
4255
4233
  console.log(`
4256
- Found ${pc9.green(String(themes.length))} theme(s): ${themes.map((t) => pc9.cyan(t)).join(", ")}`);
4234
+ Found ${pc8.green(String(themes.length))} theme(s): ${themes.map((t) => pc8.cyan(t)).join(", ")}`);
4257
4235
  const config = {
4258
4236
  outDir: tokensDir,
4259
4237
  themes: {}
4260
4238
  };
4261
4239
  for (const themeName of themes) {
4262
4240
  console.log(`
4263
- Processing theme ${pc9.cyan(themeName)}...`);
4241
+ Processing theme ${pc8.cyan(themeName)}...`);
4264
4242
  const themeTokens = await readThemeTokens(tokensDir, themeName);
4265
4243
  const themeConfig = await readThemeConfig(tokensDir, themeName);
4266
4244
  const typographyConfig = await readTypographyConfig(tokensDir, themeName);
4267
4245
  const { main, support, neutral } = categorizeColors(themeTokens, themeName);
4268
4246
  if (Object.keys(main).length === 0) {
4269
- console.warn(pc9.yellow(`
4247
+ console.warn(pc8.yellow(`
4270
4248
  Warning: No main colors found for theme ${themeName}`));
4271
4249
  }
4272
4250
  if (!neutral) {
4273
- console.warn(pc9.yellow(`
4251
+ console.warn(pc8.yellow(`
4274
4252
  Warning: No neutral color found for theme ${themeName}`));
4275
4253
  continue;
4276
4254
  }
@@ -4287,38 +4265,38 @@ Warning: No neutral color found for theme ${themeName}`));
4287
4265
  };
4288
4266
  console.log(
4289
4267
  `
4290
- \u2705 Main colors: ${Object.keys(main).map((c) => pc9.cyan(c)).join(", ") || pc9.dim("none")}`
4268
+ \u2705 Main colors: ${Object.keys(main).map((c) => pc8.cyan(c)).join(", ") || pc8.dim("none")}`
4291
4269
  );
4292
4270
  console.log(
4293
4271
  `
4294
- \u2705 Support colors: ${Object.keys(support).map((c) => pc9.cyan(c)).join(", ") || pc9.dim("none")}`
4272
+ \u2705 Support colors: ${Object.keys(support).map((c) => pc8.cyan(c)).join(", ") || pc8.dim("none")}`
4295
4273
  );
4296
4274
  console.log(`
4297
- \u2705 Neutral: ${pc9.cyan(neutral)}`);
4275
+ \u2705 Neutral: ${pc8.cyan(neutral)}`);
4298
4276
  if (borderRadius !== void 0) {
4299
4277
  console.log(`
4300
- \u2705 Border radius: ${pc9.cyan(String(borderRadius))}`);
4278
+ \u2705 Border radius: ${pc8.cyan(String(borderRadius))}`);
4301
4279
  }
4302
4280
  if (fontFamily) {
4303
4281
  console.log(`
4304
- \u2705 Font family: ${pc9.cyan(fontFamily)}`);
4282
+ \u2705 Font family: ${pc8.cyan(fontFamily)}`);
4305
4283
  }
4306
4284
  }
4307
4285
  return config;
4308
4286
  }
4309
4287
 
4310
4288
  // bin/config.ts
4311
- import pc11 from "picocolors";
4312
- import * as R28 from "ramda";
4313
-
4314
- // src/config.ts
4315
4289
  import pc10 from "picocolors";
4316
4290
  import * as R27 from "ramda";
4291
+
4292
+ // src/config.ts
4293
+ import pc9 from "picocolors";
4294
+ import * as R26 from "ramda";
4317
4295
  import { z } from "zod";
4318
4296
  import { fromError } from "zod-validation-error";
4319
- function mapPathToOptionName(path6) {
4320
- const normalisedPath = path6[0] === "themes" ? ["theme", ...R27.drop(2, path6)] : path6;
4321
- const option = R27.path(normalisedPath, cliOptions);
4297
+ function mapPathToOptionName(path5) {
4298
+ const normalisedPath = path5[0] === "themes" ? ["theme", ...R26.drop(2, path5)] : path5;
4299
+ const option = R26.path(normalisedPath, cliOptions);
4322
4300
  if (typeof option !== "string") {
4323
4301
  return;
4324
4302
  }
@@ -4332,12 +4310,12 @@ function makeFriendlyError(err) {
4332
4310
  const optionName = mapPathToOptionName(issue.path);
4333
4311
  const errorCode = `(error code: ${issue.code})`;
4334
4312
  const optionMessage = optionName ? ` or CLI option --${optionName}` : "";
4335
- return ` - Error in JSON value ${pc10.red(issuePath)}${optionMessage}:
4336
- ${issue.message} ${pc10.dim(errorCode)}`;
4313
+ return ` - Error in JSON value ${pc9.red(issuePath)}${optionMessage}:
4314
+ ${issue.message} ${pc9.dim(errorCode)}`;
4337
4315
  }).join("\n")
4338
4316
  });
4339
4317
  } catch (_err2) {
4340
- console.error(pc10.red(err instanceof Error ? err.message : "Unknown error occurred while parsing config file"));
4318
+ console.error(pc9.red(err instanceof Error ? err.message : "Unknown error occurred while parsing config file"));
4341
4319
  console.error(err instanceof Error ? err.stack : "No stack trace available");
4342
4320
  }
4343
4321
  }
@@ -4345,7 +4323,7 @@ function validateConfig(schema, unvalidatedConfig, configFilePath) {
4345
4323
  try {
4346
4324
  return schema.parse(unvalidatedConfig);
4347
4325
  } catch (err) {
4348
- console.error(pc10.redBright(`Invalid config file at ${pc10.red(configFilePath)}`));
4326
+ console.error(pc9.redBright(`Invalid config file at ${pc9.red(configFilePath)}`));
4349
4327
  const validationError = makeFriendlyError(err);
4350
4328
  console.error(validationError?.toString());
4351
4329
  process.exit(1);
@@ -4358,7 +4336,7 @@ function parseConfig(configFile, configFilePath) {
4358
4336
  try {
4359
4337
  return JSON.parse(configFile);
4360
4338
  } catch (err) {
4361
- console.error(pc10.redBright(`Failed parsing config file at ${pc10.red(configFilePath)}`));
4339
+ console.error(pc9.redBright(`Failed parsing config file at ${pc9.red(configFilePath)}`));
4362
4340
  const validationError = makeFriendlyError(err);
4363
4341
  console.error(validationError?.toString());
4364
4342
  process.exit(1);
@@ -4457,11 +4435,11 @@ async function readConfigFile(configFilePath, allowFileNotFound = true) {
4457
4435
  if (allowFileNotFound) {
4458
4436
  return "";
4459
4437
  }
4460
- console.error(pc11.redBright(`Could not read config file at ${pc11.blue(configFilePath)}`));
4438
+ console.error(pc10.redBright(`Could not read config file at ${pc10.blue(configFilePath)}`));
4461
4439
  throw err;
4462
4440
  }
4463
4441
  if (configFile) {
4464
- console.log(`Found config file: ${pc11.green(configFilePath)}`);
4442
+ console.log(`Found config file: ${pc10.green(configFilePath)}`);
4465
4443
  }
4466
4444
  return configFile;
4467
4445
  }
@@ -4469,11 +4447,11 @@ async function parseCreateConfig(configFile, options) {
4469
4447
  const { cmd, theme = "theme", configFilePath } = options;
4470
4448
  const configParsed = parseConfig(configFile, configFilePath);
4471
4449
  const themeColors = Object.values(configParsed?.themes ?? {}).map(
4472
- (x) => /* @__PURE__ */ new Set([...R28.keys(x.colors.main), ...R28.keys(x.colors.support)])
4450
+ (x) => /* @__PURE__ */ new Set([...R27.keys(x.colors.main), ...R27.keys(x.colors.support)])
4473
4451
  );
4474
- if (!R28.all(R28.equals(R28.__, themeColors[0]), themeColors)) {
4475
- console.error(pc11.redBright(`In config, all themes must have the same custom color names, but we found:`));
4476
- const themeNames = R28.keys(configParsed.themes ?? {});
4452
+ if (!R27.all(R27.equals(R27.__, themeColors[0]), themeColors)) {
4453
+ console.error(pc10.redBright(`In config, all themes must have the same custom color names, but we found:`));
4454
+ const themeNames = R27.keys(configParsed.themes ?? {});
4477
4455
  themeColors.forEach((colors2, index) => {
4478
4456
  const colorNames2 = Array.from(colors2);
4479
4457
  console.log(` - ${themeNames[index]}: ${colorNames2.join(", ")}`);
@@ -4481,7 +4459,7 @@ async function parseCreateConfig(configFile, options) {
4481
4459
  console.log();
4482
4460
  process.exit(1);
4483
4461
  }
4484
- const noUndefined = R28.reject(R28.isNil);
4462
+ const noUndefined = R27.reject(R27.isNil);
4485
4463
  const getThemeOptions = (optionGetter) => noUndefined({
4486
4464
  colors: noUndefined({
4487
4465
  main: optionGetter(cmd, "mainColors"),
@@ -4497,10 +4475,10 @@ async function parseCreateConfig(configFile, options) {
4497
4475
  const unvalidatedConfig = noUndefined({
4498
4476
  outDir: configParsed?.outDir ?? getCliOption(cmd, "outDir"),
4499
4477
  clean: configParsed?.clean ?? getCliOption(cmd, "clean"),
4500
- themes: configParsed?.themes ? R28.map((jsonThemeValues) => {
4478
+ themes: configParsed?.themes ? R27.map((jsonThemeValues) => {
4501
4479
  const defaultThemeValues = getThemeOptions(getDefaultCliOption);
4502
4480
  const cliThemeValues = getThemeOptions(getSuppliedCliOption);
4503
- const mergedConfigs = R28.mergeDeepRight(defaultThemeValues, R28.mergeDeepRight(jsonThemeValues, cliThemeValues));
4481
+ const mergedConfigs = R27.mergeDeepRight(defaultThemeValues, R27.mergeDeepRight(jsonThemeValues, cliThemeValues));
4504
4482
  return mergedConfigs;
4505
4483
  }, configParsed.themes) : (
4506
4484
  // If there are no themes specified in the JSON config, we use both explicit
@@ -4532,11 +4510,11 @@ var DEFAULT_THEME_NAME = "theme";
4532
4510
  var DEFAULT_CONFIG_FILEPATH = "designsystemet.config.json";
4533
4511
  function makeTokenCommands() {
4534
4512
  const tokenCmd = createCommand("tokens");
4535
- tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${pc12.blue("design-tokens")}`, DEFAULT_TOKENS_CREATE_DIR).option(
4513
+ tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${pc11.blue("design-tokens")}`, DEFAULT_TOKENS_CREATE_DIR).option(
4536
4514
  "-o, --out-dir <string>",
4537
- `Output directory for built ${pc12.blue("design-tokens")}`,
4515
+ `Output directory for built ${pc11.blue("design-tokens")}`,
4538
4516
  DEFAULT_TOKENS_BUILD_DIR
4539
- ).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before building tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for built ${pc12.blue("design-tokens")}`, parseBoolean, false).option("--verbose", "Enable verbose output", false).option("--config <string>", `Path to config file (default: "${DEFAULT_CONFIG_FILEPATH}")`).option("--experimental-tailwind", "Generate Tailwind CSS classes for tokens", false).action(async (opts) => {
4517
+ ).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before building tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for built ${pc11.blue("design-tokens")}`, parseBoolean, false).option("--verbose", "Enable verbose output", false).option("--config <string>", `Path to config file (default: "${DEFAULT_CONFIG_FILEPATH}")`).option("--experimental-tailwind", "Generate Tailwind CSS classes for tokens", false).action(async (opts) => {
4540
4518
  console.log(figletAscii);
4541
4519
  const { verbose, clean, dry, experimentalTailwind, tokens } = opts;
4542
4520
  dsfs.init({ dry, outdir: opts.outDir, verbose });
@@ -4550,17 +4528,17 @@ function makeTokenCommands() {
4550
4528
  tailwind: experimentalTailwind
4551
4529
  });
4552
4530
  console.log(`
4553
- \u{1F4BE} Writing build to ${pc12.green(outDir)}`);
4531
+ \u{1F4BE} Writing build to ${pc11.green(outDir)}`);
4554
4532
  await dsfs.writeFiles(files, outDir, true);
4555
4533
  console.log(`
4556
- \u2705 Finished building tokens in ${pc12.green(outDir)}`);
4534
+ \u2705 Finished building tokens in ${pc11.green(outDir)}`);
4557
4535
  return Promise.resolve();
4558
4536
  });
4559
4537
  tokenCmd.command("create").description("Create Designsystemet tokens").option(`-m, --${cliOptions.theme.colors.main} <name:hex...>`, `Main colors`, parseColorValues).option(`-s, --${cliOptions.theme.colors.support} <name:hex...>`, `Support colors`, parseColorValues).option(`-n, --${cliOptions.theme.colors.neutral} <hex>`, `Neutral hex color`, convertToHex).option(
4560
4538
  `-o, --${cliOptions.outDir} <string>`,
4561
- `Output directory for created ${pc12.blue("design-tokens")}`,
4539
+ `Output directory for created ${pc11.blue("design-tokens")}`,
4562
4540
  DEFAULT_TOKENS_CREATE_DIR
4563
- ).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${pc12.blue("design-tokens")}`, parseBoolean, false).option(`-f, --${cliOptions.theme.typography.fontFamily} <string>`, `Font family (experimental)`, DEFAULT_FONT).option(
4541
+ ).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${pc11.blue("design-tokens")}`, parseBoolean, false).option(`-f, --${cliOptions.theme.typography.fontFamily} <string>`, `Font family (experimental)`, DEFAULT_FONT).option(
4564
4542
  `-b, --${cliOptions.theme.borderRadius} <number>`,
4565
4543
  `Unitless base border-radius in px`,
4566
4544
  (radiusAsString) => Number(radiusAsString),
@@ -4577,6 +4555,10 @@ function makeTokenCommands() {
4577
4555
  cmd,
4578
4556
  configFilePath
4579
4557
  });
4558
+ const themeNames = Object.keys(config.themes);
4559
+ if (themeNames.length > 0) {
4560
+ console.log(`Using themes from config file: ${pc11.blue(themeNames.join(", "))}`);
4561
+ }
4580
4562
  dsfs.init({ dry: opts.dry, outdir: config.outDir });
4581
4563
  const outDir = dsfs.outDir;
4582
4564
  if (config.clean) {
@@ -4587,12 +4569,12 @@ function makeTokenCommands() {
4587
4569
  for (const [name, themeWithoutName] of Object.entries(config.themes)) {
4588
4570
  const theme = { name, ...themeWithoutName };
4589
4571
  const { tokenSets } = await createTokens(theme);
4590
- files = files.concat(await createTokenFiles({ outDir, theme, tokenSets }));
4572
+ files = files.concat(await createTokenFiles({ outDir, theme, tokenSets, themeNames }));
4591
4573
  }
4592
4574
  }
4593
4575
  await dsfs.writeFiles(files, outDir);
4594
4576
  console.log(`
4595
- \u2705 Finished creating tokens in ${pc12.green(outDir)} for theme: ${pc12.blue(themeName)}`);
4577
+ \u2705 Finished creating tokens in ${pc11.green(outDir)} for themes: ${pc11.blue(themeNames.join(", "))}`);
4596
4578
  return Promise.resolve();
4597
4579
  });
4598
4580
  return tokenCmd;
@@ -4601,9 +4583,9 @@ program.addCommand(makeTokenCommands());
4601
4583
  program.command("generate-config-from-tokens").description("Generate a config file from existing design tokens. Will not include overrides.").option("-d, --dir <string>", "Path to design tokens directory", DEFAULT_TOKENS_CREATE_DIR).option("-o, --out <string>", "Output path for config file", DEFAULT_CONFIG_FILEPATH).option("--dry [boolean]", "Dry run - show config without writing file", parseBoolean, false).action(async (opts) => {
4602
4584
  console.log(figletAscii);
4603
4585
  const { dry } = opts;
4604
- const tokensDir = path5.resolve(opts.dir);
4605
- const configFilePath = path5.resolve(opts.out);
4606
- dsfs.init({ dry, outdir: path5.dirname(configFilePath) });
4586
+ const tokensDir = path4.resolve(opts.dir);
4587
+ const configFilePath = path4.resolve(opts.out);
4588
+ dsfs.init({ dry, outdir: path4.dirname(configFilePath) });
4607
4589
  try {
4608
4590
  const config = await generateConfigFromTokens({
4609
4591
  tokensDir,
@@ -4619,10 +4601,10 @@ program.command("generate-config-from-tokens").description("Generate a config fi
4619
4601
  await dsfs.writeFile(configFilePath, configJson);
4620
4602
  console.log();
4621
4603
  console.log(`
4622
- \u2705 Config file written to ${pc12.blue(configFilePath)}`);
4604
+ \u2705 Config file written to ${pc11.blue(configFilePath)}`);
4623
4605
  }
4624
4606
  } catch (error) {
4625
- console.error(pc12.redBright("Error generating config:"));
4607
+ console.error(pc11.redBright("Error generating config:"));
4626
4608
  console.error(error instanceof Error ? error.message : String(error));
4627
4609
  process.exit(1);
4628
4610
  }
@@ -4640,8 +4622,8 @@ program.command("migrate").description("run a Designsystemet migration").addArgu
4640
4622
  console.error("Migration not found!");
4641
4623
  throw "Aborting";
4642
4624
  }
4643
- console.log(`Applying migration ${pc12.blue(migrationKey)} with glob: ${pc12.green(glob2)}`);
4644
- migration?.(glob2).then(() => console.log(`Migration ${pc12.blue(migrationKey)} finished`)).catch((error) => console.log(error));
4625
+ console.log(`Applying migration ${pc11.blue(migrationKey)} with glob: ${pc11.green(glob2)}`);
4626
+ migration?.(glob2).then(() => console.log(`Migration ${pc11.blue(migrationKey)} finished`)).catch((error) => console.log(error));
4645
4627
  } else {
4646
4628
  console.log("Migrate: please specify a migration name or --list");
4647
4629
  }
@@ -4656,7 +4638,7 @@ function parseBoolean(value) {
4656
4638
  return value === "true" || value === true;
4657
4639
  }
4658
4640
  async function getConfigFile(userConfigFilePath) {
4659
- const allowFileNotFound = R29.isNil(userConfigFilePath) || userConfigFilePath === DEFAULT_CONFIG_FILEPATH;
4641
+ const allowFileNotFound = R28.isNil(userConfigFilePath) || userConfigFilePath === DEFAULT_CONFIG_FILEPATH;
4660
4642
  const configFilePath = userConfigFilePath ?? DEFAULT_CONFIG_FILEPATH;
4661
4643
  const configFile = await readConfigFile(configFilePath, allowFileNotFound);
4662
4644
  return { configFile, configFilePath };
package/dist/src/index.js CHANGED
@@ -2138,7 +2138,7 @@ import * as R9 from "ramda";
2138
2138
  // package.json
2139
2139
  var package_default = {
2140
2140
  name: "@digdir/designsystemet",
2141
- version: "1.13.0",
2141
+ version: "1.13.1",
2142
2142
  description: "CLI for Designsystemet",
2143
2143
  author: "Designsystemet team",
2144
2144
  engines: {
@@ -133,7 +133,7 @@ import pc4 from "picocolors";
133
133
  // package.json
134
134
  var package_default = {
135
135
  name: "@digdir/designsystemet",
136
- version: "1.13.0",
136
+ version: "1.13.1",
137
137
  description: "CLI for Designsystemet",
138
138
  author: "Designsystemet team",
139
139
  engines: {
@@ -4,6 +4,7 @@ type CreateTokenFilesOptions = {
4
4
  outDir: string;
5
5
  theme: Theme;
6
6
  tokenSets: TokenSets;
7
+ themeNames: string[];
7
8
  };
8
9
  export declare const createTokenFiles: (options: CreateTokenFilesOptions) => Promise<OutputFile[]>;
9
10
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../src/tokens/create/files.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAa,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK3E,eAAO,MAAM,SAAS,GAAI,MAAM,OAAO,WAAkC,CAAC;AAE1E,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,SAAS,uBAAuB,0BAoDtE,CAAC"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../src/tokens/create/files.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAa,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK3E,eAAO,MAAM,SAAS,GAAI,MAAM,OAAO,WAAkC,CAAC;AAE1E,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,SAAS,uBAAuB,0BAiCtE,CAAC"}
@@ -1,8 +1,3 @@
1
- // src/tokens/create/files.ts
2
- import path2 from "path";
3
- import pc2 from "picocolors";
4
- import * as R from "ramda";
5
-
6
1
  // src/utils/filesystem.ts
7
2
  import fs from "fs/promises";
8
3
  import path from "path";
@@ -52,23 +47,23 @@ var FileSystem = class {
52
47
  }
53
48
  return fs.mkdir(dir, { recursive: true });
54
49
  };
55
- writeFile = async (path3, data) => {
50
+ writeFile = async (path2, data) => {
56
51
  if (this.dry) {
57
- console.log(`${pc.blue("writeFile")} ${path3}`);
52
+ console.log(`${pc.blue("writeFile")} ${path2}`);
58
53
  return Promise.resolve();
59
54
  }
60
- return fs.writeFile(path3, data, { encoding: "utf-8" }).catch((error) => {
61
- console.error(pc.red(`Error writing file: ${path3}`));
55
+ return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
56
+ console.error(pc.red(`Error writing file: ${path2}`));
62
57
  console.error(pc.red(error));
63
58
  throw error;
64
59
  });
65
60
  };
66
- cp = async (src, dest, filter2) => {
61
+ cp = async (src, dest, filter) => {
67
62
  if (this.dry) {
68
63
  console.log(`${pc.blue("cp")} ${src} ${dest}`);
69
64
  return Promise.resolve();
70
65
  }
71
- return fs.cp(src, dest, { recursive: true, filter: filter2 });
66
+ return fs.cp(src, dest, { recursive: true, filter });
72
67
  };
73
68
  copyFile = async (src, dest) => {
74
69
  if (this.dry) {
@@ -86,12 +81,12 @@ var FileSystem = class {
86
81
  \u{1F525} Cleaning dir ${pc.red(`${dir.trim()}`)} `);
87
82
  return fs.rm(dir, { recursive: true, force: true });
88
83
  };
89
- readFile = async (path3, allowFileNotFound) => {
84
+ readFile = async (path2, allowFileNotFound) => {
90
85
  if (this.dry) {
91
- console.log(`${pc.blue("readFile")} ${path3}`);
86
+ console.log(`${pc.blue("readFile")} ${path2}`);
92
87
  }
93
88
  try {
94
- return await fs.readFile(path3, "utf-8");
89
+ return await fs.readFile(path2, "utf-8");
95
90
  } catch (error) {
96
91
  if (allowFileNotFound && error.code === "ENOENT") {
97
92
  return "";
@@ -99,12 +94,12 @@ var FileSystem = class {
99
94
  throw error;
100
95
  }
101
96
  };
102
- readdir = async (path3) => {
97
+ readdir = async (path2) => {
103
98
  if (this.dry) {
104
- console.log(`${pc.blue("readdir")} ${path3}`);
99
+ console.log(`${pc.blue("readdir")} ${path2}`);
105
100
  }
106
101
  try {
107
- return await fs.readdir(path3);
102
+ return await fs.readdir(path2);
108
103
  } catch (error) {
109
104
  if (error.code === "ENOENT") {
110
105
  return [];
@@ -131,7 +126,7 @@ var dsfs = new FileSystem();
131
126
  // package.json
132
127
  var package_default = {
133
128
  name: "@digdir/designsystemet",
134
- version: "1.13.0",
129
+ version: "1.13.1",
135
130
  description: "CLI for Designsystemet",
136
131
  author: "Designsystemet team",
137
132
  engines: {
@@ -581,33 +576,16 @@ var createTokenFiles = async (options) => {
581
576
  const {
582
577
  outDir,
583
578
  tokenSets,
584
- theme: { name: themeName, colors }
579
+ theme: { colors },
580
+ themeNames
585
581
  } = options;
586
582
  const $themesPath = "$themes.json";
587
583
  const $metadataPath = "$metadata.json";
588
584
  const $designsystemetPath = "$designsystemet.jsonc";
589
- let themeObjects = [];
590
585
  const sizeModes = ["small", "medium", "large"];
591
586
  await dsfs.mkdir(outDir);
592
- try {
593
- const $themes2 = await dsfs.readFile(path2.join(outDir, $themesPath));
594
- if ($themes2) {
595
- themeObjects = JSON.parse($themes2);
596
- }
597
- } catch (_error) {
598
- }
599
- const concatThemeNames = R.pipe(
600
- R.filter((obj) => R.toLower(obj.group || "") === "theme"),
601
- R.map(R.prop("name")),
602
- // New theme is added to the end of the list so we keep the same order from config and Token Studio
603
- R.append(themeName),
604
- R.uniq
605
- );
606
- const themes = concatThemeNames(themeObjects);
607
- console.log(`
608
- Themes: ${pc2.blue(themes.join(", "))}`);
609
- const $themes = await generate$Themes(["dark", "light"], themes, colors, sizeModes);
610
- const $metadata = generate$Metadata(["dark", "light"], themes, colors, sizeModes);
587
+ const $themes = await generate$Themes(["dark", "light"], themeNames, colors, sizeModes);
588
+ const $metadata = generate$Metadata(["dark", "light"], themeNames, colors, sizeModes);
611
589
  const $designsystemet = generate$Designsystemet();
612
590
  const files = [];
613
591
  files.push({ destination: $themesPath, output: stringify($themes) });
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@digdir/designsystemet",
4
- version: "1.13.0",
4
+ version: "1.13.1",
5
5
  description: "CLI for Designsystemet",
6
6
  author: "Designsystemet team",
7
7
  engines: {
@@ -1910,7 +1910,7 @@ import * as R8 from "ramda";
1910
1910
  // package.json
1911
1911
  var package_default = {
1912
1912
  name: "@digdir/designsystemet",
1913
- version: "1.13.0",
1913
+ version: "1.13.1",
1914
1914
  description: "CLI for Designsystemet",
1915
1915
  author: "Designsystemet team",
1916
1916
  engines: {
@@ -1926,7 +1926,7 @@ import * as R8 from "ramda";
1926
1926
  // package.json
1927
1927
  var package_default = {
1928
1928
  name: "@digdir/designsystemet",
1929
- version: "1.13.0",
1929
+ version: "1.13.1",
1930
1930
  description: "CLI for Designsystemet",
1931
1931
  author: "Designsystemet team",
1932
1932
  engines: {
@@ -4,7 +4,7 @@ import pc3 from "picocolors";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@digdir/designsystemet",
7
- version: "1.13.0",
7
+ version: "1.13.1",
8
8
  description: "CLI for Designsystemet",
9
9
  author: "Designsystemet team",
10
10
  engines: {
@@ -5,7 +5,7 @@ import * as R2 from "ramda";
5
5
  // package.json
6
6
  var package_default = {
7
7
  name: "@digdir/designsystemet",
8
- version: "1.13.0",
8
+ version: "1.13.1",
9
9
  description: "CLI for Designsystemet",
10
10
  author: "Designsystemet team",
11
11
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "engines": {
@@ -51,7 +51,7 @@
51
51
  "style-dictionary": "^5.3.3",
52
52
  "zod": "^4.3.6",
53
53
  "zod-validation-error": "^5.0.0",
54
- "@digdir/designsystemet-types": "^1.13.0"
54
+ "@digdir/designsystemet-types": "^1.13.1"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@tokens-studio/types": "0.5.2",