@digdir/designsystemet 1.0.0-next.41 → 1.0.0-next.42

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 (44) hide show
  1. package/dist/bin/designsystemet.js +18 -13
  2. package/dist/src/colors/luminance.d.ts +54 -0
  3. package/dist/src/colors/luminance.d.ts.map +1 -0
  4. package/dist/src/colors/luminance.js +56 -0
  5. package/dist/src/colors/theme.d.ts +14 -68
  6. package/dist/src/colors/theme.d.ts.map +1 -1
  7. package/dist/src/colors/theme.js +50 -224
  8. package/dist/src/colors/types.d.ts +23 -2
  9. package/dist/src/colors/types.d.ts.map +1 -1
  10. package/dist/src/colors/utils.d.ts +41 -50
  11. package/dist/src/colors/utils.d.ts.map +1 -1
  12. package/dist/src/colors/utils.js +91 -184
  13. package/dist/src/tokens/build/configs.d.ts.map +1 -1
  14. package/dist/src/tokens/build/configs.js +1 -1
  15. package/dist/src/tokens/build/formats/css.js +1 -1
  16. package/dist/src/tokens/build/formats/js-tokens.js +1 -1
  17. package/dist/src/tokens/build/transformers.js +1 -1
  18. package/dist/src/tokens/build/types.d.ts +1 -0
  19. package/dist/src/tokens/build/types.d.ts.map +1 -1
  20. package/dist/src/tokens/build/utils/entryfile.d.ts +1 -0
  21. package/dist/src/tokens/build/utils/entryfile.d.ts.map +1 -1
  22. package/dist/src/tokens/build/utils/entryfile.js +3 -2
  23. package/dist/src/tokens/build.d.ts +3 -1
  24. package/dist/src/tokens/build.d.ts.map +1 -1
  25. package/dist/src/tokens/build.js +16 -11
  26. package/dist/src/tokens/create.js +12 -12
  27. package/dist/src/tokens/types.d.ts +1 -1
  28. package/dist/src/tokens/types.d.ts.map +1 -1
  29. package/dist/src/tokens/{build/utils/utils.d.ts → utils.d.ts} +4 -0
  30. package/dist/src/tokens/utils.d.ts.map +1 -0
  31. package/dist/src/tokens/{build/utils/utils.js → utils.js} +35 -1
  32. package/dist/src/tokens/write/generate$metadata.d.ts +3 -3
  33. package/dist/src/tokens/write/generate$metadata.d.ts.map +1 -1
  34. package/dist/src/tokens/write/generate$metadata.js +4 -4
  35. package/dist/src/tokens/write/generate$themes.d.ts +2 -2
  36. package/dist/src/tokens/write/generate$themes.d.ts.map +1 -1
  37. package/dist/src/tokens/write.d.ts +2 -1
  38. package/dist/src/tokens/write.d.ts.map +1 -1
  39. package/dist/src/tokens/write.js +23 -21
  40. package/package.json +9 -5
  41. package/dist/src/tokens/build/actions.d.ts +0 -6
  42. package/dist/src/tokens/build/actions.d.ts.map +0 -1
  43. package/dist/src/tokens/build/actions.js +0 -33
  44. package/dist/src/tokens/build/utils/utils.d.ts.map +0 -1
@@ -7,6 +7,7 @@ import { configs, getConfigsForThemeDimensions } from "./build/configs.js";
7
7
  import { colorCategories } from "./build/types.js";
8
8
  import { makeEntryFile } from "./build/utils/entryfile.js";
9
9
  import { processThemeObject } from "./build/utils/getMultidimensionalThemes.js";
10
+ import { copyFile, writeFile } from "./utils.js";
10
11
  const DEFAULT_COLOR = "accent";
11
12
  let buildOptions;
12
13
  const sd = new StyleDictionary();
@@ -27,23 +28,24 @@ const buildConfigs = {
27
28
  name: "CSS entry files",
28
29
  getConfig: configs.semanticVariables,
29
30
  dimensions: ["semantic"],
30
- build: async (sdConfigs, { outPath }) => {
31
+ build: async (sdConfigs, { outPath, dry }) => {
31
32
  await Promise.all(
32
33
  sdConfigs.map(async ({ permutation: { theme } }) => {
33
34
  console.log(`\u{1F477} ${theme}.css`);
34
35
  const builtinColorsFilename = "builtin-colors.css";
35
36
  const builtinColors = path.resolve(import.meta.dirname, "build", builtinColorsFilename);
36
- await fs.copyFile(builtinColors, path.resolve(outPath, theme, builtinColorsFilename));
37
- return makeEntryFile({ theme, outPath, buildPath: path.resolve(outPath, theme) });
37
+ await copyFile(builtinColors, path.resolve(outPath, theme, builtinColorsFilename), dry);
38
+ return makeEntryFile({ theme, outPath, buildPath: path.resolve(outPath, theme), dry });
38
39
  })
39
40
  );
40
41
  }
41
42
  }
42
43
  };
43
44
  async function buildTokens(options) {
44
- buildOptions = options;
45
+ const { dry } = options;
45
46
  const tokensDir = options.tokens;
46
- const outPath = path.resolve(options.out);
47
+ const targetDir = path.resolve(options.outDir);
48
+ buildOptions = options;
47
49
  const $themes = JSON.parse(await fs.readFile(path.resolve(`${tokensDir}/$themes.json`), "utf-8")).map(processThemeObject);
48
50
  const relevant$themes = $themes.filter((theme) => R.not(theme.group === "size" && theme.name !== "default"));
49
51
  if (!buildOptions.accentColor) {
@@ -57,7 +59,7 @@ async function buildTokens(options) {
57
59
  (val) => ({
58
60
  buildConfig: val,
59
61
  sdConfigs: getConfigsForThemeDimensions(val.getConfig, relevant$themes, val.dimensions, {
60
- outPath,
62
+ outPath: targetDir,
61
63
  tokensDir,
62
64
  ...val.options
63
65
  })
@@ -73,14 +75,17 @@ async function buildTokens(options) {
73
75
  console.log(`
74
76
  \u{1F371} Building ${chalk.green(buildConfig.name ?? key)}`);
75
77
  if (buildConfig.build) {
76
- await buildConfig.build(sdConfigs, { outPath, tokensDir, ...buildConfig.options });
78
+ await buildConfig.build(sdConfigs, { outPath: targetDir, tokensDir, ...buildConfig.options, dry });
77
79
  }
78
80
  await Promise.all(
79
81
  sdConfigs.map(async ({ config, permutation }) => {
80
82
  const modes = ["theme", ...buildConfig.dimensions];
81
83
  const modeMessage = modes.map((x) => permutation[x]).join(" - ");
82
84
  console.log(modeMessage);
83
- return (await sd.extend(config)).buildAllPlatforms();
85
+ if (!dry) {
86
+ return (await sd.extend(config)).buildAllPlatforms();
87
+ }
88
+ return Promise.resolve();
84
89
  })
85
90
  );
86
91
  }
@@ -91,9 +96,9 @@ async function buildTokens(options) {
91
96
  }
92
97
  throw err;
93
98
  }
94
- await writeColorTypeDeclaration($themes, outPath);
99
+ await writeColorTypeDeclaration($themes, targetDir, dry);
95
100
  }
96
- async function writeColorTypeDeclaration($themes, outPath) {
101
+ async function writeColorTypeDeclaration($themes, outPath, dry) {
97
102
  const colorsFileName = "colors.d.ts";
98
103
  console.log(`
99
104
  \u{1F371} Building ${chalk.green("type declarations")}`);
@@ -110,7 +115,7 @@ ${mainAndSupportColors.map((color) => ` ${color}: never;`).join("\n")}
110
115
  }
111
116
  }
112
117
  `.trimStart();
113
- await fs.writeFile(path.resolve(outPath, colorsFileName), typeDeclaration, "utf-8");
118
+ await writeFile(path.resolve(outPath, colorsFileName), typeDeclaration, dry);
114
119
  }
115
120
  export {
116
121
  DEFAULT_COLOR,
@@ -1,5 +1,5 @@
1
1
  import * as R from "ramda";
2
- import { baseColors, generateScaleForColor } from "../colors/index.js";
2
+ import { baseColors, generateColorScale } from "../colors/index.js";
3
3
  const colorCliOptions = {
4
4
  main: "main-colors",
5
5
  support: "support-colors",
@@ -47,10 +47,10 @@ const generateTypographyTokens = (themeName, { fontFamily }) => {
47
47
  }
48
48
  };
49
49
  };
50
- const generateThemeTokens = (themeName, theme, colors) => {
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
+ const generateThemeTokens = (themeName, colorScheme, colors) => {
51
+ const main = R.map((color) => createColorTokens(generateColorScale(color, colorScheme)), colors.main);
52
+ const support = R.map((color) => createColorTokens(generateColorScale(color, colorScheme)), colors.support);
53
+ const neutral = createColorTokens(generateColorScale(colors.neutral, colorScheme));
54
54
  return {
55
55
  [themeName]: {
56
56
  ...main,
@@ -59,13 +59,13 @@ const generateThemeTokens = (themeName, theme, colors) => {
59
59
  }
60
60
  };
61
61
  };
62
- const generateGlobalTokens = (theme) => {
63
- const blueScale = generateScaleForColor(baseColors.blue, theme);
64
- const greenScale = generateScaleForColor(baseColors.green, theme);
65
- const orangeScale = generateScaleForColor(baseColors.orange, theme);
66
- const purpleScale = generateScaleForColor(baseColors.purple, theme);
67
- const redScale = generateScaleForColor(baseColors.red, theme);
68
- const yellowScale = generateScaleForColor(baseColors.yellow, theme);
62
+ const generateGlobalTokens = (colorScheme) => {
63
+ const blueScale = generateColorScale(baseColors.blue, colorScheme);
64
+ const greenScale = generateColorScale(baseColors.green, colorScheme);
65
+ const orangeScale = generateColorScale(baseColors.orange, colorScheme);
66
+ const purpleScale = generateColorScale(baseColors.purple, colorScheme);
67
+ const redScale = generateColorScale(baseColors.red, colorScheme);
68
+ const yellowScale = generateColorScale(baseColors.yellow, colorScheme);
69
69
  return {
70
70
  global: {
71
71
  blue: createColorTokens(blueScale),
@@ -1,4 +1,4 @@
1
- import type { CssColor } from '@adobe/leonardo-contrast-colors';
1
+ import type { CssColor } from '../colors/types';
2
2
  export type Token = {
3
3
  $value: string;
4
4
  $type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tokens/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAEhE,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AACpE,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAGzC,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE;QACN,KAAK,EAAE,eAAe,CAAC;QACvB,IAAI,EAAE,eAAe,CAAC;QACtB,QAAQ,CAAC,EAAE,eAAe,CAAC;KAC5B,CAAC;IACF,UAAU,EAAE;QACV,OAAO,EAAE,SAAS,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,CAAC;AAEtD,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tokens/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AACpE,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAGzC,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE;QACN,KAAK,EAAE,eAAe,CAAC;QACvB,IAAI,EAAE,eAAe,CAAC;QACtB,QAAQ,CAAC,EAAE,eAAe,CAAC;KAC5B,CAAC;IACF,UAAU,EAAE;QACV,OAAO,EAAE,SAAS,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,CAAC;AAEtD,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC"}
@@ -25,4 +25,8 @@ export declare const pathStartsWithOneOf: import("ts-toolbelt/out/Function/Curry
25
25
  export declare function isSemanticToken(token: TransformedToken): boolean;
26
26
  export declare function isGlobalColorToken(token: TransformedToken): boolean;
27
27
  export declare function isColorCategoryToken(token: TransformedToken, category?: 'main' | 'support'): boolean;
28
+ export declare const mkdir: (dir: string, dry?: boolean) => Promise<string | void>;
29
+ export declare const writeFile: (path: string, data: string, dry?: boolean) => Promise<void>;
30
+ export declare const cp: (src: string, dest: string, dry?: boolean) => Promise<void>;
31
+ export declare const copyFile: (src: string, dest: string, dry?: boolean) => Promise<void>;
28
32
  //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tokens/utils.ts"],"names":[],"mappings":"AAGA,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;AAED,eAAO,MAAM,KAAK,QAAe,MAAM,QAAQ,OAAO,2BAOrD,CAAC;AAEF,eAAO,MAAM,SAAS,SAAgB,MAAM,QAAQ,MAAM,QAAQ,OAAO,kBAOxE,CAAC;AAEF,eAAO,MAAM,EAAE,QAAe,MAAM,QAAQ,MAAM,QAAQ,OAAO,kBAOhE,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAe,MAAM,QAAQ,MAAM,QAAQ,OAAO,kBAOtE,CAAC"}
@@ -1,3 +1,5 @@
1
+ import fs from "node:fs/promises";
2
+ import chalk from "chalk";
1
3
  import * as R from "ramda";
2
4
  const mapToLowerCase = R.map(R.toLower);
3
5
  const hasAnyTruth = R.any(R.equals(true));
@@ -29,12 +31,44 @@ function isColorCategoryToken(token, category) {
29
31
  }
30
32
  return R.startsWith(["color", category], token.path);
31
33
  }
34
+ const mkdir = async (dir, dry) => {
35
+ if (dry) {
36
+ console.log(`${chalk.blue("mkdir")} ${dir}`);
37
+ return Promise.resolve();
38
+ }
39
+ return await fs.mkdir(dir, { recursive: true });
40
+ };
41
+ const writeFile = async (path, data, dry) => {
42
+ if (dry) {
43
+ console.log(`${chalk.blue("writeFile")} ${path}`);
44
+ return Promise.resolve();
45
+ }
46
+ return await fs.writeFile(path, data, { encoding: "utf-8" });
47
+ };
48
+ const cp = async (src, dest, dry) => {
49
+ if (dry) {
50
+ console.log(`${chalk.blue("cp")} ${src} ${dest}`);
51
+ return Promise.resolve();
52
+ }
53
+ return await fs.cp(src, dest, { recursive: true });
54
+ };
55
+ const copyFile = async (src, dest, dry) => {
56
+ if (dry) {
57
+ console.log(`${chalk.blue("copyFile")} ${src} to ${dest}`);
58
+ return Promise.resolve();
59
+ }
60
+ return await fs.copyFile(src, dest);
61
+ };
32
62
  export {
63
+ copyFile,
64
+ cp,
33
65
  getType,
34
66
  getValue,
35
67
  isColorCategoryToken,
36
68
  isGlobalColorToken,
37
69
  isSemanticToken,
70
+ mkdir,
38
71
  pathStartsWithOneOf,
39
- typeEquals
72
+ typeEquals,
73
+ writeFile
40
74
  };
@@ -1,9 +1,9 @@
1
- import type { ColorMode } from '../../colors/types.js';
1
+ import type { ColorScheme } from '../../colors/types.js';
2
2
  import type { Colors } from '../types.js';
3
- type ColorModes = Array<ColorMode>;
3
+ type ColorSchemes = Array<ColorScheme>;
4
4
  type Metadata = {
5
5
  tokenSetOrder: string[];
6
6
  };
7
- export declare function generateMetadataJson(modes: ColorModes, themes: string[], colors: Colors): Metadata;
7
+ export declare function generateMetadataJson(schemes: ColorSchemes, themes: string[], colors: Colors): Metadata;
8
8
  export {};
9
9
  //# sourceMappingURL=generate$metadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate$metadata.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AAEnC,KAAK,QAAQ,GAAG;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAmBlG"}
1
+ {"version":3,"file":"generate$metadata.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAEvC,KAAK,QAAQ,GAAG;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAmBtG"}
@@ -1,13 +1,13 @@
1
- function generateMetadataJson(modes, themes, colors) {
1
+ function generateMetadataJson(schemes, themes, colors) {
2
2
  return {
3
3
  tokenSetOrder: [
4
4
  "primitives/globals",
5
5
  "primitives/size/default",
6
6
  ...themes.map((theme) => `primitives/modes/typography/primary/${theme}`),
7
7
  ...themes.map((theme) => `primitives/modes/typography/secondary/${theme}`),
8
- ...modes.flatMap((mode) => [
9
- `primitives/modes/color-scheme/${mode}/global`,
10
- ...themes.map((theme) => `primitives/modes/color-scheme/${mode}/${theme}`)
8
+ ...schemes.flatMap((scheme) => [
9
+ `primitives/modes/color-scheme/${scheme}/global`,
10
+ ...themes.map((theme) => `primitives/modes/color-scheme/${scheme}/${theme}`)
11
11
  ]),
12
12
  ...themes.map((theme) => `themes/${theme}`),
13
13
  "semantic/color",
@@ -1,7 +1,7 @@
1
1
  import { type ThemeObject } from '@tokens-studio/types';
2
- import type { ColorMode } from '../../colors/types.js';
2
+ import type { ColorScheme } from '../../colors/types.js';
3
3
  import type { Colors } from '../types.js';
4
- type ColorSchemes = Array<ColorMode>;
4
+ type ColorSchemes = Array<ColorScheme>;
5
5
  type ThemeObject_ = ThemeObject & {
6
6
  $figmaCollectionId?: string;
7
7
  $figmaModeId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"generate$themes.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$themes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAM1C,KAAK,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AAErC,KAAK,YAAY,GAAG,WAAW,GAAG;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAU/G"}
1
+ {"version":3,"file":"generate$themes.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$themes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAM1C,KAAK,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAEvC,KAAK,YAAY,GAAG,WAAW,GAAG;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAU/G"}
@@ -1,10 +1,11 @@
1
1
  import type { Colors, Tokens } from './types.js';
2
2
  export declare const stringify: (data: unknown) => string;
3
3
  type WriteTokensOptions = {
4
- writeDir: string;
4
+ outDir: string;
5
5
  tokens: Tokens;
6
6
  themeName: string;
7
7
  colors: Colors;
8
+ dry?: boolean;
8
9
  };
9
10
  export declare const writeTokens: (options: WriteTokensOptions) => Promise<void>;
10
11
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAc,MAAM,EAAQ,MAAM,EAA8B,MAAM,YAAY,CAAC;AAQ/F,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,WAAW,YAAmB,kBAAkB,kBAkK5D,CAAC"}
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAc,MAAM,EAAQ,MAAM,EAA8B,MAAM,YAAY,CAAC;AAS/F,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,WAAW,YAAmB,kBAAkB,kBAmK5D,CAAC"}
@@ -7,14 +7,15 @@ import customColorTemplate from "./design-tokens/template/semantic/modes/categor
7
7
  import semanticColorTemplate from "./design-tokens/template/semantic/semantic-color-template.json" with { type: "json" };
8
8
  import themeBaseFile from "./design-tokens/template/themes/theme-base-file.json" with { type: "json" };
9
9
  import themeColorTemplate from "./design-tokens/template/themes/theme-color-template.json" with { type: "json" };
10
+ import { cp, mkdir, writeFile } from "./utils.js";
10
11
  import { generateMetadataJson } from "./write/generate$metadata.js";
11
12
  import { generateThemesJson } from "./write/generate$themes.js";
12
13
  const DIRNAME = import.meta.dirname || __dirname;
13
14
  const DEFAULT_FILES_PATH = path.join(DIRNAME, "./design-tokens/default");
14
15
  const TEMPLATE_FILES_PATH = path.join(DIRNAME, "./design-tokens/template/");
15
16
  const stringify = (data) => JSON.stringify(data, null, 2);
16
- const generateColorSchemeFile = (folder, name, tokens, outPath) => {
17
- const path2 = `${outPath}/primitives/modes/color-scheme/${folder}`;
17
+ const generateColorSchemeFile = (scheme, name, tokens, outPath) => {
18
+ const path2 = `${outPath}/primitives/modes/color-scheme/${scheme}`;
18
19
  return {
19
20
  data: stringify(tokens),
20
21
  path: path2,
@@ -30,12 +31,12 @@ const generateTypographyFile = (folder, name, tokens, outPath) => {
30
31
  };
31
32
  };
32
33
  const writeTokens = async (options) => {
33
- const { writeDir, tokens, themeName, colors } = options;
34
- const targetDir = path.resolve(process.cwd(), String(writeDir));
34
+ const { outDir, tokens, themeName, colors, dry } = options;
35
+ const targetDir = path.resolve(process.cwd(), String(outDir));
35
36
  const $themesPath = path.join(targetDir, "$themes.json");
36
37
  const $metadataPath = path.join(targetDir, "$metadata.json");
37
38
  let themes = [themeName];
38
- await fs.mkdir(targetDir, { recursive: true });
39
+ await mkdir(targetDir, dry);
39
40
  try {
40
41
  const $themes = await fs.readFile($themesPath, "utf-8");
41
42
  const themeObjects = JSON.parse($themes) || [];
@@ -50,11 +51,9 @@ const writeTokens = async (options) => {
50
51
  console.log(`Themes: ${chalk.blue(themes.join(", "))}`);
51
52
  const $theme = generateThemesJson(["light", "dark"], themes, colors);
52
53
  const $metadata = generateMetadataJson(["light", "dark"], themes, colors);
53
- await fs.writeFile($themesPath, stringify($theme));
54
- await fs.writeFile($metadataPath, stringify($metadata));
55
- await fs.cp(DEFAULT_FILES_PATH, targetDir, {
56
- recursive: true
57
- });
54
+ await writeFile($themesPath, stringify($theme), dry);
55
+ await writeFile($metadataPath, stringify($metadata), dry);
56
+ await cp(DEFAULT_FILES_PATH, targetDir, dry);
58
57
  const mainColorNames = Object.keys(colors.main);
59
58
  const supportColorNames = Object.keys(colors.support);
60
59
  const customColors = [...mainColorNames, "neutral", ...supportColorNames];
@@ -64,14 +63,14 @@ const writeTokens = async (options) => {
64
63
  ["support", supportColorNames]
65
64
  ]) {
66
65
  const colorCategoryPath = path.join(targetDir, "semantic", "modes", `${colorCategory}-color`);
67
- await fs.mkdir(colorCategoryPath, { recursive: true });
66
+ await mkdir(colorCategoryPath, dry);
68
67
  for (const colorName of colorNames) {
69
68
  const customColorFile = {
70
69
  color: {
71
70
  [colorCategory]: customColorTemplate
72
71
  }
73
72
  };
74
- await fs.writeFile(
73
+ await writeFile(
75
74
  path.join(colorCategoryPath, `${colorName}.json`),
76
75
  JSON.stringify(
77
76
  customColorFile,
@@ -82,7 +81,8 @@ const writeTokens = async (options) => {
82
81
  return value;
83
82
  },
84
83
  2
85
- )
84
+ ),
85
+ dry
86
86
  );
87
87
  }
88
88
  }
@@ -98,7 +98,7 @@ const writeTokens = async (options) => {
98
98
  ...semanticColorBaseFile.color
99
99
  }
100
100
  };
101
- await fs.writeFile(
101
+ await writeFile(
102
102
  path.join(targetDir, `semantic/color.json`),
103
103
  JSON.stringify(
104
104
  semanticColors,
@@ -109,9 +109,10 @@ const writeTokens = async (options) => {
109
109
  return value;
110
110
  },
111
111
  2
112
- )
112
+ ),
113
+ dry
113
114
  );
114
- await fs.mkdir(path.join(targetDir, "themes"), { recursive: true });
115
+ await mkdir(path.join(targetDir, "themes"), dry);
115
116
  const themeColorTokens = Object.fromEntries(
116
117
  customColors.map(
117
118
  (colorName) => [
@@ -128,7 +129,7 @@ const writeTokens = async (options) => {
128
129
  },
129
130
  ...remainingThemeFile
130
131
  };
131
- await fs.writeFile(
132
+ await writeFile(
132
133
  path.join(targetDir, `themes/${themeName}.json`),
133
134
  JSON.stringify(
134
135
  themeFile,
@@ -139,7 +140,8 @@ const writeTokens = async (options) => {
139
140
  return value;
140
141
  },
141
142
  2
142
- )
143
+ ),
144
+ dry
143
145
  );
144
146
  const files = [
145
147
  generateColorSchemeFile("light", themeName, tokens.colors.light[themeName], targetDir),
@@ -154,11 +156,11 @@ const writeTokens = async (options) => {
154
156
  for (const file of files) {
155
157
  const dirPath = path.resolve(file.path);
156
158
  const filePath = path.resolve(file.filePath);
157
- await fs.mkdir(dirPath, { recursive: true });
158
- await fs.writeFile(filePath, file.data, { encoding: "utf-8" });
159
+ await mkdir(dirPath, dry);
160
+ await writeFile(filePath, file.data, dry);
159
161
  }
160
162
  console.log(
161
- `Finished creating Designsystem design tokens in ${chalk.green(writeDir)} for theme ${chalk.blue(themeName)}`
163
+ `Finished creating Designsystem design tokens in ${chalk.green(outDir)} for theme ${chalk.blue(themeName)}`
162
164
  );
163
165
  };
164
166
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "1.0.0-next.41",
3
+ "version": "1.0.0-next.42",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "repository": {
@@ -34,18 +34,22 @@
34
34
  "build:tokens": "yarn clean:theme && yarn designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand",
35
35
  "build:tokens:debug": "yarn clean:theme && tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand",
36
36
  "build": "tsup && yarn build:types",
37
- "build:swc": "yarn clean && swc src bin --copy-files -d dist && yarn build:types",
38
37
  "build:types": "tsc --emitDeclarationOnly --declaration",
39
- "test:tokens-create": "yarn designsystemet tokens create -m dominant:#007682 secondary:#ff0000 -n #003333 -s support1:#12404f support2:#0054a6 support3:#942977 -w ./test-tokens-create",
38
+ "types": "tsc --noEmit",
39
+ "test:tokens-create": "yarn designsystemet tokens create -m dominant:#007682 secondary:#ff0000 -n #003333 -s support1:#12404f support2:#0054a6 support3:#942977 -o ./test-tokens-create",
40
40
  "test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens-create -o ./test-tokens-build",
41
41
  "test:tokens-create-and-build": "rimraf test-tokens-create && rimraf test-tokens-build && yarn test:tokens-create && yarn test:tokens-build",
42
42
  "test": "yarn test:tokens-create-and-build",
43
43
  "clean": "rimraf dist",
44
44
  "clean:theme": "yarn workspace @digdir/designsystemet-theme clean",
45
- "update:template": "tsx ./src/tokens/template.ts"
45
+ "update:template": "tsx ./src/tokens/template.ts",
46
+ "internal:tokens-create-digdir": "yarn designsystemet tokens create --theme theme -m accent:#0062BA -n #1E2B3C -s brand1:#F45F63 brand2:#E5AA20 brand3:#1E98F5 -o ./internal/design-tokens",
47
+ "internal:tokens-create-altinn": "yarn designsystemet tokens create --theme theme2 -m accent:#0162BA -n #1E2B3C -s brand1:#0162BA brand2:#3F3161 brand3:#E02F4A -o ./internal/design-tokens",
48
+ "internal:tokens-create-uutilsynet": "yarn designsystemet tokens create --theme theme3 -m accent:#0162BA -n #1E2B3C -s brand1:#5B60D1 brand2:#FEA769 brand3:#5DA290 -o ./internal/design-tokens",
49
+ "internal:tokens-create-portal": "yarn designsystemet tokens create --theme theme4 -m accent:#4D107D -n #1E2B3C -s brand1:#A259DC brand2:#DF73E4 brand3:#E86ABF -o ./internal/design-tokens",
50
+ "internal:tokens-create-all": "yarn internal:tokens-create-digdir && yarn internal:tokens-create-altinn && yarn internal:tokens-create-uutilsynet && yarn internal:tokens-create-portal"
46
51
  },
47
52
  "dependencies": {
48
- "@adobe/leonardo-contrast-colors": "^1.0.0",
49
53
  "@commander-js/extra-typings": "^12.1.0",
50
54
  "@tokens-studio/sd-transforms": "1.2.2",
51
55
  "apca-w3": "^0.1.9",
@@ -1,6 +0,0 @@
1
- import type { Action } from 'style-dictionary/types';
2
- /**
3
- * Creates a CSS entry file that imports base CSS files for a theme
4
- */
5
- export declare const makeEntryFile: Action;
6
- //# sourceMappingURL=actions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/actions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AASrD;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAuB3B,CAAC"}
@@ -1,33 +0,0 @@
1
- import chalk from "chalk";
2
- import glob from "fast-glob";
3
- import fs from "fs-extra";
4
- import * as R from "ramda";
5
- const sortLightmodeFirst = R.sortWith([R.descend(R.includes("light")), R.descend(R.includes("secondary"))]);
6
- const header = `@charset "UTF-8";
7
-
8
- @layer ds.reset, ds.theme, ds.base, ds.utilities, ds.components;
9
-
10
- `;
11
- const makeEntryFile = {
12
- name: "make_entryfile",
13
- do: async (dictionary, platform) => {
14
- const { outPath, theme, log } = platform;
15
- const writePath = `${outPath}/${theme}.css`;
16
- if (log?.verbosity !== "silent") {
17
- console.log(chalk.green(`Creating entry file: ${writePath}`));
18
- }
19
- const generateImportUrls = R.pipe(
20
- sortLightmodeFirst,
21
- R.map((file) => `@import url('${theme}/${file.toString()}');`),
22
- R.join("\n")
23
- );
24
- const files = await glob(`**/*`, { cwd: platform.buildPath });
25
- const content = header + generateImportUrls(files);
26
- await fs.writeFile(writePath, content);
27
- },
28
- undo: async function noOp() {
29
- }
30
- };
31
- export {
32
- makeEntryFile
33
- };
@@ -1 +0,0 @@
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"}