@digdir/designsystemet 1.0.0-next.46 → 1.0.0-next.47
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/config.d.ts +6 -0
- package/dist/bin/config.d.ts.map +1 -1
- package/dist/bin/config.js +56 -0
- package/dist/bin/designsystemet.js +19 -12
- package/dist/bin/options.js +12 -0
- package/dist/config.schema.json +4 -0
- package/dist/src/tokens/build.d.ts +3 -1
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +5 -2
- package/dist/src/tokens/create.d.ts +1 -0
- package/dist/src/tokens/create.d.ts.map +1 -1
- package/dist/src/tokens/create.js +1 -0
- package/dist/src/tokens/utils.d.ts +1 -0
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/dist/src/tokens/utils.js +9 -0
- package/dist/src/tokens/write.d.ts +3 -0
- package/dist/src/tokens/write.d.ts.map +1 -1
- package/dist/src/tokens/write.js +6 -2
- package/package.json +11 -15
package/dist/bin/config.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const colorRegex: RegExp;
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const configFileSchema: z.ZodObject<{
|
|
8
8
|
outDir: z.ZodOptional<z.ZodString>;
|
|
9
|
+
clean: z.ZodOptional<z.ZodBoolean>;
|
|
9
10
|
themes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
10
11
|
colors: z.ZodObject<{
|
|
11
12
|
main: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodString, `#${string}` | `rgb(${number} ${number} ${number})` | `hsl(${number}deg ${number}% ${number}%)` | `hsv(${number}deg ${number}% ${number}%)` | `hsluv(${number} ${number} ${number})` | `lab(${number}% ${number} ${number})` | `lch(${number}% ${number} ${number}deg)` | `oklab(${number}% ${number} ${number})` | `oklch(${number}% ${number} ${number}deg)` | `jab(${number}% ${number} ${number})` | `jch(${number}% ${number} ${number}deg)`, string>>;
|
|
@@ -61,6 +62,7 @@ export declare const configFileSchema: z.ZodObject<{
|
|
|
61
62
|
};
|
|
62
63
|
borderRadius: number;
|
|
63
64
|
}>;
|
|
65
|
+
clean?: boolean | undefined;
|
|
64
66
|
outDir?: string | undefined;
|
|
65
67
|
}, {
|
|
66
68
|
themes: Record<string, {
|
|
@@ -74,6 +76,7 @@ export declare const configFileSchema: z.ZodObject<{
|
|
|
74
76
|
};
|
|
75
77
|
borderRadius: number;
|
|
76
78
|
}>;
|
|
79
|
+
clean?: boolean | undefined;
|
|
77
80
|
outDir?: string | undefined;
|
|
78
81
|
}>;
|
|
79
82
|
/**
|
|
@@ -82,6 +85,7 @@ export declare const configFileSchema: z.ZodObject<{
|
|
|
82
85
|
*/
|
|
83
86
|
export declare const combinedConfigSchema: z.ZodObject<{
|
|
84
87
|
outDir: z.ZodString;
|
|
88
|
+
clean: z.ZodBoolean;
|
|
85
89
|
themes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
86
90
|
colors: z.ZodObject<{
|
|
87
91
|
main: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodString, `#${string}` | `rgb(${number} ${number} ${number})` | `hsl(${number}deg ${number}% ${number}%)` | `hsv(${number}deg ${number}% ${number}%)` | `hsluv(${number} ${number} ${number})` | `lab(${number}% ${number} ${number})` | `lch(${number}% ${number} ${number}deg)` | `oklab(${number}% ${number} ${number})` | `oklch(${number}% ${number} ${number}deg)` | `jab(${number}% ${number} ${number})` | `jch(${number}% ${number} ${number}deg)`, string>>;
|
|
@@ -126,6 +130,7 @@ export declare const combinedConfigSchema: z.ZodObject<{
|
|
|
126
130
|
borderRadius: number;
|
|
127
131
|
}>>;
|
|
128
132
|
}, "strip", z.ZodTypeAny, {
|
|
133
|
+
clean: boolean;
|
|
129
134
|
themes: Record<string, {
|
|
130
135
|
colors: {
|
|
131
136
|
main: Record<string, `#${string}` | `rgb(${number} ${number} ${number})` | `hsl(${number}deg ${number}% ${number}%)` | `hsv(${number}deg ${number}% ${number}%)` | `hsluv(${number} ${number} ${number})` | `lab(${number}% ${number} ${number})` | `lch(${number}% ${number} ${number}deg)` | `oklab(${number}% ${number} ${number})` | `oklch(${number}% ${number} ${number}deg)` | `jab(${number}% ${number} ${number})` | `jch(${number}% ${number} ${number}deg)`>;
|
|
@@ -139,6 +144,7 @@ export declare const combinedConfigSchema: z.ZodObject<{
|
|
|
139
144
|
}>;
|
|
140
145
|
outDir: string;
|
|
141
146
|
}, {
|
|
147
|
+
clean: boolean;
|
|
142
148
|
themes: Record<string, {
|
|
143
149
|
colors: {
|
|
144
150
|
main: Record<string, string>;
|
package/dist/bin/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../bin/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,sBAQ5D;AAUD,eAAO,MAAM,UAAU,QAA2C,CAAC;AA6BnE;;GAEG;AACH,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../bin/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,sBAQ5D;AAUD,eAAO,MAAM,UAAU,QAA2C,CAAC;AA6BnE;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAO3B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAA8B,CAAC;AAChE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as R from "ramda";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { convertToHex } from "../src/colors/index.js";
|
|
4
|
+
import { cliOptions } from "../src/tokens/create.js";
|
|
5
|
+
function mapPathToOptionName(path) {
|
|
6
|
+
const normalisedPath = path[0] === "themes" ? ["theme", ...R.drop(2, path)] : path;
|
|
7
|
+
const option = R.path(normalisedPath, cliOptions);
|
|
8
|
+
if (typeof option !== "string") {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
return option;
|
|
12
|
+
}
|
|
13
|
+
const hexPatterns = [
|
|
14
|
+
// Hex colors: #000, #0000, #000000, #00000000
|
|
15
|
+
`#[0-9a-fA-F]{3}`,
|
|
16
|
+
`#[0-9a-fA-F]{4}`,
|
|
17
|
+
`#[0-9a-fA-F]{6}`,
|
|
18
|
+
`#[0-9a-fA-F]{8}`
|
|
19
|
+
];
|
|
20
|
+
const colorRegex = new RegExp(`^${hexPatterns.join("|")}$`);
|
|
21
|
+
const colorSchema = z.string({ description: "A hex color, which is used for creating a color scale" }).regex(colorRegex).transform(convertToHex);
|
|
22
|
+
const colorCategorySchema = z.record(colorSchema, { description: "One or more color definitions" });
|
|
23
|
+
const themeSchema = z.object(
|
|
24
|
+
{
|
|
25
|
+
colors: z.object(
|
|
26
|
+
{
|
|
27
|
+
main: colorCategorySchema,
|
|
28
|
+
support: colorCategorySchema,
|
|
29
|
+
neutral: colorSchema
|
|
30
|
+
},
|
|
31
|
+
{ description: "Defines the colors for this theme" }
|
|
32
|
+
),
|
|
33
|
+
typography: z.object(
|
|
34
|
+
{
|
|
35
|
+
fontFamily: z.string({ description: "Sets the font-family for this theme" })
|
|
36
|
+
},
|
|
37
|
+
{ description: "Defines the typography for a given theme" }
|
|
38
|
+
),
|
|
39
|
+
borderRadius: z.number({ description: "Defines the border-radius for this theme" })
|
|
40
|
+
},
|
|
41
|
+
{ description: "An object defining a theme. The property name holding the object becomes the theme name." }
|
|
42
|
+
);
|
|
43
|
+
const configFileSchema = z.object({
|
|
44
|
+
outDir: z.string({ description: "Path to the output directory for the created design tokens" }).optional(),
|
|
45
|
+
clean: z.boolean({ description: "Delete the output directory before building or creating tokens" }).optional(),
|
|
46
|
+
themes: z.record(themeSchema, {
|
|
47
|
+
description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
const combinedConfigSchema = configFileSchema.required();
|
|
51
|
+
export {
|
|
52
|
+
colorRegex,
|
|
53
|
+
combinedConfigSchema,
|
|
54
|
+
configFileSchema,
|
|
55
|
+
mapPathToOptionName
|
|
56
|
+
};
|
|
@@ -15,27 +15,30 @@ import { getDefaultOrExplicitOption, getExplicitOptionOnly } from "./options.js"
|
|
|
15
15
|
program.name("designsystemet").description("CLI for working with Designsystemet").showHelpAfterError();
|
|
16
16
|
function makeTokenCommands() {
|
|
17
17
|
const tokenCmd = createCommand("tokens");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
18
|
+
const DEFAULT_TOKENS_CREATE_DIR = "./design-tokens";
|
|
19
|
+
const DEFAULT_TOKENS_BUILD_DIR = "./design-tokens-build";
|
|
20
20
|
const DEFAULT_FONT = "Inter";
|
|
21
21
|
const DEFAULT_THEME_NAME = "theme";
|
|
22
22
|
const DEFAULT_CONFIG_FILE = "designsystemet.config.json";
|
|
23
|
-
tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${chalk.blue("design-tokens")}`,
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${chalk.blue("design-tokens")}`, DEFAULT_TOKENS_CREATE_DIR).option(
|
|
24
|
+
"-o, --out-dir <string>",
|
|
25
|
+
`Output directory for built ${chalk.blue("design-tokens")}`,
|
|
26
|
+
DEFAULT_TOKENS_BUILD_DIR
|
|
27
|
+
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before building tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for built ${chalk.blue("design-tokens")}`, parseBoolean, false).option("-p, --preview", "Generate preview token.ts files", false).option("--verbose", "Enable verbose output", false).action((opts) => {
|
|
28
|
+
const { preview, verbose, clean, dry } = opts;
|
|
29
|
+
const tokens = typeof opts.tokens === "string" ? opts.tokens : DEFAULT_TOKENS_CREATE_DIR;
|
|
26
30
|
const outDir = typeof opts.outDir === "string" ? opts.outDir : "./dist/tokens";
|
|
27
|
-
const dry = Boolean(opts.dry);
|
|
28
31
|
console.log(`Building tokens in ${chalk.green(tokens)}`);
|
|
29
32
|
if (dry) {
|
|
30
33
|
console.log(`Performing dry run, no files will be written`);
|
|
31
34
|
}
|
|
32
|
-
return buildTokens({ tokens, outDir, preview, verbose, dry });
|
|
35
|
+
return buildTokens({ tokens, outDir, preview, verbose, dry, clean });
|
|
33
36
|
});
|
|
34
37
|
tokenCmd.command("create").description("Create Designsystemet tokens").option(`-m, --${cliOptions.theme.colors.main} <name:hex...>`, `Main colors`, parseColorValues).option(`-s, --${cliOptions.theme.colors.support} <name:hex...>`, `Support colors`, parseColorValues).option(`-n, --${cliOptions.theme.colors.neutral} <hex>`, `Neutral hex color`, convertToHex).option(
|
|
35
38
|
`-o, --${cliOptions.outDir} <string>`,
|
|
36
39
|
`Output directory for created ${chalk.blue("design-tokens")}`,
|
|
37
|
-
|
|
38
|
-
).option("--dry [boolean]", `Dry run for created ${chalk.blue("design-tokens")}`, false).option(`-f, --${cliOptions.theme.typography.fontFamily} <string>`, `Font family`, DEFAULT_FONT).option(
|
|
40
|
+
DEFAULT_TOKENS_CREATE_DIR
|
|
41
|
+
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${chalk.blue("design-tokens")}`, parseBoolean, false).option(`-f, --${cliOptions.theme.typography.fontFamily} <string>`, `Font family`, DEFAULT_FONT).option(
|
|
39
42
|
`-b, --${cliOptions.theme.borderRadius} <number>`,
|
|
40
43
|
`Unitless base border-radius in px`,
|
|
41
44
|
(radiusAsString) => Number(radiusAsString),
|
|
@@ -45,8 +48,7 @@ function makeTokenCommands() {
|
|
|
45
48
|
`Path to JSON config file (default: "${DEFAULT_CONFIG_FILE}")`,
|
|
46
49
|
(value) => parseJsonConfig(value, { allowFileNotFound: false })
|
|
47
50
|
).action(async (opts, cmd) => {
|
|
48
|
-
|
|
49
|
-
if (dry) {
|
|
51
|
+
if (opts.dry) {
|
|
50
52
|
console.log(`Performing dry run, no files will be written`);
|
|
51
53
|
}
|
|
52
54
|
const configFile = await (opts.json ? opts.json : parseJsonConfig(DEFAULT_CONFIG_FILE, { allowFileNotFound: true }));
|
|
@@ -84,6 +86,7 @@ function makeTokenCommands() {
|
|
|
84
86
|
});
|
|
85
87
|
const unvalidatedConfig = noUndefined({
|
|
86
88
|
outDir: propsFromJson?.outDir ?? getDefaultOrExplicitOption(cmd, "outDir"),
|
|
89
|
+
clean: propsFromJson?.clean ?? getDefaultOrExplicitOption(cmd, "clean"),
|
|
87
90
|
themes: propsFromJson?.themes ? (
|
|
88
91
|
// For each theme specified in the JSON config, we override the config values
|
|
89
92
|
// with the explicitly set options from the CLI.
|
|
@@ -109,7 +112,7 @@ function makeTokenCommands() {
|
|
|
109
112
|
for (const [name, themeWithoutName] of Object.entries(config.themes)) {
|
|
110
113
|
const theme = { name, ...themeWithoutName };
|
|
111
114
|
const tokens = createTokens(theme);
|
|
112
|
-
await writeTokens({ outDir: config.outDir, tokens, theme, dry });
|
|
115
|
+
await writeTokens({ outDir: config.outDir, tokens, theme, dry: opts.dry, clean: config.clean });
|
|
113
116
|
}
|
|
114
117
|
});
|
|
115
118
|
return tokenCmd;
|
|
@@ -139,6 +142,7 @@ async function parseJsonConfig(jsonPath, options) {
|
|
|
139
142
|
let jsonFile;
|
|
140
143
|
try {
|
|
141
144
|
jsonFile = await fs.readFile(resolvedPath, { encoding: "utf-8" });
|
|
145
|
+
console.log(`Found JSON config file: ${chalk.green(resolvedPath)}`);
|
|
142
146
|
} catch (err) {
|
|
143
147
|
if (err instanceof Error) {
|
|
144
148
|
const nodeErr = err;
|
|
@@ -177,3 +181,6 @@ function parseColorValues(value, previous = {}) {
|
|
|
177
181
|
previous[name] = convertToHex(hex);
|
|
178
182
|
return previous;
|
|
179
183
|
}
|
|
184
|
+
function parseBoolean(value, previous) {
|
|
185
|
+
return value === "true" || value === true;
|
|
186
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const getOptionIfMatchingSource = (...sources) => (command, option) => {
|
|
2
|
+
const source = command.getOptionValueSource(option);
|
|
3
|
+
if (sources.includes(source)) {
|
|
4
|
+
return command.getOptionValue(option);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
const getExplicitOptionOnly = getOptionIfMatchingSource("cli");
|
|
8
|
+
const getDefaultOrExplicitOption = getOptionIfMatchingSource("cli", "default");
|
|
9
|
+
export {
|
|
10
|
+
getDefaultOrExplicitOption,
|
|
11
|
+
getExplicitOptionOnly
|
|
12
|
+
};
|
package/dist/config.schema.json
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"type": "string",
|
|
9
9
|
"description": "Path to the output directory for the created design tokens"
|
|
10
10
|
},
|
|
11
|
+
"clean": {
|
|
12
|
+
"type": "boolean",
|
|
13
|
+
"description": "Delete the output directory before building or creating tokens"
|
|
14
|
+
},
|
|
11
15
|
"themes": {
|
|
12
16
|
"type": "object",
|
|
13
17
|
"additionalProperties": {
|
|
@@ -10,8 +10,10 @@ type Options = {
|
|
|
10
10
|
verbose: boolean;
|
|
11
11
|
/** Set the default "accent" color, if not overridden with data-color */
|
|
12
12
|
accentColor?: string;
|
|
13
|
-
/** Dry run */
|
|
13
|
+
/** Dry run, no files will be written */
|
|
14
14
|
dry?: boolean;
|
|
15
|
+
/** Clean the output path before building tokens */
|
|
16
|
+
clean?: boolean;
|
|
15
17
|
};
|
|
16
18
|
export declare let buildOptions: Options | undefined;
|
|
17
19
|
export declare function buildTokens(options: Options): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/tokens/build.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,KAAK,OAAO,GAAG;IACb,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/tokens/build.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,KAAK,OAAO,GAAG;IACb,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,mDAAmD;IACnD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,eAAO,IAAI,YAAY,EAAE,OAAO,GAAG,SAAS,CAAC;AAwC7C,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqFjE"}
|
package/dist/src/tokens/build.js
CHANGED
|
@@ -7,7 +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
|
+
import { cleanDir, copyFile, writeFile } from "./utils.js";
|
|
11
11
|
const DEFAULT_COLOR = "accent";
|
|
12
12
|
let buildOptions;
|
|
13
13
|
const sd = new StyleDictionary();
|
|
@@ -42,7 +42,7 @@ const buildConfigs = {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
async function buildTokens(options) {
|
|
45
|
-
const { dry } = options;
|
|
45
|
+
const { dry, clean } = options;
|
|
46
46
|
const tokensDir = options.tokens;
|
|
47
47
|
const targetDir = path.resolve(options.outDir);
|
|
48
48
|
buildOptions = options;
|
|
@@ -66,6 +66,9 @@ async function buildTokens(options) {
|
|
|
66
66
|
}),
|
|
67
67
|
buildConfigs
|
|
68
68
|
);
|
|
69
|
+
if (clean) {
|
|
70
|
+
await cleanDir(targetDir, dry);
|
|
71
|
+
}
|
|
69
72
|
try {
|
|
70
73
|
for (const [key, { buildConfig, sdConfigs }] of R.toPairs(buildAndSdConfigs)) {
|
|
71
74
|
if (!(buildConfig.enabled?.() ?? true)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,EAAqC,MAAM,YAAY,CAAC;AAE3F,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,EAAqC,MAAM,YAAY,CAAC;AAE3F,eAAO,MAAM,UAAU;;;;;;;;;;;;;;CAcb,CAAC;AAgFX,eAAO,MAAM,YAAY,SAAU,KAAK,WAqBvC,CAAC"}
|
|
@@ -30,4 +30,5 @@ export declare const writeFile: (path: string, data: string, dry?: boolean) => P
|
|
|
30
30
|
export declare const cp: (src: string, dest: string, dry?: boolean) => Promise<void>;
|
|
31
31
|
export declare const copyFile: (src: string, dest: string, dry?: boolean) => Promise<void>;
|
|
32
32
|
export declare const isDigit: (s: string) => boolean;
|
|
33
|
+
export declare const cleanDir: (dir: string, dry?: boolean) => Promise<void>;
|
|
33
34
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +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,4DAAmB,MAAM,EAAE,GAAG,MAAM,SAAS,gBAAgB,aAMlF,CAAC;AAEH,eAAO,MAAM,mBAAmB,4DAAmB,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;AAEF,eAAO,MAAM,OAAO,MAAO,MAAM,YAAoB,CAAC"}
|
|
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,4DAAmB,MAAM,EAAE,GAAG,MAAM,SAAS,gBAAgB,aAMlF,CAAC;AAEH,eAAO,MAAM,mBAAmB,4DAAmB,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;AAEF,eAAO,MAAM,OAAO,MAAO,MAAM,YAAoB,CAAC;AAEtD,eAAO,MAAM,QAAQ,QAAe,MAAM,QAAQ,OAAO,kBASxD,CAAC"}
|
package/dist/src/tokens/utils.js
CHANGED
|
@@ -60,7 +60,16 @@ const copyFile = async (src, dest, dry) => {
|
|
|
60
60
|
return await fs.copyFile(src, dest);
|
|
61
61
|
};
|
|
62
62
|
const isDigit = (s) => /^\d+$/.test(s);
|
|
63
|
+
const cleanDir = async (dir, dry) => {
|
|
64
|
+
if (dry) {
|
|
65
|
+
console.log(`${chalk.blue("cleanDir")} ${dir}`);
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
console.log(`${chalk.red("Cleaning outputDir: ")} ${dir}`);
|
|
69
|
+
return await fs.rm(dir, { recursive: true, force: true });
|
|
70
|
+
};
|
|
63
71
|
export {
|
|
72
|
+
cleanDir,
|
|
64
73
|
copyFile,
|
|
65
74
|
cp,
|
|
66
75
|
getType,
|
|
@@ -4,7 +4,10 @@ type WriteTokensOptions = {
|
|
|
4
4
|
outDir: string;
|
|
5
5
|
tokens: Tokens;
|
|
6
6
|
theme: Theme;
|
|
7
|
+
/** Dry run, no files will be written */
|
|
7
8
|
dry?: boolean;
|
|
9
|
+
/** Clean output directory before writing tokens */
|
|
10
|
+
clean?: boolean;
|
|
8
11
|
};
|
|
9
12
|
export declare const writeTokens: (options: WriteTokensOptions) => Promise<void>;
|
|
10
13
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,EAA8B,MAAM,YAAY,CAAC;AAS9F,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,EAA8B,MAAM,YAAY,CAAC;AAS9F,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,mDAAmD;IACnD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,WAAW,YAAmB,kBAAkB,kBAiL5D,CAAC"}
|
package/dist/src/tokens/write.js
CHANGED
|
@@ -7,7 +7,7 @@ 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
|
+
import { cleanDir, cp, mkdir, writeFile } from "./utils.js";
|
|
11
11
|
import { generateMetadataJson } from "./write/generate$metadata.js";
|
|
12
12
|
import { generateThemesJson } from "./write/generate$themes.js";
|
|
13
13
|
const DIRNAME = import.meta.dirname || __dirname;
|
|
@@ -35,12 +35,16 @@ const writeTokens = async (options) => {
|
|
|
35
35
|
outDir,
|
|
36
36
|
tokens,
|
|
37
37
|
theme: { name: themeName, colors, borderRadius },
|
|
38
|
-
dry
|
|
38
|
+
dry,
|
|
39
|
+
clean
|
|
39
40
|
} = options;
|
|
40
41
|
const targetDir = path.resolve(process.cwd(), String(outDir));
|
|
41
42
|
const $themesPath = path.join(targetDir, "$themes.json");
|
|
42
43
|
const $metadataPath = path.join(targetDir, "$metadata.json");
|
|
43
44
|
let themes = [themeName];
|
|
45
|
+
if (clean) {
|
|
46
|
+
await cleanDir(targetDir, dry);
|
|
47
|
+
}
|
|
44
48
|
await mkdir(targetDir, dry);
|
|
45
49
|
try {
|
|
46
50
|
const $themes = await fs.readFile($themesPath, "utf-8");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digdir/designsystemet",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.47",
|
|
4
4
|
"description": "CLI for Designsystemet",
|
|
5
5
|
"author": "Designsystemet team",
|
|
6
6
|
"engines": {
|
|
@@ -34,26 +34,23 @@
|
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"designsystemet": "tsx ./bin/designsystemet.ts",
|
|
37
|
-
"build:tokens": "yarn
|
|
38
|
-
"build:tokens:debug": "
|
|
37
|
+
"build:tokens": "yarn designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
|
|
38
|
+
"build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
|
|
39
39
|
"build": "tsup && yarn build:types && yarn build:json-schema",
|
|
40
40
|
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
41
41
|
"build:json-schema": "tsx ./src/build-scripts/createJsonSchema.ts",
|
|
42
42
|
"types": "tsc --noEmit",
|
|
43
|
-
"test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 complimentary:#ff0000 -n #003333 -s support1:#12404f support2:#0054a6 support3:#942977 -b 99 -o ./test-tokens-create",
|
|
43
|
+
"test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 complimentary:#ff0000 -n #003333 -s support1:#12404f support2:#0054a6 support3:#942977 -b 99 -o ./test-tokens-create --clean",
|
|
44
44
|
"test:tokens-create-json": "yarn designsystemet tokens create --json ./test-tokens-create-complex.config.json",
|
|
45
|
-
"test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens-create -o ./test-tokens-build",
|
|
46
|
-
"test:tokens-create-and-build-options": "yarn
|
|
47
|
-
"test:tokens-create-and-build-json": "yarn
|
|
45
|
+
"test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens-create -o ./test-tokens-build --clean",
|
|
46
|
+
"test:tokens-create-and-build-options": "yarn test:tokens-create-options && yarn test:tokens-build",
|
|
47
|
+
"test:tokens-create-and-build-json": "yarn test:tokens-create-json && yarn test:tokens-build",
|
|
48
48
|
"test": "yarn test:tokens-create-and-build-options && yarn test:tokens-create-and-build-json",
|
|
49
|
-
"clean": "rimraf dist",
|
|
50
|
-
"clean:test-tokens": "rimraf test-tokens-create && rimraf test-tokens-build",
|
|
51
|
-
"clean:theme": "yarn workspace @digdir/designsystemet-theme clean",
|
|
52
49
|
"update:template": "tsx ./src/tokens/template.ts",
|
|
53
|
-
"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",
|
|
54
|
-
"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",
|
|
55
|
-
"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",
|
|
56
|
-
"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-digdir": "yarn designsystemet tokens create --theme theme -m accent:#0062BA -n #1E2B3C -s brand1:#F45F63 brand2:#E5AA20 brand3:#1E98F5 -o ./internal/design-tokens --clean",
|
|
51
|
+
"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 --clean",
|
|
52
|
+
"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 --clean",
|
|
53
|
+
"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 --clean",
|
|
57
54
|
"internal:tokens-create-all": "yarn internal:tokens-create-digdir && yarn internal:tokens-create-altinn && yarn internal:tokens-create-uutilsynet && yarn internal:tokens-create-portal"
|
|
58
55
|
},
|
|
59
56
|
"dependencies": {
|
|
@@ -71,7 +68,6 @@
|
|
|
71
68
|
"postcss": "^8.4.41",
|
|
72
69
|
"prompts": "^2.4.2",
|
|
73
70
|
"ramda": "^0.30.1",
|
|
74
|
-
"rimraf": "^6.0.1",
|
|
75
71
|
"style-dictionary": "^4.0.1",
|
|
76
72
|
"zod": "^3.23.8",
|
|
77
73
|
"zod-validation-error": "^3.4.0"
|