@digdir/designsystemet 1.13.2 → 1.13.3

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 (74) hide show
  1. package/dist/bin/config.js +50 -658
  2. package/dist/bin/designsystemet.js +131 -4623
  3. package/dist/bin/options.js +22 -14
  4. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +9 -0
  5. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +8 -0
  6. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +13 -0
  7. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +10 -0
  8. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +10 -0
  9. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +53 -0
  10. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +14 -0
  11. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +9 -0
  12. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +32 -0
  13. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +15 -0
  14. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/index.js +11 -0
  15. package/dist/package.js +5 -0
  16. package/dist/src/colors/colorMetadata.js +255 -261
  17. package/dist/src/colors/index.js +5 -522
  18. package/dist/src/colors/theme.js +104 -343
  19. package/dist/src/colors/types.js +22 -25
  20. package/dist/src/colors/utils.js +241 -154
  21. package/dist/src/config.js +103 -444
  22. package/dist/src/index.js +10 -3588
  23. package/dist/src/migrations/beta-to-v1.js +339 -537
  24. package/dist/src/migrations/codemods/css/plugins.js +31 -42
  25. package/dist/src/migrations/codemods/css/run.js +20 -151
  26. package/dist/src/migrations/color-rename-next49.js +44 -220
  27. package/dist/src/migrations/index.js +7 -577
  28. package/dist/src/tokens/build.js +39 -1816
  29. package/dist/src/tokens/create/files.js +43 -602
  30. package/dist/src/tokens/create/generators/$designsystemet.js +8 -97
  31. package/dist/src/tokens/create/generators/$metadata.js +17 -20
  32. package/dist/src/tokens/create/generators/$themes.js +137 -311
  33. package/dist/src/tokens/create/generators/primitives/color-scheme.js +68 -443
  34. package/dist/src/tokens/create/generators/primitives/globals.js +141 -147
  35. package/dist/src/tokens/create/generators/primitives/size.js +146 -156
  36. package/dist/src/tokens/create/generators/primitives/typography.js +213 -217
  37. package/dist/src/tokens/create/generators/semantic/color-modes.js +24 -59
  38. package/dist/src/tokens/create/generators/semantic/color.js +42 -326
  39. package/dist/src/tokens/create/generators/semantic/style.js +379 -382
  40. package/dist/src/tokens/create/generators/themes/theme.js +108 -392
  41. package/dist/src/tokens/create.js +47 -1591
  42. package/dist/src/tokens/format.js +38 -3324
  43. package/dist/src/tokens/generate-config.js +155 -298
  44. package/dist/src/tokens/index.js +3 -3344
  45. package/dist/src/tokens/process/configs/color.js +50 -1085
  46. package/dist/src/tokens/process/configs/semantic.js +45 -1083
  47. package/dist/src/tokens/process/configs/shared.js +18 -109
  48. package/dist/src/tokens/process/configs/size-mode.js +27 -1082
  49. package/dist/src/tokens/process/configs/size.js +32 -1083
  50. package/dist/src/tokens/process/configs/type-scale.js +49 -1083
  51. package/dist/src/tokens/process/configs/typography.js +63 -1084
  52. package/dist/src/tokens/process/configs.js +88 -1224
  53. package/dist/src/tokens/process/formats/css/color.js +58 -1079
  54. package/dist/src/tokens/process/formats/css/semantic.js +27 -1081
  55. package/dist/src/tokens/process/formats/css/size-mode.js +43 -1077
  56. package/dist/src/tokens/process/formats/css/size.js +86 -1079
  57. package/dist/src/tokens/process/formats/css/type-scale.js +53 -1083
  58. package/dist/src/tokens/process/formats/css/typography.js +27 -1081
  59. package/dist/src/tokens/process/formats/css.js +18 -1081
  60. package/dist/src/tokens/process/output/declarations.js +18 -1201
  61. package/dist/src/tokens/process/output/tailwind.js +26 -40
  62. package/dist/src/tokens/process/output/theme.js +73 -206
  63. package/dist/src/tokens/process/platform.js +165 -1355
  64. package/dist/src/tokens/process/transformers.js +49 -89
  65. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +100 -1183
  66. package/dist/src/tokens/process/utils/kebab-case.js +7 -5
  67. package/dist/src/tokens/types.js +6 -7
  68. package/dist/src/tokens/utils.js +102 -93
  69. package/dist/src/types.js +1 -5
  70. package/dist/src/utils/filesystem.js +112 -124
  71. package/package.json +10 -13
  72. package/configs/test-tokens.config.json +0 -82
  73. package/dist/src/scripts/createJsonSchema.js +0 -409
  74. package/dist/src/scripts/update-preview-tokens.js +0 -3353
@@ -1,7 +1,9 @@
1
- // src/tokens/process/utils/kebab-case.ts
1
+ //#region src/tokens/process/utils/kebab-case.ts
2
+ /**
3
+ * Function to convert a string to kebab-case.
4
+ */
2
5
  function kebabCase(str) {
3
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
6
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
4
7
  }
5
- export {
6
- kebabCase
7
- };
8
+ //#endregion
9
+ export { kebabCase };
@@ -1,8 +1,7 @@
1
- // src/tokens/types.ts
2
- var colorCategories = {
3
- main: "main",
4
- support: "support"
5
- };
6
- export {
7
- colorCategories
1
+ //#region src/tokens/types.ts
2
+ const colorCategories = {
3
+ main: "main",
4
+ support: "support"
8
5
  };
6
+ //#endregion
7
+ export { colorCategories };
@@ -1,112 +1,121 @@
1
- // src/tokens/utils.ts
1
+ import { colorCategories } from "./types.js";
2
2
  import * as R from "ramda";
3
-
4
- // src/tokens/types.ts
5
- var colorCategories = {
6
- main: "main",
7
- support: "support"
8
- };
9
-
10
- // src/tokens/utils.ts
11
- var mapToLowerCase = R.map(R.toLower);
12
- var hasAnyTruth = R.any(R.equals(true));
13
- var getType = (token) => (token.$type ?? token.type) || "";
14
- var getValue = (token) => token.$value ?? token.value;
15
- var typeEquals = R.curry(
16
- (types, token) => {
17
- if (R.isNil(token)) {
18
- return false;
19
- }
20
- return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
21
- }
22
- );
23
- var pathStartsWithOneOf = R.curry(
24
- (paths, token) => {
25
- if (R.isNil(token)) {
26
- return false;
27
- }
28
- const tokenPath = mapToLowerCase(token.path);
29
- const matchPathsStartingWith = R.map((pathOrString) => {
30
- const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
31
- return R.startsWith(mapToLowerCase(path), tokenPath);
32
- }, paths);
33
- return hasAnyTruth(matchPathsStartingWith);
34
- }
35
- );
3
+ //#region src/tokens/utils.ts
4
+ const mapToLowerCase = R.map(R.toLower);
5
+ const hasAnyTruth = R.any(R.equals(true));
6
+ /**
7
+ * Returns type based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
8
+ * @param token Transformed token
9
+ * @returns type
10
+ */
11
+ const getType = (token) => (token.$type ?? token.type) || "";
12
+ /**
13
+ * Returns value based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
14
+ *
15
+ * Use generic (`<T>`) to define return value type
16
+ * @param token Transformed or Design token
17
+ * @returns value
18
+ */
19
+ const getValue = (token) => token.$value ?? token.value;
20
+ /**
21
+ * Check if token type matches provided type
22
+ * This function is curried
23
+ * @param types Type or array of types to check against
24
+ * @param token Transformed token
25
+ * @returns boolean
26
+ */
27
+ const typeEquals = R.curry((types, token) => {
28
+ if (R.isNil(token)) return false;
29
+ return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
30
+ });
31
+ const pathStartsWithOneOf = R.curry((paths, token) => {
32
+ if (R.isNil(token)) return false;
33
+ const tokenPath = mapToLowerCase(token.path);
34
+ return hasAnyTruth(R.map((pathOrString) => {
35
+ const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
36
+ return R.startsWith(mapToLowerCase(path), tokenPath);
37
+ }, paths));
38
+ });
36
39
  function isSemanticToken(token) {
37
- return token.filePath.includes("semantic/");
40
+ return token.filePath.includes("semantic/");
38
41
  }
39
42
  function isSemanticColorToken(token, color) {
40
- return token.filePath.includes("semantic/") && R.startsWith(["color", color], token.path);
43
+ return token.filePath.includes("semantic/") && R.startsWith(["color", color], token.path);
41
44
  }
42
45
  function isGlobalColorToken(token) {
43
- return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
46
+ return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
44
47
  }
45
48
  function isColorCategoryToken(token, category) {
46
- if (!category) {
47
- return Object.keys(colorCategories).some(
48
- (colorCategory) => isColorCategoryToken(token, colorCategory)
49
- );
50
- }
51
- return R.startsWith(["color", category], token.path);
49
+ if (!category) return Object.keys(colorCategories).some((colorCategory) => isColorCategoryToken(token, colorCategory));
50
+ return R.startsWith(["color", category], token.path);
52
51
  }
53
- var isDigit = (s) => /^\d+$/.test(s);
52
+ const isDigit = (s) => /^\d+$/.test(s);
53
+ /** Copied from Style Dictionary and added types
54
+ @see https://github.com/amzn/style-dictionary/blob/31c29df0382a61b085f6392dc3225c5009fbffc5/lib/utils/combineJSON.js#L33 */
54
55
  function traverseObj(obj, fn) {
55
- for (const key in obj) {
56
- const prop = obj[key];
57
- if (prop != null) {
58
- fn.apply(null, [obj, key, prop]);
59
- if (typeof prop === "object") {
60
- traverseObj(prop, fn);
61
- }
62
- }
63
- }
64
- return obj;
56
+ for (const key in obj) {
57
+ const prop = obj[key];
58
+ if (prop != null) {
59
+ fn.apply(null, [
60
+ obj,
61
+ key,
62
+ prop
63
+ ]);
64
+ if (typeof prop === "object") traverseObj(prop, fn);
65
+ }
66
+ }
67
+ return obj;
65
68
  }
69
+ /**
70
+ * In the given tokens array, inline and remove tokens that match the predicate
71
+ *
72
+ * Example: In pseudo-code, given the predicate `(token) => token.path === ['size', '1']` and the following tokens
73
+ * ```js
74
+ * [
75
+ * { path: ['size', 'base'], original: { $value: '8px' } },
76
+ * { path: ['size', '1'], original: { $value: '{size.base} * 2' } },
77
+ * { path: ['size', 'sm']: original: { $value: 'min({size.1}, 12px)' } }
78
+ * ]
79
+ * ```
80
+ * would return
81
+ * ```js
82
+ * [
83
+ * { path: ['size', 'base'], original: { $value: '8px' } },
84
+ * { path: ['size', 'sm']: original: { $value: 'min({size.base} * 2, 12px)' } }
85
+ * ]
86
+ * ```
87
+ *
88
+ * @param shouldInline - predicate to determine if token should be inlined
89
+ * @param tokens - array of tokens to transform
90
+ * @returns copy of `tokens` without those that matched the predicate,
91
+ * where references to the matching tokens have been inlined
92
+ */
66
93
  function inlineTokens(shouldInline, tokens) {
67
- const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
68
- return otherTokens.map((token) => {
69
- let transformed = getValue(token.original);
70
- for (const ref of inlineableTokens) {
71
- const refName = ref.path.join(".");
72
- if (typeof transformed === "string") {
73
- transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
74
- }
75
- }
76
- const tokenWithInlinedRefs = R.set(R.lensPath(["original", "$value"]), transformed, token);
77
- return tokenWithInlinedRefs;
78
- });
94
+ const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
95
+ return otherTokens.map((token) => {
96
+ let transformed = getValue(token.original);
97
+ for (const ref of inlineableTokens) {
98
+ const refName = ref.path.join(".");
99
+ if (typeof transformed === "string") transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
100
+ }
101
+ return R.set(R.lensPath(["original", "$value"]), transformed, token);
102
+ });
79
103
  }
80
- var sizeMap = {
81
- xsmall: "xs",
82
- small: "sm",
83
- medium: "md",
84
- large: "lg",
85
- xlarge: "xl"
104
+ const sizeMap = {
105
+ xsmall: "xs",
106
+ small: "sm",
107
+ medium: "md",
108
+ large: "lg",
109
+ xlarge: "xl"
86
110
  };
87
111
  function shortSizeName(size) {
88
- return sizeMap[size] ?? size;
112
+ return sizeMap[size] ?? size;
89
113
  }
90
- var sizeComparator = (size) => {
91
- const sortIndex = Object.entries(sizeMap).findIndex(([key, val]) => key === size || val === size);
92
- return sortIndex ?? 0;
114
+ const sizeComparator = (size) => {
115
+ return Object.entries(sizeMap).findIndex(([key, val]) => key === size || val === size) ?? 0;
93
116
  };
94
117
  function orderBySize(sizes) {
95
- return R.sortBy(sizeComparator, sizes);
118
+ return R.sortBy(sizeComparator, sizes);
96
119
  }
97
- export {
98
- getType,
99
- getValue,
100
- inlineTokens,
101
- isColorCategoryToken,
102
- isDigit,
103
- isGlobalColorToken,
104
- isSemanticColorToken,
105
- isSemanticToken,
106
- orderBySize,
107
- pathStartsWithOneOf,
108
- shortSizeName,
109
- sizeComparator,
110
- traverseObj,
111
- typeEquals
112
- };
120
+ //#endregion
121
+ export { getType, getValue, inlineTokens, isColorCategoryToken, isDigit, isGlobalColorToken, isSemanticColorToken, isSemanticToken, orderBySize, pathStartsWithOneOf, shortSizeName, sizeComparator, traverseObj, typeEquals };
package/dist/src/types.js CHANGED
@@ -1,6 +1,2 @@
1
- // src/types.ts
2
1
  export * from "@digdir/designsystemet-types";
3
- /*!
4
- * This file is deprecated and will be removed in a future release.
5
- * Use @digdir/designsystemet-types instead
6
- */
2
+ export {};
@@ -1,127 +1,115 @@
1
- // src/utils/filesystem.ts
2
- import fs from "fs/promises";
3
- import path from "path";
4
1
  import pc from "picocolors";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ //#region src/utils/filesystem.ts
5
5
  var FileSystem = class {
6
- isInitialized = false;
7
- dry = false;
8
- verbose = false;
9
- /** Default working directory is where the process was started */
10
- workingDir = process.cwd();
11
- outDir = this.workingDir;
12
- /** Initialize the file system */
13
- init({ dry, outdir, verbose }) {
14
- if (this.isInitialized) {
15
- console.warn(pc.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
16
- return;
17
- }
18
- if (dry) {
19
- console.log(pc.blue("Initializing FileSystem in dry-run mode. No files will be written."));
20
- }
21
- this.dry = dry ?? false;
22
- this.verbose = verbose ?? false;
23
- this.outDir = outdir ? path.isAbsolute(outdir) ? outdir : path.join(this.workingDir, outdir) : this.workingDir;
24
- if (this.verbose) {
25
- console.log(
26
- `FileSystem initialized with workingDir: ${pc.green(this.workingDir)}, outDir: ${pc.green(this.outDir)}`
27
- );
28
- }
29
- this.isInitialized = true;
30
- }
31
- /**
32
- * Creates a directory if it does not already exist.
33
- *
34
- * @param dir - The path of the directory to create.
35
- *
36
- * @returns A promise that resolves when the operation is complete.
37
- * If the directory already exists or `dry` is `true`, the promise resolves immediately.
38
- */
39
- mkdir = async (dir) => {
40
- if (this.dry) {
41
- console.log(`${pc.blue("mkdir")} ${dir}`);
42
- return Promise.resolve();
43
- }
44
- const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
45
- if (exists) {
46
- return Promise.resolve();
47
- }
48
- return fs.mkdir(dir, { recursive: true });
49
- };
50
- writeFile = async (path2, data) => {
51
- if (this.dry) {
52
- console.log(`${pc.blue("writeFile")} ${path2}`);
53
- return Promise.resolve();
54
- }
55
- return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
56
- console.error(pc.red(`Error writing file: ${path2}`));
57
- console.error(pc.red(error));
58
- throw error;
59
- });
60
- };
61
- cp = async (src, dest, filter) => {
62
- if (this.dry) {
63
- console.log(`${pc.blue("cp")} ${src} ${dest}`);
64
- return Promise.resolve();
65
- }
66
- return fs.cp(src, dest, { recursive: true, filter });
67
- };
68
- copyFile = async (src, dest) => {
69
- if (this.dry) {
70
- console.log(`${pc.blue("copyFile")} ${src} to ${dest}`);
71
- return Promise.resolve();
72
- }
73
- return fs.copyFile(src, dest);
74
- };
75
- cleanDir = async (dir) => {
76
- if (this.dry) {
77
- console.log(`${pc.blue("cleanDir")} ${dir}`);
78
- return Promise.resolve();
79
- }
80
- console.log(`
81
- \u{1F525} Cleaning dir ${pc.red(`${dir.trim()}`)} `);
82
- return fs.rm(dir, { recursive: true, force: true });
83
- };
84
- readFile = async (path2, allowFileNotFound) => {
85
- if (this.dry) {
86
- console.log(`${pc.blue("readFile")} ${path2}`);
87
- }
88
- try {
89
- return await fs.readFile(path2, "utf-8");
90
- } catch (error) {
91
- if (allowFileNotFound && error.code === "ENOENT") {
92
- return "";
93
- }
94
- throw error;
95
- }
96
- };
97
- readdir = async (path2) => {
98
- if (this.dry) {
99
- console.log(`${pc.blue("readdir")} ${path2}`);
100
- }
101
- try {
102
- return await fs.readdir(path2);
103
- } catch (error) {
104
- if (error.code === "ENOENT") {
105
- return [];
106
- }
107
- throw error;
108
- }
109
- };
110
- writeFiles = async (files, outDir, log) => {
111
- for (const { destination: filename, output } of files) {
112
- if (filename) {
113
- const filePath = path.join(outDir, filename);
114
- const fileDir = path.dirname(filePath);
115
- if (log) {
116
- console.log(filename);
117
- }
118
- await this.mkdir(fileDir);
119
- await this.writeFile(filePath, output);
120
- }
121
- }
122
- };
123
- };
124
- var dsfs = new FileSystem();
125
- export {
126
- dsfs
6
+ isInitialized = false;
7
+ dry = false;
8
+ verbose = false;
9
+ /** Default working directory is where the process was started */
10
+ workingDir = process.cwd();
11
+ outDir = this.workingDir;
12
+ /** Initialize the file system */
13
+ init({ dry, outdir, verbose }) {
14
+ if (this.isInitialized) {
15
+ console.warn(pc.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
16
+ return;
17
+ }
18
+ if (dry) console.log(pc.blue("Initializing FileSystem in dry-run mode. No files will be written."));
19
+ this.dry = dry ?? false;
20
+ this.verbose = verbose ?? false;
21
+ this.outDir = outdir ? path.isAbsolute(outdir) ? outdir : path.join(this.workingDir, outdir) : this.workingDir;
22
+ if (this.verbose) console.log(`FileSystem initialized with workingDir: ${pc.green(this.workingDir)}, outDir: ${pc.green(this.outDir)}`);
23
+ this.isInitialized = true;
24
+ }
25
+ /**
26
+ * Creates a directory if it does not already exist.
27
+ *
28
+ * @param dir - The path of the directory to create.
29
+ *
30
+ * @returns A promise that resolves when the operation is complete.
31
+ * If the directory already exists or `dry` is `true`, the promise resolves immediately.
32
+ */
33
+ mkdir = async (dir) => {
34
+ if (this.dry) {
35
+ console.log(`${pc.blue("mkdir")} ${dir}`);
36
+ return Promise.resolve();
37
+ }
38
+ if (await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false)) return Promise.resolve();
39
+ return fs.mkdir(dir, { recursive: true });
40
+ };
41
+ writeFile = async (path, data) => {
42
+ if (this.dry) {
43
+ console.log(`${pc.blue("writeFile")} ${path}`);
44
+ return Promise.resolve();
45
+ }
46
+ return fs.writeFile(path, data, { encoding: "utf-8" }).catch((error) => {
47
+ console.error(pc.red(`Error writing file: ${path}`));
48
+ console.error(pc.red(error));
49
+ throw error;
50
+ });
51
+ };
52
+ cp = async (src, dest, filter) => {
53
+ if (this.dry) {
54
+ console.log(`${pc.blue("cp")} ${src} ${dest}`);
55
+ return Promise.resolve();
56
+ }
57
+ return fs.cp(src, dest, {
58
+ recursive: true,
59
+ filter
60
+ });
61
+ };
62
+ copyFile = async (src, dest) => {
63
+ if (this.dry) {
64
+ console.log(`${pc.blue("copyFile")} ${src} to ${dest}`);
65
+ return Promise.resolve();
66
+ }
67
+ return fs.copyFile(src, dest);
68
+ };
69
+ cleanDir = async (dir) => {
70
+ if (this.dry) {
71
+ console.log(`${pc.blue("cleanDir")} ${dir}`);
72
+ return Promise.resolve();
73
+ }
74
+ console.log(`\n🔥 Cleaning dir ${pc.red(`${dir.trim()}`)} `);
75
+ return fs.rm(dir, {
76
+ recursive: true,
77
+ force: true
78
+ });
79
+ };
80
+ readFile = async (path, allowFileNotFound) => {
81
+ if (this.dry) console.log(`${pc.blue("readFile")} ${path}`);
82
+ try {
83
+ return await fs.readFile(path, "utf-8");
84
+ } catch (error) {
85
+ if (allowFileNotFound && error.code === "ENOENT") return "";
86
+ throw error;
87
+ }
88
+ };
89
+ readdir = async (path) => {
90
+ if (this.dry) console.log(`${pc.blue("readdir")} ${path}`);
91
+ try {
92
+ return await fs.readdir(path);
93
+ } catch (error) {
94
+ if (error.code === "ENOENT") return [];
95
+ throw error;
96
+ }
97
+ };
98
+ writeFiles = async (files, outDir, log) => {
99
+ for (const { destination: filename, output } of files) if (filename) {
100
+ const filePath = path.join(outDir, filename);
101
+ const fileDir = path.dirname(filePath);
102
+ if (log) console.log(filename);
103
+ await this.mkdir(fileDir);
104
+ await this.writeFile(filePath, output);
105
+ }
106
+ };
127
107
  };
108
+ /**
109
+ * An abstraction of Node's file system API and helper functions for Designsystemet CLI interaction with the file system.
110
+ *
111
+ * Allows dry-running destructive operations, logging and store relevant file system state.
112
+ */
113
+ const dsfs = new FileSystem();
114
+ //#endregion
115
+ export { dsfs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "1.13.2",
3
+ "version": "1.13.3",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "engines": {
@@ -15,8 +15,7 @@
15
15
  "type": "module",
16
16
  "main": "./dist/src/index.js",
17
17
  "files": [
18
- "./dist/**",
19
- "./configs/**"
18
+ "./dist/**"
20
19
  ],
21
20
  "bin": "dist/bin/designsystemet.js",
22
21
  "exports": {
@@ -51,7 +50,7 @@
51
50
  "style-dictionary": "^5.4.0",
52
51
  "zod": "^4.3.6",
53
52
  "zod-validation-error": "^5.0.0",
54
- "@digdir/designsystemet-types": "1.13.2"
53
+ "@digdir/designsystemet-types": "1.13.3"
55
54
  },
56
55
  "devDependencies": {
57
56
  "@tokens-studio/types": "0.5.2",
@@ -59,25 +58,23 @@
59
58
  "@types/node": "24.12.2",
60
59
  "@types/object-hash": "3.0.6",
61
60
  "@types/ramda": "0.31.1",
62
- "tsup": "8.5.1",
61
+ "tsdown": "0.21.9",
63
62
  "tsx": "4.21.0",
64
63
  "typescript": "5.9.3"
65
64
  },
66
65
  "scripts": {
67
66
  "designsystemet": "tsx ./bin/designsystemet.ts",
68
67
  "designsystemet:inspect": "tsx --inspect-brk ./bin/designsystemet.ts",
69
- "build": "tsup && pnpm build:types && pnpm build:json-schema",
68
+ "build": "tsdown && pnpm build:types && pnpm build:json-schema",
70
69
  "build:types": "tsc --emitDeclarationOnly --declaration",
71
70
  "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
72
71
  "types": "tsc --noEmit",
73
72
  "test:tokens-create-options": "pnpm run designsystemet tokens create -m dominant:\"#007682\" -n \"#003333\" -b 99 -o ./temp/options/design-tokens --theme options --clean",
74
- "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
75
- "test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
76
- "test:tokens-build-tailwind": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean --experimental-tailwind",
77
- "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
78
- "test:tokens-build-config:inspect": "pnpm run designsystemet:inspect tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
79
- "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
80
- "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
73
+ "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./tests/test-tokens.config.json",
74
+ "test:tokens-build-options": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean --experimental-tailwind",
75
+ "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./tests/config/design-tokens -o ./tests/config/build --clean --experimental-tailwind",
76
+ "test:tokens-build-config:inspect": "pnpm run designsystemet:inspect tokens build -t ./tests/config/design-tokens -o ./tests/config/build --clean",
77
+ "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build-options",
81
78
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
82
79
  "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../design-tokens --dry",
83
80
  "test": "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
@@ -1,82 +0,0 @@
1
- {
2
- "$schema": "../dist/config.schema.json",
3
- "outDir": "./temp/config/design-tokens",
4
- "clean": true,
5
- "themes": {
6
- "some-org": {
7
- "colors": {
8
- "main": {
9
- "dominant": "#0062BA",
10
- "complimentary": "#94237C"
11
- },
12
- "support": {
13
- "first": "#F45F63",
14
- "second": "#E5AA20",
15
- "third": "#1E98F5",
16
- "fourth": "#F167EC"
17
- },
18
- "neutral": "#303030"
19
- },
20
- "typography": {
21
- "fontFamily": "Inter"
22
- },
23
- "borderRadius": 8,
24
- "overrides": {
25
- "colors": {
26
- "dominant": {
27
- "background-default": {
28
- "light": "#ff0000",
29
- "dark": "#000fff"
30
- },
31
- "background-tinted": {
32
- "light": "#f0ff00",
33
- "dark": "#ff00ff"
34
- }
35
- },
36
- "danger": {
37
- "background-default": {
38
- "light": "#0000ff",
39
- "dark": "#0000ff"
40
- }
41
- }
42
- },
43
- "severity": {
44
- "danger": "#ff00ff"
45
- },
46
- "linkVisited": {
47
- "light": "#ff1234",
48
- "dark": "#1234ff"
49
- },
50
- "focus": {
51
- "inner": {
52
- "light": "#00ff00",
53
- "dark": "#00ffff"
54
- },
55
- "outer": {
56
- "light": "#ffff00",
57
- "dark": "#ff00aa"
58
- }
59
- }
60
- }
61
- },
62
- "other-org": {
63
- "colors": {
64
- "main": {
65
- "dominant": "#ffaaaa",
66
- "complimentary": "#00ff00"
67
- },
68
- "support": {
69
- "first": "#abcdef",
70
- "second": "#123456",
71
- "third": "#994a22",
72
- "fourth": "#3d5f30"
73
- },
74
- "neutral": "#c05030"
75
- },
76
- "typography": {
77
- "fontFamily": "Roboto"
78
- },
79
- "borderRadius": 99
80
- }
81
- }
82
- }