@digdir/designsystemet 1.0.0-next.34 → 1.0.0-next.35
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.
- package/dist/bin/designsystemet.js +3 -2
- package/dist/src/tokens/build/configs.js +5 -5
- package/dist/src/tokens/build/formats/css.js +0 -1
- package/dist/src/tokens/build/utils/entryfile.js +31 -4
- package/dist/src/tokens/build.js +67 -53
- package/dist/src/tokens/design-tokens/default/semantic/style.json +23 -35
- package/dist/src/tokens/design-tokens/template/$themes.json +736 -728
- package/dist/types/src/tokens/build/configs.d.ts +2 -2
- package/dist/types/src/tokens/build/configs.d.ts.map +1 -1
- package/dist/types/src/tokens/build/formats/css.d.ts.map +1 -1
- package/dist/types/src/tokens/build/utils/entryfile.d.ts.map +1 -1
- package/dist/types/src/tokens/build.d.ts +2 -0
- package/dist/types/src/tokens/build.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -11,12 +11,13 @@ program.name("Designsystemet").description("CLI for working with Designsystemet"
|
|
|
11
11
|
function makeTokenCommands() {
|
|
12
12
|
const tokenCmd = createCommand("tokens");
|
|
13
13
|
const DEFAULT_TOKENSDIR = "./design-tokens";
|
|
14
|
-
tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${chalk.blue("design-tokens")}`, DEFAULT_TOKENSDIR).option("-o, --out <string>", `Output directory for built ${chalk.blue("design-tokens")}`, "./dist/tokens").option("-p, --preview", "Generate preview token.ts files", false).action((opts) => {
|
|
14
|
+
tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${chalk.blue("design-tokens")}`, DEFAULT_TOKENSDIR).option("-o, --out <string>", `Output directory for built ${chalk.blue("design-tokens")}`, "./dist/tokens").option("-p, --preview", "Generate preview token.ts files", false).option("--verbose", "Enable verbose output", false).action((opts) => {
|
|
15
15
|
const tokens = typeof opts.tokens === "string" ? opts.tokens : DEFAULT_TOKENSDIR;
|
|
16
16
|
const out = typeof opts.out === "string" ? opts.out : "./dist/tokens";
|
|
17
17
|
const preview = opts.preview;
|
|
18
|
+
const verbose = opts.verbose;
|
|
18
19
|
console.log(`Bulding tokens in ${chalk.green(tokens)}`);
|
|
19
|
-
return buildTokens({ tokens, out, preview });
|
|
20
|
+
return buildTokens({ tokens, out, preview, verbose });
|
|
20
21
|
});
|
|
21
22
|
tokenCmd.command("create").description("Create Designsystemet tokens").requiredOption("-a, --accent <number>", `Accent hex color`).requiredOption("-n, --neutral <number>", `Neutral hex color`).requiredOption("-b1, --brand1 <number>", `Brand1 hex color`).requiredOption("-b2, --brand2 <number>", `Brand2 hex color`).requiredOption("-b3, --brand3 <number>", `Brand3 hex color`).option("-w, --write [string]", `Output directory for created ${chalk.blue("design-tokens")}`, DEFAULT_TOKENSDIR).option("-f, --font-family <string>", `Font family`, "Inter").option("--theme <string>", `Theme name`, "theme").action(async (opts) => {
|
|
22
23
|
const { theme, fontFamily } = opts;
|
|
@@ -48,7 +48,6 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
48
48
|
const layer = `ds.theme.color-mode.${mode}`;
|
|
49
49
|
return {
|
|
50
50
|
usesDtcg,
|
|
51
|
-
log: { verbosity: "silent" },
|
|
52
51
|
preprocessors: ["tokens-studio"],
|
|
53
52
|
platforms: {
|
|
54
53
|
css: {
|
|
@@ -83,7 +82,6 @@ const semanticVariables = ({ outPath, theme }) => {
|
|
|
83
82
|
const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing", "border-radius"], token);
|
|
84
83
|
return {
|
|
85
84
|
usesDtcg,
|
|
86
|
-
log: { verbosity: "silent" },
|
|
87
85
|
preprocessors: ["tokens-studio"],
|
|
88
86
|
platforms: {
|
|
89
87
|
css: {
|
|
@@ -116,7 +114,6 @@ const semanticVariables = ({ outPath, theme }) => {
|
|
|
116
114
|
const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
|
|
117
115
|
return {
|
|
118
116
|
usesDtcg,
|
|
119
|
-
log: { verbosity: "silent" },
|
|
120
117
|
preprocessors: ["tokens-studio"],
|
|
121
118
|
platforms: {
|
|
122
119
|
ts: {
|
|
@@ -151,7 +148,6 @@ const typographyVariables = ({ outPath, theme, typography }) => {
|
|
|
151
148
|
const layer = `ds.theme.typography.${typography}`;
|
|
152
149
|
return {
|
|
153
150
|
usesDtcg: true,
|
|
154
|
-
log: { verbosity: "silent" },
|
|
155
151
|
preprocessors: ["tokens-studio"],
|
|
156
152
|
expand: {
|
|
157
153
|
include: ["typography"],
|
|
@@ -196,7 +192,7 @@ const typographyVariables = ({ outPath, theme, typography }) => {
|
|
|
196
192
|
}
|
|
197
193
|
};
|
|
198
194
|
};
|
|
199
|
-
const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes) => permutatedThemes.map((permutatedTheme) => {
|
|
195
|
+
const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes, logVerbosity) => permutatedThemes.map((permutatedTheme) => {
|
|
200
196
|
const {
|
|
201
197
|
selectedTokenSets = [],
|
|
202
198
|
mode = "unknown",
|
|
@@ -220,6 +216,10 @@ const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes) => permutat
|
|
|
220
216
|
});
|
|
221
217
|
const config = {
|
|
222
218
|
...config_,
|
|
219
|
+
log: {
|
|
220
|
+
...config_?.log,
|
|
221
|
+
verbosity: logVerbosity
|
|
222
|
+
},
|
|
223
223
|
source,
|
|
224
224
|
include
|
|
225
225
|
};
|
|
@@ -87,7 +87,6 @@ const typography = {
|
|
|
87
87
|
format: "css",
|
|
88
88
|
usesDtcg
|
|
89
89
|
});
|
|
90
|
-
console.log("dictionary.allTokens", dictionary.allTokens);
|
|
91
90
|
const filteredTokens = R.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
92
91
|
const formattedTokens = R.pipe(R.map(format), R.join("\n"))(filteredTokens);
|
|
93
92
|
const content = selector ? `${selector} {
|
|
@@ -1,14 +1,40 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
1
2
|
import glob from "fast-glob";
|
|
2
3
|
import fs from "fs-extra";
|
|
3
4
|
import * as R from "ramda";
|
|
4
|
-
const
|
|
5
|
+
const sortOrder = [
|
|
6
|
+
"color-mode/light",
|
|
7
|
+
"typography/secondary",
|
|
8
|
+
"semantic",
|
|
9
|
+
"color-mode/dark",
|
|
10
|
+
"color-mode/contrast",
|
|
11
|
+
"typography/primary"
|
|
12
|
+
];
|
|
13
|
+
const sortByDefinedOrder = R.sortBy((fileName) => {
|
|
14
|
+
const sortIndex = sortOrder.findIndex((sortElement) => fileName.includes(`${sortElement}.css`));
|
|
15
|
+
if (sortIndex === -1) {
|
|
16
|
+
console.error(
|
|
17
|
+
chalk.yellow("WARNING: CSS section does not have a defined sort order:", fileName.replace(".css", ""))
|
|
18
|
+
);
|
|
19
|
+
console.log(
|
|
20
|
+
chalk.dim(
|
|
21
|
+
`
|
|
22
|
+
A Digdir developer should define its order in the sortOrder array in entryfile.ts.
|
|
23
|
+
The section will currently be added to the end of the entry file, but the exact
|
|
24
|
+
order may change due to nondeterminism.`.trim()
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
console.log();
|
|
28
|
+
return Infinity;
|
|
29
|
+
}
|
|
30
|
+
return sortIndex;
|
|
31
|
+
});
|
|
5
32
|
const header = `@charset "UTF-8";
|
|
6
33
|
|
|
7
34
|
@layer ds.reset, ds.theme, ds.base, ds.utilities, ds.components;
|
|
8
35
|
|
|
9
36
|
`;
|
|
10
|
-
const
|
|
11
|
-
sortLightmodeFirst,
|
|
37
|
+
const concat = R.pipe(
|
|
12
38
|
R.map((file) => {
|
|
13
39
|
try {
|
|
14
40
|
const content = fs.readFileSync(file, "utf-8").toString();
|
|
@@ -23,7 +49,8 @@ const sortAndConcat = R.pipe(
|
|
|
23
49
|
const makeEntryFile = async ({ outPath, buildPath, theme }) => {
|
|
24
50
|
const writePath = `${outPath}/${theme}.css`;
|
|
25
51
|
const files = await glob(`**/*`, { cwd: buildPath });
|
|
26
|
-
const
|
|
52
|
+
const sortedFileNames = sortByDefinedOrder(files);
|
|
53
|
+
const content = header + concat(sortedFileNames.map((file) => `${buildPath}/${file}`));
|
|
27
54
|
await fs.writeFile(writePath, content);
|
|
28
55
|
};
|
|
29
56
|
export {
|
package/dist/src/tokens/build.js
CHANGED
|
@@ -8,76 +8,90 @@ import { makeEntryFile } from "./build/utils/entryfile.js";
|
|
|
8
8
|
const { permutateThemes, getConfigs } = configs;
|
|
9
9
|
const sd = new StyleDictionary();
|
|
10
10
|
async function buildTokens(options) {
|
|
11
|
+
const verbosity = options.verbose ? "verbose" : "silent";
|
|
11
12
|
const tokensDir = options.tokens;
|
|
12
13
|
const storefrontOutDir = path.resolve("../../apps/storefront/tokens");
|
|
13
14
|
const outPath = path.resolve(options.out);
|
|
14
15
|
const $themes = JSON.parse(fs.readFileSync(path.resolve(`${tokensDir}/$themes.json`), "utf-8"));
|
|
15
16
|
const relevant$themes = $themes.filter((theme) => {
|
|
16
17
|
const group = R.toLower(R.defaultTo("")(theme.group));
|
|
17
|
-
if (group === "size" && theme.name !== "default") return false;
|
|
18
|
+
if (group === "size" && theme.name.toLowerCase() !== "default") return false;
|
|
18
19
|
return true;
|
|
19
20
|
});
|
|
20
21
|
const themes = permutateThemes(relevant$themes);
|
|
21
22
|
const typographyThemes = R.filter((val) => val.mode === "light", themes);
|
|
22
23
|
const colormodeThemes = R.filter((val) => val.typography === "primary", themes);
|
|
23
24
|
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(
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const colorModeConfigs = getConfigs(configs.colorModeVariables, outPath, tokensDir, colormodeThemes, verbosity);
|
|
26
|
+
const semanticConfigs = getConfigs(configs.semanticVariables, outPath, tokensDir, semanticThemes, verbosity);
|
|
27
|
+
const typographyConfigs = getConfigs(configs.typographyVariables, outPath, tokensDir, typographyThemes, verbosity);
|
|
28
|
+
const storefrontConfigs = getConfigs(
|
|
29
|
+
configs.typescriptTokens,
|
|
30
|
+
storefrontOutDir,
|
|
31
|
+
tokensDir,
|
|
32
|
+
colormodeThemes,
|
|
33
|
+
verbosity
|
|
34
|
+
);
|
|
35
|
+
try {
|
|
36
|
+
if (typographyConfigs.length > 0) {
|
|
37
|
+
console.log(`
|
|
30
38
|
\u{1F371} Building ${chalk.green("typography")}`);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
await Promise.all(
|
|
40
|
+
typographyConfigs.map(async ({ theme, typography, config }) => {
|
|
41
|
+
console.log(`\u{1F477} ${theme} - ${typography}`);
|
|
42
|
+
const typographyClasses = await sd.extend(config);
|
|
43
|
+
return typographyClasses.buildAllPlatforms();
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (colorModeConfigs.length > 0) {
|
|
48
|
+
console.log(`
|
|
41
49
|
\u{1F371} Building ${chalk.green("color-mode")}`);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
await Promise.all(
|
|
51
|
+
colorModeConfigs.map(async ({ theme, mode, config }) => {
|
|
52
|
+
console.log(`\u{1F477} ${theme} - ${mode}`);
|
|
53
|
+
const themeVariablesSD = await sd.extend(config);
|
|
54
|
+
return themeVariablesSD.buildAllPlatforms();
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (semanticConfigs.length > 0) {
|
|
59
|
+
console.log(`
|
|
52
60
|
\u{1F371} Building ${chalk.green("semantic")}`);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
await Promise.all(
|
|
62
|
+
semanticConfigs.map(async ({ theme, config, semantic }) => {
|
|
63
|
+
console.log(`\u{1F477} ${theme} - ${semantic}`);
|
|
64
|
+
const typographyClasses = await sd.extend(config);
|
|
65
|
+
return typographyClasses.buildAllPlatforms();
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (storefrontConfigs.length > 0 && options.preview) {
|
|
70
|
+
console.log(`
|
|
63
71
|
\u{1F371} Building ${chalk.green("Storefront preview tokens")}`);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
await Promise.all(
|
|
73
|
+
storefrontConfigs.map(async ({ theme, mode, config }) => {
|
|
74
|
+
console.log(`\u{1F477} ${theme} - ${mode}`);
|
|
75
|
+
const storefrontSD = await sd.extend(config);
|
|
76
|
+
return storefrontSD.buildAllPlatforms();
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (semanticConfigs.length > 0) {
|
|
81
|
+
console.log(`
|
|
74
82
|
\u{1F371} Building ${chalk.green("CSS file")}`);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
await Promise.all(
|
|
84
|
+
semanticConfigs.map(async ({ theme }) => {
|
|
85
|
+
console.log(`\u{1F477} ${theme}.css`);
|
|
86
|
+
return makeEntryFile({ theme, outPath, buildPath: path.resolve(`${outPath}/${theme}`) });
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if (err instanceof Error) {
|
|
92
|
+
err.message = err.message.replace('log.verbosity "verbose" or use ', "");
|
|
93
|
+
}
|
|
94
|
+
throw err;
|
|
81
95
|
}
|
|
82
96
|
}
|
|
83
97
|
export {
|
|
@@ -72,49 +72,17 @@
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"$type": "typography",
|
|
78
|
-
"$value": {
|
|
79
|
-
"fontFamily": "{font.family}",
|
|
80
|
-
"fontWeight": "{font-weight.regular}",
|
|
81
|
-
"lineHeight": "{line-height.lg}",
|
|
82
|
-
"fontSize": "{font-size.8}",
|
|
83
|
-
"letterSpacing": "{letter-spacing.8}"
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
"md": {
|
|
75
|
+
"body": {
|
|
76
|
+
"xl": {
|
|
87
77
|
"$type": "typography",
|
|
88
78
|
"$value": {
|
|
89
79
|
"fontFamily": "{font.family}",
|
|
90
80
|
"fontWeight": "{font-weight.regular}",
|
|
91
|
-
"lineHeight": "{line-height.
|
|
81
|
+
"lineHeight": "{line-height.md}",
|
|
92
82
|
"fontSize": "{font-size.7}",
|
|
93
83
|
"letterSpacing": "{letter-spacing.8}"
|
|
94
84
|
}
|
|
95
85
|
},
|
|
96
|
-
"sm": {
|
|
97
|
-
"$type": "typography",
|
|
98
|
-
"$value": {
|
|
99
|
-
"fontFamily": "{font.family}",
|
|
100
|
-
"fontWeight": "{font-weight.regular}",
|
|
101
|
-
"lineHeight": "{line-height.lg}",
|
|
102
|
-
"fontSize": "{font-size.6}",
|
|
103
|
-
"letterSpacing": "{letter-spacing.7}"
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"xs": {
|
|
107
|
-
"$type": "typography",
|
|
108
|
-
"$value": {
|
|
109
|
-
"fontFamily": "{font.family}",
|
|
110
|
-
"fontWeight": "{font-weight.regular}",
|
|
111
|
-
"lineHeight": "{line-height.lg}",
|
|
112
|
-
"fontSize": "{font-size.5}",
|
|
113
|
-
"letterSpacing": "{letter-spacing.6}"
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
"paragraph": {
|
|
118
86
|
"lg": {
|
|
119
87
|
"$type": "typography",
|
|
120
88
|
"$value": {
|
|
@@ -156,6 +124,16 @@
|
|
|
156
124
|
}
|
|
157
125
|
},
|
|
158
126
|
"short": {
|
|
127
|
+
"xl": {
|
|
128
|
+
"$type": "typography",
|
|
129
|
+
"$value": {
|
|
130
|
+
"fontFamily": "{font.family}",
|
|
131
|
+
"fontWeight": "{font-weight.regular}",
|
|
132
|
+
"lineHeight": "{line-height.sm}",
|
|
133
|
+
"fontSize": "{font-size.7}",
|
|
134
|
+
"letterSpacing": "{letter-spacing.8}"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
159
137
|
"lg": {
|
|
160
138
|
"$type": "typography",
|
|
161
139
|
"$value": {
|
|
@@ -198,6 +176,16 @@
|
|
|
198
176
|
}
|
|
199
177
|
},
|
|
200
178
|
"long": {
|
|
179
|
+
"xl": {
|
|
180
|
+
"$type": "typography",
|
|
181
|
+
"$value": {
|
|
182
|
+
"fontFamily": "{font.family}",
|
|
183
|
+
"fontWeight": "{font-weight.regular}",
|
|
184
|
+
"lineHeight": "{line-height.lg}",
|
|
185
|
+
"fontSize": "{font-size.7}",
|
|
186
|
+
"letterSpacing": "{letter-spacing.8}"
|
|
187
|
+
}
|
|
188
|
+
},
|
|
201
189
|
"lg": {
|
|
202
190
|
"$type": "typography",
|
|
203
191
|
"$value": {
|