@digdir/designsystemet 1.0.0-next.34 → 1.0.0-next.36

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 (149) hide show
  1. package/README.md +16 -0
  2. package/dist/{types/bin → bin}/designsystemet.d.ts.map +1 -1
  3. package/dist/bin/designsystemet.js +16 -16
  4. package/dist/src/colors/index.d.ts.map +1 -0
  5. package/dist/{types/src → src}/colors/theme.d.ts +8 -3
  6. package/dist/src/colors/theme.d.ts.map +1 -0
  7. package/dist/src/colors/theme.js +17 -18
  8. package/dist/{types/src → src}/colors/types.d.ts +0 -1
  9. package/dist/src/colors/types.d.ts.map +1 -0
  10. package/dist/{types/src → src}/colors/utils.d.ts +7 -1
  11. package/dist/src/colors/utils.d.ts.map +1 -0
  12. package/dist/src/colors/utils.js +13 -6
  13. package/dist/src/index.d.ts +3 -0
  14. package/dist/src/index.d.ts.map +1 -0
  15. package/dist/src/index.js +2 -0
  16. package/dist/src/init/createTokensPackage.d.ts.map +1 -0
  17. package/dist/src/init/generateMetadataJson.d.ts.map +1 -0
  18. package/dist/src/init/generateThemesJson.d.ts.map +1 -0
  19. package/dist/src/init/index.d.ts.map +1 -0
  20. package/dist/src/init/nextStepsMarkdown.d.ts.map +1 -0
  21. package/dist/src/init/utils.d.ts.map +1 -0
  22. package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
  23. package/dist/src/migrations/beta-to-v1.js +4 -4
  24. package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
  25. package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
  26. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +1 -0
  27. package/dist/src/migrations/codemods/jsx/run.d.ts.map +1 -0
  28. package/dist/src/migrations/index.d.ts.map +1 -0
  29. package/dist/src/migrations/react-beta-to-v1.d.ts.map +1 -0
  30. package/dist/src/tokens/build/actions.d.ts.map +1 -0
  31. package/dist/src/tokens/build/builtin-colors.css +87 -0
  32. package/dist/src/tokens/build/configs.d.ts +21 -0
  33. package/dist/src/tokens/build/configs.d.ts.map +1 -0
  34. package/dist/src/tokens/build/configs.js +114 -61
  35. package/dist/src/tokens/build/formats/css.d.ts +13 -0
  36. package/dist/src/tokens/build/formats/css.d.ts.map +1 -0
  37. package/dist/src/tokens/build/formats/css.js +55 -4
  38. package/dist/src/tokens/build/formats/js-tokens.d.ts.map +1 -0
  39. package/dist/src/tokens/build/formats/js-tokens.js +2 -2
  40. package/dist/{types/src → src}/tokens/build/transformers.d.ts +1 -0
  41. package/dist/src/tokens/build/transformers.d.ts.map +1 -0
  42. package/dist/src/tokens/build/transformers.js +13 -0
  43. package/dist/src/tokens/build/types.d.ts +44 -0
  44. package/dist/src/tokens/build/types.d.ts.map +1 -0
  45. package/dist/src/tokens/build/types.js +7 -0
  46. package/dist/src/tokens/build/utils/entryfile.d.ts.map +1 -0
  47. package/dist/src/tokens/build/utils/entryfile.js +39 -4
  48. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts +35 -0
  49. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +1 -0
  50. package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +112 -0
  51. package/dist/src/tokens/build/utils/noCase.d.ts.map +1 -0
  52. package/dist/{types/src → src}/tokens/build/utils/utils.d.ts +3 -0
  53. package/dist/src/tokens/build/utils/utils.d.ts.map +1 -0
  54. package/dist/src/tokens/build/utils/utils.js +15 -0
  55. package/dist/src/tokens/build.d.ts +17 -0
  56. package/dist/src/tokens/build.d.ts.map +1 -0
  57. package/dist/src/tokens/build.js +81 -68
  58. package/dist/{types/src → src}/tokens/create.d.ts +5 -0
  59. package/dist/src/tokens/create.d.ts.map +1 -0
  60. package/dist/src/tokens/create.js +13 -10
  61. package/dist/src/tokens/design-tokens/default/primitives/globals.json +2 -8
  62. package/dist/src/tokens/design-tokens/default/semantic/style.json +109 -217
  63. package/dist/src/tokens/design-tokens/template/$metadata.json +4 -0
  64. package/dist/src/tokens/design-tokens/template/$themes.json +852 -728
  65. package/dist/src/tokens/design-tokens/template/semantic/color-base-file.json +262 -0
  66. package/dist/src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json +62 -0
  67. package/dist/src/tokens/design-tokens/template/semantic/semantic-color-template.json +62 -0
  68. package/dist/src/tokens/design-tokens/template/themes/theme-base-file.json +53 -0
  69. package/dist/src/tokens/design-tokens/template/themes/theme-color-template.json +62 -0
  70. package/dist/src/tokens/index.d.ts +2 -0
  71. package/dist/src/tokens/index.d.ts.map +1 -0
  72. package/dist/src/tokens/index.js +5 -0
  73. package/dist/src/tokens/template.d.ts.map +1 -0
  74. package/dist/src/tokens/template.js +36 -4
  75. package/dist/{types/src → src}/tokens/types.d.ts +5 -2
  76. package/dist/src/tokens/types.d.ts.map +1 -0
  77. package/dist/{types/src → src}/tokens/write/generate$metadata.d.ts +2 -1
  78. package/dist/src/tokens/write/generate$metadata.d.ts.map +1 -0
  79. package/dist/src/tokens/write/generate$metadata.js +3 -1
  80. package/dist/{types/src → src}/tokens/write/generate$themes.d.ts +2 -1
  81. package/dist/src/tokens/write/generate$themes.d.ts.map +1 -0
  82. package/dist/src/tokens/write/generate$themes.js +16 -2
  83. package/dist/{types/src → src}/tokens/write.d.ts +2 -1
  84. package/dist/src/tokens/write.d.ts.map +1 -0
  85. package/dist/src/tokens/write.js +93 -5
  86. package/package.json +11 -6
  87. package/dist/src/init/template/prettier.config.js +0 -5
  88. package/dist/src/tokens/build/utils/permutateThemes.js +0 -64
  89. package/dist/src/tokens/design-tokens/default/semantic/color.json +0 -572
  90. package/dist/src/tokens/design-tokens/template/themes/theme.json +0 -334
  91. package/dist/types/src/colors/index.d.ts.map +0 -1
  92. package/dist/types/src/colors/theme.d.ts.map +0 -1
  93. package/dist/types/src/colors/types.d.ts.map +0 -1
  94. package/dist/types/src/colors/utils.d.ts.map +0 -1
  95. package/dist/types/src/init/createTokensPackage.d.ts.map +0 -1
  96. package/dist/types/src/init/generateMetadataJson.d.ts.map +0 -1
  97. package/dist/types/src/init/generateThemesJson.d.ts.map +0 -1
  98. package/dist/types/src/init/index.d.ts.map +0 -1
  99. package/dist/types/src/init/nextStepsMarkdown.d.ts.map +0 -1
  100. package/dist/types/src/init/template/prettier.config.d.mts +0 -9
  101. package/dist/types/src/init/template/prettier.config.d.mts.map +0 -1
  102. package/dist/types/src/init/utils.d.ts.map +0 -1
  103. package/dist/types/src/migrations/beta-to-v1.d.ts.map +0 -1
  104. package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +0 -1
  105. package/dist/types/src/migrations/codemods/css/run.d.ts.map +0 -1
  106. package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
  107. package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +0 -1
  108. package/dist/types/src/migrations/index.d.ts.map +0 -1
  109. package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +0 -1
  110. package/dist/types/src/tokens/build/actions.d.ts.map +0 -1
  111. package/dist/types/src/tokens/build/configs.d.ts +0 -31
  112. package/dist/types/src/tokens/build/configs.d.ts.map +0 -1
  113. package/dist/types/src/tokens/build/formats/css.d.ts +0 -5
  114. package/dist/types/src/tokens/build/formats/css.d.ts.map +0 -1
  115. package/dist/types/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
  116. package/dist/types/src/tokens/build/transformers.d.ts.map +0 -1
  117. package/dist/types/src/tokens/build/utils/entryfile.d.ts.map +0 -1
  118. package/dist/types/src/tokens/build/utils/noCase.d.ts.map +0 -1
  119. package/dist/types/src/tokens/build/utils/permutateThemes.d.ts +0 -17
  120. package/dist/types/src/tokens/build/utils/permutateThemes.d.ts.map +0 -1
  121. package/dist/types/src/tokens/build/utils/utils.d.ts.map +0 -1
  122. package/dist/types/src/tokens/build.d.ts +0 -11
  123. package/dist/types/src/tokens/build.d.ts.map +0 -1
  124. package/dist/types/src/tokens/create.d.ts.map +0 -1
  125. package/dist/types/src/tokens/template.d.ts.map +0 -1
  126. package/dist/types/src/tokens/types.d.ts.map +0 -1
  127. package/dist/types/src/tokens/write/generate$metadata.d.ts.map +0 -1
  128. package/dist/types/src/tokens/write/generate$themes.d.ts.map +0 -1
  129. package/dist/types/src/tokens/write.d.ts.map +0 -1
  130. /package/dist/{types/bin → bin}/designsystemet.d.ts +0 -0
  131. /package/dist/{types/src → src}/colors/index.d.ts +0 -0
  132. /package/dist/{types/src → src}/init/createTokensPackage.d.ts +0 -0
  133. /package/dist/{types/src → src}/init/generateMetadataJson.d.ts +0 -0
  134. /package/dist/{types/src → src}/init/generateThemesJson.d.ts +0 -0
  135. /package/dist/{types/src → src}/init/index.d.ts +0 -0
  136. /package/dist/{types/src → src}/init/nextStepsMarkdown.d.ts +0 -0
  137. /package/dist/{types/src → src}/init/utils.d.ts +0 -0
  138. /package/dist/{types/src → src}/migrations/beta-to-v1.d.ts +0 -0
  139. /package/dist/{types/src → src}/migrations/codemods/css/plugins.d.ts +0 -0
  140. /package/dist/{types/src → src}/migrations/codemods/css/run.d.ts +0 -0
  141. /package/dist/{types/src → src}/migrations/codemods/jsx/classname-prefix.d.ts +0 -0
  142. /package/dist/{types/src → src}/migrations/codemods/jsx/run.d.ts +0 -0
  143. /package/dist/{types/src → src}/migrations/index.d.ts +0 -0
  144. /package/dist/{types/src → src}/migrations/react-beta-to-v1.d.ts +0 -0
  145. /package/dist/{types/src → src}/tokens/build/actions.d.ts +0 -0
  146. /package/dist/{types/src → src}/tokens/build/formats/js-tokens.d.ts +0 -0
  147. /package/dist/{types/src → src}/tokens/build/utils/entryfile.d.ts +0 -0
  148. /package/dist/{types/src → src}/tokens/build/utils/noCase.d.ts +0 -0
  149. /package/dist/{types/src → src}/tokens/template.d.ts +0 -0
@@ -0,0 +1,112 @@
1
+ import { TokenSetStatus } from "@tokens-studio/types";
2
+ import chalk from "chalk";
3
+ import { kebabCase } from "change-case";
4
+ import * as R from "ramda";
5
+ import { buildOptions } from "../../build.js";
6
+ const getMultidimensionalThemes = (themes, dimensions) => {
7
+ const verboseLogging = buildOptions?.verbose;
8
+ const grouped$themes = groupThemes(themes);
9
+ const permutations = permutateThemes(grouped$themes);
10
+ const ALL_DEPENDENT_ON = ["theme"];
11
+ const keys = R.keys(grouped$themes);
12
+ const nonDependentKeys = keys.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
13
+ if (verboseLogging) {
14
+ console.log(chalk.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
15
+ console.log(chalk.cyan(` (ignoring permutations for ${nonDependentKeys})`));
16
+ }
17
+ return permutations.filter((val) => {
18
+ const filters = nonDependentKeys.map((x) => val.permutation[x] === grouped$themes[x][0].name);
19
+ return filters.every((x) => x);
20
+ });
21
+ };
22
+ const processed = Symbol("Type brand for ProcessedThemeObject");
23
+ function isProcessed(theme) {
24
+ return Boolean(theme[processed]);
25
+ }
26
+ function processThemeObject(theme) {
27
+ if (isProcessed(theme)) {
28
+ return theme;
29
+ }
30
+ const result = { ...theme, [processed]: true };
31
+ if (result.group) {
32
+ result.group = kebabCase(result.group);
33
+ }
34
+ result.name = kebabCase(result.name);
35
+ return result;
36
+ }
37
+ function groupThemes(themes) {
38
+ const groups = {};
39
+ for (const rawTheme of themes) {
40
+ const theme = processThemeObject(rawTheme);
41
+ if (theme.group) {
42
+ const groupKey = theme.group;
43
+ groups[groupKey] = [...groups[groupKey] ?? [], theme];
44
+ } else {
45
+ throw new Error(
46
+ `Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
47
+ );
48
+ }
49
+ }
50
+ return groups;
51
+ }
52
+ const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
53
+ function permutateThemes(groups) {
54
+ const separator = "_";
55
+ const permutations = cartesian(Object.values(groups));
56
+ const permutatedThemes = permutations.map((perm) => {
57
+ const permutatedTheme = perm.reduce(
58
+ (acc, theme) => {
59
+ const { group, name, selectedTokenSets } = theme;
60
+ let updatedPermutation = acc.permutation;
61
+ if (group) {
62
+ const groupProp = R.lensProp(group);
63
+ updatedPermutation = R.set(groupProp, name, updatedPermutation);
64
+ }
65
+ const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
66
+ const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
67
+ return {
68
+ permutation: updatedPermutation,
69
+ name: updatedName,
70
+ selectedTokenSets: sets
71
+ };
72
+ },
73
+ {
74
+ name: "",
75
+ selectedTokenSets: [],
76
+ permutation: {
77
+ mode: "unknown",
78
+ "main-color": "unknown",
79
+ "support-color": "unknown",
80
+ theme: "unknown",
81
+ semantic: "unknown",
82
+ size: "unknown",
83
+ typography: "unknown"
84
+ }
85
+ }
86
+ );
87
+ if (hasUnknownProps(permutatedTheme)) {
88
+ throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
89
+ }
90
+ const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
91
+ return { ...permutatedTheme, selectedTokenSets: Array.from(uniqueTokenSets) };
92
+ });
93
+ return permutatedThemes;
94
+ }
95
+ function filterTokenSets(tokensets) {
96
+ return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
97
+ if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
98
+ return -1;
99
+ }
100
+ if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
101
+ return 1;
102
+ }
103
+ return 0;
104
+ }).map((entry) => entry[0]);
105
+ }
106
+ function cartesian(a) {
107
+ return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e].flat())));
108
+ }
109
+ export {
110
+ getMultidimensionalThemes,
111
+ processThemeObject
112
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noCase.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/utils/noCase.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,OAAO;IACtB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CACtE;AAQD;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,OAAY,UAkB1D"}
@@ -22,4 +22,7 @@ export declare const getValue: <T>(token: TransformedToken | DesignToken) => T;
22
22
  */
23
23
  export declare const typeEquals: import("ts-toolbelt/out/Function/Curry").Curry<(types: string[] | string, token: TransformedToken) => boolean>;
24
24
  export declare const pathStartsWithOneOf: import("ts-toolbelt/out/Function/Curry").Curry<(paths: string[], token: TransformedToken) => boolean>;
25
+ export declare function isSemanticToken(token: TransformedToken): boolean;
26
+ export declare function isGlobalColorToken(token: TransformedToken): boolean;
27
+ export declare function isColorCategoryToken(token: TransformedToken, category?: 'main' | 'support'): boolean;
25
28
  //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/utils/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM5E;;;;GAIG;AACH,eAAO,MAAM,OAAO,UAAW,gBAAgB,WAAkD,CAAC;AAElG;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,gBAAgB,GAAG,WAAW,KAAG,CAAuC,CAAC;AAE5G;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,yDAAmB,MAAM,EAAE,GAAG,MAAM,SAAS,gBAAgB,aAMlF,CAAC;AAEH,eAAO,MAAM,mBAAmB,yDAAmB,MAAM,EAAE,SAAS,gBAAgB,aASlF,CAAC;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAEhE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAEnE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAKpG"}
@@ -17,9 +17,24 @@ const pathStartsWithOneOf = R.curry((paths, token) => {
17
17
  const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
18
18
  return hasAnyTruth(matchPathsStartingWith);
19
19
  });
20
+ function isSemanticToken(token) {
21
+ return token.filePath.includes("semantic/");
22
+ }
23
+ function isGlobalColorToken(token) {
24
+ return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
25
+ }
26
+ function isColorCategoryToken(token, category) {
27
+ if (!category) {
28
+ return ["main", "support"].some((c) => isColorCategoryToken(token, c));
29
+ }
30
+ return R.startsWith(["color", category], token.path);
31
+ }
20
32
  export {
21
33
  getType,
22
34
  getValue,
35
+ isColorCategoryToken,
36
+ isGlobalColorToken,
37
+ isSemanticToken,
23
38
  pathStartsWithOneOf,
24
39
  typeEquals
25
40
  };
@@ -0,0 +1,17 @@
1
+ export declare const DEFAULT_COLOR = "accent";
2
+ type Options = {
3
+ /** Design tokens path */
4
+ tokens: string;
5
+ /** Output directory for built tokens */
6
+ out: string;
7
+ /** Generate preview tokens */
8
+ preview: boolean;
9
+ /** Enable verbose output */
10
+ verbose: boolean;
11
+ /** Set the default "accent" color, if not overridden with data-color */
12
+ accentColor?: string;
13
+ };
14
+ export declare let buildOptions: Options | undefined;
15
+ export declare function buildTokens(options: Options): Promise<void>;
16
+ export {};
17
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/tokens/build.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,KAAK,OAAO,GAAG;IACb,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,IAAI,YAAY,EAAE,OAAO,GAAG,SAAS,CAAC;AAwC7C,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAuEjE"}
@@ -1,85 +1,98 @@
1
- import fs from "node:fs";
1
+ import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import chalk from "chalk";
4
4
  import * as R from "ramda";
5
5
  import StyleDictionary from "style-dictionary";
6
- import * as configs from "./build/configs.js";
6
+ import { configs, getConfigsForThemeDimensions } from "./build/configs.js";
7
7
  import { makeEntryFile } from "./build/utils/entryfile.js";
8
- const { permutateThemes, getConfigs } = configs;
8
+ import { processThemeObject } from "./build/utils/getMultidimensionalThemes.js";
9
+ const DEFAULT_COLOR = "accent";
10
+ let buildOptions;
9
11
  const sd = new StyleDictionary();
12
+ const buildConfigs = {
13
+ typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
14
+ "color-mode": { getConfig: configs.colorModeVariables, dimensions: ["mode"] },
15
+ "main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
16
+ "support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
17
+ semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] },
18
+ storefront: {
19
+ name: "Storefront preview tokens",
20
+ getConfig: configs.typescriptTokens,
21
+ dimensions: ["mode"],
22
+ options: { outPath: path.resolve("../../apps/storefront/tokens") },
23
+ enabled: () => buildOptions?.preview ?? false
24
+ },
25
+ entryFiles: {
26
+ name: "CSS entry files",
27
+ getConfig: configs.semanticVariables,
28
+ dimensions: ["semantic"],
29
+ build: async (sdConfigs, { outPath }) => {
30
+ await Promise.all(
31
+ sdConfigs.map(async ({ permutation: { theme } }) => {
32
+ console.log(`\u{1F477} ${theme}.css`);
33
+ const builtinColorsFilename = "builtin-colors.css";
34
+ const builtinColors = path.resolve(import.meta.dirname, "build", builtinColorsFilename);
35
+ await fs.copyFile(builtinColors, path.resolve(outPath, theme, builtinColorsFilename));
36
+ return makeEntryFile({ theme, outPath, buildPath: path.resolve(outPath, theme) });
37
+ })
38
+ );
39
+ }
40
+ }
41
+ };
10
42
  async function buildTokens(options) {
43
+ buildOptions = options;
11
44
  const tokensDir = options.tokens;
12
- const storefrontOutDir = path.resolve("../../apps/storefront/tokens");
13
45
  const outPath = path.resolve(options.out);
14
- const $themes = JSON.parse(fs.readFileSync(path.resolve(`${tokensDir}/$themes.json`), "utf-8"));
15
- const relevant$themes = $themes.filter((theme) => {
16
- const group = R.toLower(R.defaultTo("")(theme.group));
17
- if (group === "size" && theme.name !== "default") return false;
18
- return true;
19
- });
20
- const themes = permutateThemes(relevant$themes);
21
- const typographyThemes = R.filter((val) => val.mode === "light", themes);
22
- const colormodeThemes = R.filter((val) => val.typography === "primary", themes);
23
- const semanticThemes = R.filter((val) => val.mode === "light" && val.typography === "primary", themes);
24
- const colorModeConfigs = getConfigs(configs.colorModeVariables, outPath, tokensDir, colormodeThemes);
25
- const semanticConfigs = getConfigs(configs.semanticVariables, outPath, tokensDir, semanticThemes);
26
- const typographyConfigs = getConfigs(configs.typographyVariables, outPath, tokensDir, typographyThemes);
27
- const storefrontConfigs = getConfigs(configs.typescriptTokens, storefrontOutDir, tokensDir, colormodeThemes);
28
- if (typographyConfigs.length > 0) {
29
- console.log(`
30
- \u{1F371} Building ${chalk.green("typography")}`);
31
- await Promise.all(
32
- typographyConfigs.map(async ({ theme, typography, config }) => {
33
- console.log(`\u{1F477} ${theme} - ${typography}`);
34
- const typographyClasses = await sd.extend(config);
35
- return typographyClasses.buildAllPlatforms();
36
- })
37
- );
38
- }
39
- if (colorModeConfigs.length > 0) {
40
- console.log(`
41
- \u{1F371} Building ${chalk.green("color-mode")}`);
42
- await Promise.all(
43
- colorModeConfigs.map(async ({ theme, mode, config }) => {
44
- console.log(`\u{1F477} ${theme} - ${mode}`);
45
- const themeVariablesSD = await sd.extend(config);
46
- return themeVariablesSD.buildAllPlatforms();
47
- })
48
- );
49
- }
50
- if (semanticConfigs.length > 0) {
51
- console.log(`
52
- \u{1F371} Building ${chalk.green("semantic")}`);
53
- await Promise.all(
54
- semanticConfigs.map(async ({ theme, config, semantic }) => {
55
- console.log(`\u{1F477} ${theme} - ${semantic}`);
56
- const typographyClasses = await sd.extend(config);
57
- return typographyClasses.buildAllPlatforms();
58
- })
59
- );
46
+ const $themes = JSON.parse(await fs.readFile(path.resolve(`${tokensDir}/$themes.json`), "utf-8")).map(processThemeObject);
47
+ const relevant$themes = $themes.filter((theme) => R.not(theme.group === "size" && theme.name !== "default"));
48
+ if (!buildOptions.accentColor) {
49
+ const accentOrFirstMainColor = relevant$themes.find((theme) => theme.name === DEFAULT_COLOR) || relevant$themes.find((theme) => theme.group === "main-color");
50
+ buildOptions.accentColor = accentOrFirstMainColor?.name;
60
51
  }
61
- if (storefrontConfigs.length > 0 && options.preview) {
62
- console.log(`
63
- \u{1F371} Building ${chalk.green("Storefront preview tokens")}`);
64
- await Promise.all(
65
- storefrontConfigs.map(async ({ theme, mode, config }) => {
66
- console.log(`\u{1F477} ${theme} - ${mode}`);
67
- const storefrontSD = await sd.extend(config);
68
- return storefrontSD.buildAllPlatforms();
69
- })
70
- );
52
+ if (buildOptions.accentColor !== DEFAULT_COLOR) {
53
+ console.log("accent color:", buildOptions.accentColor);
71
54
  }
72
- if (semanticConfigs.length > 0) {
73
- console.log(`
74
- \u{1F371} Building ${chalk.green("CSS file")}`);
75
- await Promise.all(
76
- semanticConfigs.map(async ({ theme }) => {
77
- console.log(`\u{1F477} ${theme}.css`);
78
- return makeEntryFile({ theme, outPath, buildPath: path.resolve(`${outPath}/${theme}`) });
55
+ const buildAndSdConfigs = R.map(
56
+ (val) => ({
57
+ buildConfig: val,
58
+ sdConfigs: getConfigsForThemeDimensions(val.getConfig, relevant$themes, val.dimensions, {
59
+ outPath,
60
+ tokensDir,
61
+ ...val.options
79
62
  })
80
- );
63
+ }),
64
+ buildConfigs
65
+ );
66
+ try {
67
+ for (const [key, { buildConfig, sdConfigs }] of R.toPairs(buildAndSdConfigs)) {
68
+ if (!(buildConfig.enabled?.() ?? true)) {
69
+ continue;
70
+ }
71
+ if (sdConfigs.length > 0) {
72
+ console.log(`
73
+ \u{1F371} Building ${chalk.green(buildConfig.name ?? key)}`);
74
+ if (buildConfig.build) {
75
+ return await buildConfig.build(sdConfigs, { outPath, tokensDir, ...buildConfig.options });
76
+ }
77
+ await Promise.all(
78
+ sdConfigs.map(async ({ config, permutation }) => {
79
+ const modes = ["theme", ...buildConfig.dimensions];
80
+ const modeMessage = modes.map((x) => permutation[x]).join(" - ");
81
+ console.log(modeMessage);
82
+ return (await sd.extend(config)).buildAllPlatforms();
83
+ })
84
+ );
85
+ }
86
+ }
87
+ } catch (err) {
88
+ if (err instanceof Error) {
89
+ err.message = err.message.replace('log.verbosity "verbose" or use ', "");
90
+ }
91
+ throw err;
81
92
  }
82
93
  }
83
94
  export {
95
+ DEFAULT_COLOR,
96
+ buildOptions,
84
97
  buildTokens
85
98
  };
@@ -1,4 +1,9 @@
1
1
  import type { Colors, Tokens, Typography } from './types.js';
2
+ export declare const colorCliOptions: {
3
+ readonly main: "main-colors";
4
+ readonly support: "support-colors";
5
+ readonly neutral: "neutral-color";
6
+ };
2
7
  export type CreateTokensOptions = {
3
8
  colors: Colors;
4
9
  typography: Typography;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAyB,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpF,eAAO,MAAM,eAAe;;;;CAIlB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAgFF,eAAO,MAAM,YAAY,SAAU,mBAAmB,WAqBrD,CAAC"}
@@ -1,4 +1,10 @@
1
+ import * as R from "ramda";
1
2
  import { baseColors, generateScaleForColor } from "../colors/index.js";
3
+ const colorCliOptions = {
4
+ main: "main-colors",
5
+ support: "support-colors",
6
+ neutral: "neutral-color"
7
+ };
2
8
  const createColorTokens = (colorArray) => {
3
9
  const obj = {};
4
10
  const $type = "color";
@@ -42,18 +48,14 @@ const generateTypographyTokens = (themeName, { fontFamily }) => {
42
48
  };
43
49
  };
44
50
  const generateThemeTokens = (themeName, theme, colors) => {
45
- const accentColors = generateScaleForColor(colors.accent, theme);
46
- const neutralColors = generateScaleForColor(colors.neutral, theme);
47
- const brand1Colors = generateScaleForColor(colors.brand1, theme);
48
- const brand2Colors = generateScaleForColor(colors.brand2, theme);
49
- const brand3Colors = generateScaleForColor(colors.brand3, theme);
51
+ const main = R.map((color) => createColorTokens(generateScaleForColor(color, theme)), colors.main);
52
+ const support = R.map((color) => createColorTokens(generateScaleForColor(color, theme)), colors.support);
53
+ const neutral = createColorTokens(generateScaleForColor(colors.neutral, theme));
50
54
  return {
51
55
  [themeName]: {
52
- accent: createColorTokens(accentColors),
53
- neutral: createColorTokens(neutralColors),
54
- brand1: createColorTokens(brand1Colors),
55
- brand2: createColorTokens(brand2Colors),
56
- brand3: createColorTokens(brand3Colors)
56
+ ...main,
57
+ ...support,
58
+ neutral
57
59
  }
58
60
  };
59
61
  };
@@ -96,5 +98,6 @@ const createTokens = (opts) => {
96
98
  return tokens;
97
99
  };
98
100
  export {
101
+ colorCliOptions,
99
102
  createTokens
100
103
  };
@@ -134,12 +134,6 @@
134
134
  ]
135
135
  }
136
136
  },
137
- "border-radius": {
138
- "base": {
139
- "$type": "borderRadius",
140
- "$value": "4"
141
- }
142
- },
143
137
  "opacity": {
144
138
  "30": {
145
139
  "$type": "opacity",
@@ -147,13 +141,13 @@
147
141
  }
148
142
  },
149
143
  "sizing": {
150
- "base": {
144
+ "scale": {
151
145
  "$type": "sizing",
152
146
  "$value": "4"
153
147
  }
154
148
  },
155
149
  "spacing": {
156
- "base": {
150
+ "scale": {
157
151
  "$type": "spacing",
158
152
  "$value": "4"
159
153
  }