@digdir/designsystemet 1.0.0-next.33 → 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 +24 -13
- package/dist/src/tokens/build/formats/css.js +16 -92
- package/dist/src/tokens/build/transformers.js +7 -7
- 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 +3 -3
- 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/transformers.d.ts +1 -1
- package/dist/types/src/tokens/build/transformers.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;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { register } from "@tokens-studio/sd-transforms";
|
|
1
|
+
import { expandTypesMap, register } from "@tokens-studio/sd-transforms";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
import StyleDictionary from "style-dictionary";
|
|
4
4
|
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
5
5
|
import * as formats from "./formats/css.js";
|
|
6
6
|
import { jsTokens } from "./formats/js-tokens.js";
|
|
7
|
-
import { nameKebab, sizeRem,
|
|
7
|
+
import { nameKebab, sizeRem, typographyName } from "./transformers.js";
|
|
8
8
|
import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
|
|
9
9
|
import { pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
|
|
10
10
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
@@ -15,7 +15,7 @@ const separator = "_";
|
|
|
15
15
|
const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
|
|
16
16
|
StyleDictionary.registerTransform(sizeRem);
|
|
17
17
|
StyleDictionary.registerTransform(nameKebab);
|
|
18
|
-
StyleDictionary.registerTransform(
|
|
18
|
+
StyleDictionary.registerTransform(typographyName);
|
|
19
19
|
StyleDictionary.registerFormat(jsTokens);
|
|
20
20
|
StyleDictionary.registerFormat(formats.colormode);
|
|
21
21
|
StyleDictionary.registerFormat(formats.semantic);
|
|
@@ -26,7 +26,7 @@ const dsTransformers = [
|
|
|
26
26
|
"ts/size/px",
|
|
27
27
|
sizeRem.name,
|
|
28
28
|
"ts/typography/fontWeight",
|
|
29
|
-
|
|
29
|
+
typographyName.name,
|
|
30
30
|
"ts/color/modifiers",
|
|
31
31
|
"ts/color/css/hexrgba",
|
|
32
32
|
"ts/size/lineheight",
|
|
@@ -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: {
|
|
@@ -102,7 +100,7 @@ const semanticVariables = ({ outPath, theme }) => {
|
|
|
102
100
|
{
|
|
103
101
|
destination: `semantic.css`,
|
|
104
102
|
format: formats.semantic.name,
|
|
105
|
-
filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily"], token)
|
|
103
|
+
filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily", "typography"], token)
|
|
106
104
|
}
|
|
107
105
|
],
|
|
108
106
|
options: {
|
|
@@ -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: {
|
|
@@ -146,13 +143,16 @@ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
|
|
|
146
143
|
}
|
|
147
144
|
};
|
|
148
145
|
};
|
|
149
|
-
const
|
|
146
|
+
const typographyVariables = ({ outPath, theme, typography }) => {
|
|
150
147
|
const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${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"],
|
|
152
|
+
expand: {
|
|
153
|
+
include: ["typography"],
|
|
154
|
+
typesMap: { ...expandTypesMap, typography: { ...expandTypesMap.typography, letterSpacing: "dimension" } }
|
|
155
|
+
},
|
|
156
156
|
platforms: {
|
|
157
157
|
css: {
|
|
158
158
|
prefix,
|
|
@@ -161,7 +161,14 @@ const typographyCSS = ({ outPath, theme, typography }) => {
|
|
|
161
161
|
layer,
|
|
162
162
|
buildPath: `${outPath}/${theme}/`,
|
|
163
163
|
basePxFontSize,
|
|
164
|
-
transforms: [
|
|
164
|
+
transforms: [
|
|
165
|
+
nameKebab.name,
|
|
166
|
+
"ts/size/px",
|
|
167
|
+
sizeRem.name,
|
|
168
|
+
"ts/size/lineheight",
|
|
169
|
+
"ts/typography/fontWeight",
|
|
170
|
+
typographyName.name
|
|
171
|
+
],
|
|
165
172
|
files: [
|
|
166
173
|
{
|
|
167
174
|
destination: `typography/${typography}.css`,
|
|
@@ -185,7 +192,7 @@ const typographyCSS = ({ outPath, theme, typography }) => {
|
|
|
185
192
|
}
|
|
186
193
|
};
|
|
187
194
|
};
|
|
188
|
-
const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes) => permutatedThemes.map((permutatedTheme) => {
|
|
195
|
+
const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes, logVerbosity) => permutatedThemes.map((permutatedTheme) => {
|
|
189
196
|
const {
|
|
190
197
|
selectedTokenSets = [],
|
|
191
198
|
mode = "unknown",
|
|
@@ -209,6 +216,10 @@ const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes) => permutat
|
|
|
209
216
|
});
|
|
210
217
|
const config = {
|
|
211
218
|
...config_,
|
|
219
|
+
log: {
|
|
220
|
+
...config_?.log,
|
|
221
|
+
verbosity: logVerbosity
|
|
222
|
+
},
|
|
212
223
|
source,
|
|
213
224
|
include
|
|
214
225
|
};
|
|
@@ -223,5 +234,5 @@ export {
|
|
|
223
234
|
semanticVariables,
|
|
224
235
|
separator,
|
|
225
236
|
typescriptTokens,
|
|
226
|
-
|
|
237
|
+
typographyVariables
|
|
227
238
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
-
import { createPropertyFormatter, fileHeader,
|
|
3
|
-
import {
|
|
4
|
-
import { getValue, typeEquals } from "../utils/utils.js";
|
|
2
|
+
import { createPropertyFormatter, fileHeader, usesReferences } from "style-dictionary/utils";
|
|
3
|
+
import { getValue } from "../utils/utils.js";
|
|
5
4
|
const prefersColorScheme = (mode, content) => `
|
|
6
5
|
@media (prefers-color-scheme: ${mode}) {
|
|
7
6
|
[data-ds-color-mode="auto"] ${content}
|
|
@@ -21,10 +20,12 @@ const colormode = {
|
|
|
21
20
|
format: "css",
|
|
22
21
|
usesDtcg
|
|
23
22
|
});
|
|
24
|
-
const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `
|
|
23
|
+
const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `
|
|
24
|
+
color-scheme: ${mode_};
|
|
25
25
|
` : "";
|
|
26
|
+
const formattedTokens = dictionary.allTokens.map(format).join("\n");
|
|
26
27
|
const content = `{
|
|
27
|
-
${
|
|
28
|
+
${formattedTokens}
|
|
28
29
|
${colorSchemeProperty}}
|
|
29
30
|
`;
|
|
30
31
|
const autoSelectorContent = ["light", "dark"].includes(mode_) ? prefersColorScheme(mode_, content) : "";
|
|
@@ -40,7 +41,6 @@ const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}:
|
|
|
40
41
|
const semantic = {
|
|
41
42
|
name: "ds/css-semantic",
|
|
42
43
|
format: async ({ dictionary, file, options, platform }) => {
|
|
43
|
-
const { allTokens } = dictionary;
|
|
44
44
|
const { outputReferences, usesDtcg } = options;
|
|
45
45
|
const { selector, isCalculatedToken, layer } = platform;
|
|
46
46
|
const header = await fileHeader({ file });
|
|
@@ -50,7 +50,7 @@ const semantic = {
|
|
|
50
50
|
format: "css",
|
|
51
51
|
usesDtcg
|
|
52
52
|
});
|
|
53
|
-
const
|
|
53
|
+
const formattedTokens = R.map((token) => {
|
|
54
54
|
const originalValue = getValue(token.original);
|
|
55
55
|
if (usesReferences(originalValue) && typeof outputReferences === "function" && outputReferences?.(token, { dictionary })) {
|
|
56
56
|
if (isCalculatedToken?.(token, options)) {
|
|
@@ -58,10 +58,9 @@ const semantic = {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
return format(token);
|
|
61
|
-
});
|
|
62
|
-
const formattedVariables = formatTokens(allTokens);
|
|
61
|
+
}, dictionary.allTokens);
|
|
63
62
|
const content = `{
|
|
64
|
-
${
|
|
63
|
+
${formattedTokens.join("\n")}
|
|
65
64
|
}
|
|
66
65
|
`;
|
|
67
66
|
const body = R.isNotNil(layer) ? `@layer ${layer} {
|
|
@@ -72,28 +71,9 @@ ${selector} ${content}
|
|
|
72
71
|
return header + body;
|
|
73
72
|
}
|
|
74
73
|
};
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
R.
|
|
78
|
-
R.head,
|
|
79
|
-
R.defaultTo(""),
|
|
80
|
-
R.trim,
|
|
81
|
-
(name) => `var(${name})`
|
|
82
|
-
);
|
|
83
|
-
const bemify = R.pipe(
|
|
84
|
-
(path) => {
|
|
85
|
-
const filteredPath = path.filter((p) => p !== "typography");
|
|
86
|
-
const withPrefix = R.concat([prefix], R.remove(0, 0, filteredPath));
|
|
87
|
-
const [rest, last] = R.splitAt(-1, withPrefix);
|
|
88
|
-
const className = `${rest.join("-")}--${R.head(last)}`;
|
|
89
|
-
return className;
|
|
90
|
-
},
|
|
91
|
-
R.trim,
|
|
92
|
-
R.toLower
|
|
93
|
-
);
|
|
94
|
-
const classSelector = R.pipe(R.prop("path"), bemify);
|
|
95
|
-
const sortTypographyLast = R.sortWith([
|
|
96
|
-
R.ascend((token) => typeEquals("typography")(token) ? 1 : 0)
|
|
74
|
+
const typographyFontFamilyPredicate = R.allPass([
|
|
75
|
+
R.pathSatisfies(R.includes("typography"), ["path"]),
|
|
76
|
+
R.pathSatisfies(R.includes("fontFamily"), ["path"])
|
|
97
77
|
]);
|
|
98
78
|
const typography = {
|
|
99
79
|
name: "ds/css-typography",
|
|
@@ -107,67 +87,11 @@ const typography = {
|
|
|
107
87
|
format: "css",
|
|
108
88
|
usesDtcg
|
|
109
89
|
});
|
|
110
|
-
const
|
|
111
|
-
const formattedTokens = R.pipe(
|
|
112
|
-
sortByType,
|
|
113
|
-
R.reduce(
|
|
114
|
-
(acc, token) => {
|
|
115
|
-
if (typeEquals("fontweight", token)) {
|
|
116
|
-
const className = `
|
|
117
|
-
.${classSelector(token)} {
|
|
118
|
-
font-weight: ${getValue(token)};
|
|
119
|
-
}`;
|
|
120
|
-
return Object.assign(acc, {
|
|
121
|
-
variables: [...acc.variables, format(token)],
|
|
122
|
-
classes: [...acc.classes, className]
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (typeEquals("lineheight", token)) {
|
|
126
|
-
const className = `
|
|
127
|
-
.${classSelector(token)} {
|
|
128
|
-
line-height: ${getValue(token)};
|
|
129
|
-
}`;
|
|
130
|
-
return Object.assign(acc, {
|
|
131
|
-
variables: [...acc.variables, format(token)],
|
|
132
|
-
classes: [...acc.classes, className]
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
if (typeEquals("typography", token)) {
|
|
136
|
-
let references = [];
|
|
137
|
-
try {
|
|
138
|
-
references = getReferences(getValue(token.original), dictionary.tokens);
|
|
139
|
-
} catch (error) {
|
|
140
|
-
console.error("Error getting references", error);
|
|
141
|
-
throw new Error(JSON.stringify(token, null, 2));
|
|
142
|
-
}
|
|
143
|
-
const fontweight = R.find(typeEquals(["fontweight"]))(references);
|
|
144
|
-
const lineheight = R.find(typeEquals(["lineheight"]))(references);
|
|
145
|
-
const fontsize = R.find(typeEquals(["fontsize"]))(references);
|
|
146
|
-
const letterSpacing = R.find(typeEquals(["dimension"]))(references);
|
|
147
|
-
const fontSizeVar = fontsize ? getVariableName(format(fontsize)) : null;
|
|
148
|
-
const fontWeightVar = fontweight ? getVariableName(format(fontweight)) : null;
|
|
149
|
-
const lineheightVar = lineheight ? getVariableName(format(lineheight)) : null;
|
|
150
|
-
const letterSpacingVar = letterSpacing ? getVariableName(format(letterSpacing)) : null;
|
|
151
|
-
const className = `
|
|
152
|
-
.${classSelector(token)} {
|
|
153
|
-
${fontSizeVar ? `font-size: ${fontSizeVar};` : ""}
|
|
154
|
-
${lineheightVar ? `line-height: ${lineheightVar};` : ""}
|
|
155
|
-
${fontWeightVar ? `font-weight: ${fontWeightVar};` : ""}
|
|
156
|
-
${letterSpacingVar ? `letter-spacing: ${letterSpacingVar};` : ""}
|
|
157
|
-
}`;
|
|
158
|
-
return Object.assign(acc, { classes: [className, ...acc.classes] });
|
|
159
|
-
}
|
|
160
|
-
return Object.assign(acc, { variables: [...acc.variables, format(token)] });
|
|
161
|
-
},
|
|
162
|
-
{ variables: [], classes: [] }
|
|
163
|
-
)
|
|
164
|
-
)(sortedTokens);
|
|
165
|
-
const classes = formattedTokens.classes.join("\n");
|
|
166
|
-
const variables = formattedTokens.variables.join("\n");
|
|
90
|
+
const filteredTokens = R.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
91
|
+
const formattedTokens = R.pipe(R.map(format), R.join("\n"))(filteredTokens);
|
|
167
92
|
const content = selector ? `${selector} {
|
|
168
|
-
${
|
|
169
|
-
|
|
170
|
-
}` : classes;
|
|
93
|
+
${formattedTokens}
|
|
94
|
+
}` : formattedTokens;
|
|
171
95
|
const body = R.isNotNil(layer) ? `@layer ${layer} {
|
|
172
96
|
${content}
|
|
173
97
|
}` : content;
|
|
@@ -34,18 +34,18 @@ const nameKebab = {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
const
|
|
38
|
-
name: "typography
|
|
39
|
-
type: "
|
|
37
|
+
const typographyName = {
|
|
38
|
+
name: "name/typography",
|
|
39
|
+
type: "name",
|
|
40
40
|
transitive: true,
|
|
41
|
-
|
|
41
|
+
// expanded tokens have different type so we match on path instead
|
|
42
|
+
filter: (token) => pathStartsWithOneOf(["typography"], token),
|
|
42
43
|
transform: (token) => {
|
|
43
|
-
|
|
44
|
-
return `${typography.fontWeight} ${typography.fontSize}/${typography.lineHeight} '${typography.fontFamily}'`;
|
|
44
|
+
return token.name.replace("-typography", "");
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
export {
|
|
48
48
|
nameKebab,
|
|
49
49
|
sizeRem,
|
|
50
|
-
|
|
50
|
+
typographyName
|
|
51
51
|
};
|
|
@@ -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.
|
|
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": {
|