@digdir/designsystemet 0.1.0-next.29 → 0.1.0-next.31

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.
@@ -16,10 +16,10 @@ function makeTokenCommands() {
16
16
  console.log(`Bulding tokens in ${chalk.green(tokens)}`);
17
17
  return buildTokens({ tokens, out, preview });
18
18
  });
19
- tokenCmd.command("create").description("Create Designsystemet tokens").option("-w, --write [string]", `Output directory for created ${chalk.blue("design-tokens")}`, "./design-tokens").option("-a, --accent <number>", `Accent hex color`).option("-n, --neutral <number>", `Neutral hex color`).option("-b1, --brand1 <number>", `Brand1 hex color`).option("-b2, --brand2 <number>", `Brand2 hex color`).option("-b3, --brand3 <number>", `Brand3 hex color`).option("-f, --font-family <string>", `Font family`).action(async (opts) => {
19
+ tokenCmd.command("create").description("Create Designsystemet tokens").option("-w, --write [string]", `Output directory for created ${chalk.blue("design-tokens")}`).option("-a, --accent <number>", `Accent hex color`).option("-n, --neutral <number>", `Neutral hex color`).option("-b1, --brand1 <number>", `Brand1 hex color`).option("-b2, --brand2 <number>", `Brand2 hex color`).option("-b3, --brand3 <number>", `Brand3 hex color`).option("-f, --font-family <string>", `Font family`).action(async (opts) => {
20
20
  console.log(`Creating tokens with options ${chalk.green(JSON.stringify(opts))}`);
21
- const outPath = typeof opts.write === "string" ? opts.write : "./design-tokens";
22
21
  const family = typeof opts.fontFamily === "string" ? opts.fontFamily : "Inter";
22
+ const write2 = typeof opts.write === "boolean" ? "./design-tokens" : opts.write;
23
23
  const props = {
24
24
  colors: {
25
25
  accent: convertToHex(opts.accent),
@@ -31,7 +31,7 @@ function makeTokenCommands() {
31
31
  typography: {
32
32
  family
33
33
  },
34
- outPath
34
+ write: write2
35
35
  };
36
36
  await createTokens(props);
37
37
  });
@@ -3,8 +3,8 @@ import { Hsluv } from "hsluv";
3
3
  import { getContrastFromHex, getContrastFromLightness, getLightnessFromHex } from "./utils.js";
4
4
  const baseColors = {
5
5
  blue: "#0A71C0",
6
- green: "#078D19",
7
- orange: "#CA5C21",
6
+ green: "#068718",
7
+ orange: "#B8581D",
8
8
  purple: "#663299",
9
9
  red: "#C01B1B",
10
10
  yellow: "#EABF28"
@@ -2,7 +2,7 @@ import { normalizeTokenSetName } from "./utils.js";
2
2
  function generateMetadataJson(modes, themes) {
3
3
  return {
4
4
  tokenSetOrder: [
5
- "primitives/modes/globals",
5
+ "primitives/globals",
6
6
  "primitives/size/default",
7
7
  "primitives/modes/typography/primary/theme",
8
8
  "primitives/modes/typography/secondary/theme",
@@ -67,8 +67,7 @@ const generateThemeTokens = (theme, colors) => {
67
67
  const generateColorModeFile = (folder, name, tokens, outPath) => {
68
68
  const path2 = `${outPath}/primitives/modes/colors/${folder}`;
69
69
  return {
70
- data: `${JSON.stringify(tokens, null, 2)}
71
- `,
70
+ data: JSON.stringify(tokens, null, 2),
72
71
  path: path2,
73
72
  filePath: `${path2}/${name}.json`
74
73
  };
@@ -76,8 +75,7 @@ const generateColorModeFile = (folder, name, tokens, outPath) => {
76
75
  const generateTypographyFile = (folder, name, tokens, outPath) => {
77
76
  const path2 = `${outPath}/primitives/modes/typography/${folder}`;
78
77
  return {
79
- data: `${JSON.stringify(tokens, null, 2)}
80
- `,
78
+ data: JSON.stringify(tokens, null, 2),
81
79
  path: path2,
82
80
  filePath: `${path2}/${name}.json`
83
81
  };
@@ -101,7 +99,7 @@ const generateGlobalTokens = (theme) => {
101
99
  };
102
100
  };
103
101
  const createTokens = async (opts) => {
104
- const { colors, outPath, typography } = opts;
102
+ const { colors, write, typography } = opts;
105
103
  const tokens = {
106
104
  colors: {
107
105
  light: {
@@ -115,34 +113,33 @@ const createTokens = async (opts) => {
115
113
  primary: generateTypographyTokens(typography)
116
114
  }
117
115
  };
118
- const write = R.isNotNil(outPath);
119
- if (write) {
120
- const targetDir = path.resolve(process.cwd(), outPath);
116
+ if (R.isNotNil(write)) {
117
+ const targetDir = path.resolve(process.cwd(), String(write));
121
118
  await fs.mkdir(targetDir, { recursive: true });
122
119
  console.log("Generating metadata and themes files");
123
120
  const $theme = generateThemesJson(["Light", "Dark", "Contrast"], ["theme"]);
124
121
  const $metadata = generateMetadataJson(["Light", "Dark", "Contrast"], ["theme"]);
125
122
  await fs.writeFile(path.join(targetDir, "$themes.json"), JSON.stringify($theme, null, 2));
126
123
  await fs.writeFile(path.join(targetDir, "$metadata.json"), JSON.stringify($metadata, null, 2));
127
- console.log(`Copy files to ${targetDir}`);
124
+ console.log(`Copying default files to ${targetDir}`);
128
125
  await fs.cp(DEFAULT_FILES_PATH, targetDir, {
129
126
  recursive: true
130
127
  });
131
128
  const files = [
132
- generateColorModeFile("light", "theme", tokens.colors.light.theme, outPath),
133
- generateColorModeFile("light", "global", tokens.colors.light.global, outPath),
134
- generateColorModeFile("dark", "theme", tokens.colors.dark.theme, outPath),
135
- generateColorModeFile("dark", "global", tokens.colors.dark.global, outPath),
136
- generateColorModeFile("contrast", "theme", tokens.colors.contrast.theme, outPath),
137
- generateColorModeFile("contrast", "global", tokens.colors.contrast.global, outPath),
138
- generateTypographyFile("primary", "theme", tokens.typography.primary, outPath),
139
- generateTypographyFile("secondary", "theme", tokens.typography.primary, outPath)
129
+ generateColorModeFile("light", "theme", tokens.colors.light.theme, targetDir),
130
+ generateColorModeFile("light", "global", tokens.colors.light.global, targetDir),
131
+ generateColorModeFile("dark", "theme", tokens.colors.dark.theme, targetDir),
132
+ generateColorModeFile("dark", "global", tokens.colors.dark.global, targetDir),
133
+ generateColorModeFile("contrast", "theme", tokens.colors.contrast.theme, targetDir),
134
+ generateColorModeFile("contrast", "global", tokens.colors.contrast.global, targetDir),
135
+ generateTypographyFile("primary", "theme", tokens.typography.primary, targetDir),
136
+ generateTypographyFile("secondary", "theme", tokens.typography.primary, targetDir)
140
137
  ];
141
138
  for (const file of files) {
142
- const path_ = path.resolve(file.path);
139
+ const dirPath = path.resolve(file.path);
143
140
  const filePath = path.resolve(file.filePath);
144
141
  console.log(`Writing file ${filePath}`);
145
- await fs.mkdir(path_, { recursive: true });
142
+ await fs.mkdir(dirPath, { recursive: true });
146
143
  await fs.writeFile(filePath, file.data, { encoding: "utf-8" });
147
144
  }
148
145
  }
@@ -5,7 +5,7 @@ type Typography = Record<string, string>;
5
5
  type CreateTokens = {
6
6
  colors: Colors;
7
7
  typography: Typography;
8
- outPath: string;
8
+ write?: string;
9
9
  };
10
10
  type DesignTokens = Record<string, {
11
11
  $value: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/create/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAGhE,OAAO,KAAK,EAAwB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI/E,KAAK,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AAC5C,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGzC,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAQF,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AACtE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAC/D,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC/C,KAAK,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AA2GtC,eAAO,MAAM,YAAY,SAAgB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDpD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/create/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAGhE,OAAO,KAAK,EAAwB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI/E,KAAK,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AAC5C,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGzC,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAQF,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AACtE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAC/D,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC/C,KAAK,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AA2GtC,eAAO,MAAM,YAAY,SAAgB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "0.1.0-next.29",
3
+ "version": "0.1.0-next.31",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "repository": {