@digdir/designsystemet 1.0.4 → 1.0.5

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.
@@ -984,7 +984,7 @@ var buildConfigs = {
984
984
  // },
985
985
  };
986
986
  async function processPlatform(options) {
987
- const { dry, process, $themes } = options;
987
+ const { process, $themes } = options;
988
988
  const platform = "css";
989
989
  const tokenSets = process === "format" ? options.tokenSets : void 0;
990
990
  const tokensDir = process === "build" ? options.tokensDir : void 0;
@@ -0,0 +1,27 @@
1
+ import type { OutputFile } from '../types.js';
2
+ import type { ProcessReturn } from './platform.js';
3
+ export declare const defaultFileHeader: string;
4
+ type CreateThemeCSSFiles = {
5
+ /** The processed build results containing formatted CSS outputs grouped by themes and other permutations. */
6
+ processedBuilds: ProcessReturn;
7
+ /** Optional header to be included in the generated CSS files. */
8
+ fileHeader?: string;
9
+ };
10
+ /**
11
+ * Generates theme-specific CSS files from Style Dictionary build results.
12
+ *
13
+ * @param processedBuilds - The processed build results containing formatted CSS outputs
14
+ * grouped by themes and other permutations.
15
+ * @param fileHeader - Optional header to be included in the generated CSS files.
16
+ * @returns An array of `OutputFile` objects, each representing a theme-specific CSS file
17
+ * with its destination and content.
18
+ *
19
+ * @remarks
20
+ * - The function groups the build results by theme and ensures a deterministic order
21
+ * for the sections of the entry CSS file using a predefined sort order.
22
+ * - If a CSS section does not have a defined sort order the section is added to the end of the entry file.
23
+ * - The generated CSS files include a header with metadata and layer definitions.
24
+ */
25
+ export declare const createThemeCSSFiles: ({ processedBuilds, fileHeader, }: CreateThemeCSSFiles) => OutputFile[];
26
+ export {};
27
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../src/tokens/process/theme.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,eAAO,MAAM,iBAAiB,QAA2B,CAAC;AAE1D,KAAK,mBAAmB,GAAG;IACzB,6GAA6G;IAC7G,eAAe,EAAE,aAAa,CAAC;IAC/B,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,kCAGjC,mBAAmB,KAAG,UAAU,EAiFlC,CAAC"}
@@ -0,0 +1,172 @@
1
+ // src/tokens/process/theme.ts
2
+ import * as R from "ramda";
3
+ import chalk from "chalk";
4
+
5
+ // package.json
6
+ var package_default = {
7
+ name: "@digdir/designsystemet",
8
+ version: "1.0.5",
9
+ description: "CLI for Designsystemet",
10
+ author: "Designsystemet team",
11
+ engines: {
12
+ node: ">=22.14.0"
13
+ },
14
+ repository: {
15
+ type: "git",
16
+ url: "git+https://github.com/digdir/designsystemet.git"
17
+ },
18
+ homepage: "https://github.com/digdir/designsystemet/tree/main/scripts/cli",
19
+ license: "MIT",
20
+ type: "module",
21
+ main: "./dist/src/index.js",
22
+ files: [
23
+ "./dist/**"
24
+ ],
25
+ bin: "dist/bin/designsystemet.js",
26
+ exports: {
27
+ ".": {
28
+ import: "./dist/src/index.js"
29
+ },
30
+ "./color": {
31
+ import: "./dist/src/colors/index.js"
32
+ },
33
+ "./tokens": {
34
+ import: "./dist/src/tokens/index.js"
35
+ }
36
+ },
37
+ publishConfig: {
38
+ access: "public"
39
+ },
40
+ scripts: {
41
+ designsystemet: "tsx ./bin/designsystemet.ts",
42
+ "build:tokens": "yarn designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
43
+ "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
44
+ build: "tsup && yarn build:types && yarn build:json-schema",
45
+ "build:types": "tsc --emitDeclarationOnly --declaration",
46
+ "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
47
+ types: "tsc --noEmit",
48
+ "test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 -n #003333 -b 99 -o ./test-tokens/options --theme options --clean",
49
+ "test:tokens-create-config": "yarn designsystemet tokens create --config ./test/test-tokens.config.json",
50
+ "test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens/options -o ./test-tokens/options-build --clean",
51
+ "test:tokens-build-config": "yarn designsystemet tokens build -t ./test-tokens/config -o ./test-tokens/config-build --clean",
52
+ "test:tokens-create-and-build-options": "yarn test:tokens-create-options && yarn test:tokens-build",
53
+ "test:tokens-create-and-build-config": "yarn test:tokens-create-config && yarn test:tokens-build-config",
54
+ test: "yarn test:tokens-create-and-build-options && yarn test:tokens-create-and-build-config",
55
+ "internal:tokens-create": "yarn designsystemet tokens create --config ./internal.config.json",
56
+ "update:template": "tsx ./src/scripts/update-template.ts",
57
+ "update:design-tokens": "yarn internal:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
58
+ verify: "yarn test && yarn update:template && yarn update:design-tokens"
59
+ },
60
+ dependencies: {
61
+ "@commander-js/extra-typings": "^13.1.0",
62
+ "@tokens-studio/sd-transforms": "1.2.12",
63
+ "apca-w3": "^0.1.9",
64
+ chalk: "^5.4.1",
65
+ "change-case": "^5.4.4",
66
+ "chroma-js": "^3.1.2",
67
+ commander: "^13.1.0",
68
+ "fast-glob": "^3.3.3",
69
+ hsluv: "^1.0.1",
70
+ "object-hash": "^3.0.0",
71
+ postcss: "^8.5.3",
72
+ ramda: "^0.30.1",
73
+ "style-dictionary": "^4.3.3",
74
+ zod: "^3.24.2",
75
+ "zod-validation-error": "^3.4.0"
76
+ },
77
+ devDependencies: {
78
+ "@types/apca-w3": "^0.1.3",
79
+ "@types/chroma-js": "^3.1.1",
80
+ "@types/fs-extra": "^11.0.4",
81
+ "@types/glob": "^8.1.0",
82
+ "@types/jscodeshift": "^0.12.0",
83
+ "@types/node": "^22.14.0",
84
+ "@types/object-hash": "^3.0.6",
85
+ "@types/ramda": "^0.30.2",
86
+ "fs-extra": "^11.3.0",
87
+ "ts-toolbelt": "^9.6.0",
88
+ tslib: "^2.8.1",
89
+ tsup: "^8.4.0",
90
+ tsx: "^4.19.3",
91
+ typescript: "^5.8.2",
92
+ "zod-to-json-schema": "^3.24.5"
93
+ }
94
+ };
95
+
96
+ // src/tokens/process/theme.ts
97
+ var defaultFileHeader = `build: v${package_default.version}`;
98
+ var createThemeCSSFiles = ({
99
+ processedBuilds,
100
+ fileHeader = defaultFileHeader
101
+ }) => {
102
+ const groupedByTheme = {};
103
+ for (const [_, buildResults] of Object.entries(R.dissoc("types", processedBuilds))) {
104
+ for (const buildResult of buildResults) {
105
+ const themeName = buildResult.permutation.theme;
106
+ const newOutputs = buildResult.formatted;
107
+ if (R.isNotEmpty(newOutputs)) {
108
+ const currentOutputs = groupedByTheme[themeName] ?? [];
109
+ groupedByTheme[themeName] = R.concat(currentOutputs, newOutputs);
110
+ }
111
+ }
112
+ }
113
+ const sortOrder = [
114
+ "color-scheme/light",
115
+ "typography/secondary",
116
+ "semantic",
117
+ "color-scheme/dark",
118
+ "color-scheme/contrast",
119
+ "typography/primary",
120
+ "color/"
121
+ ];
122
+ const sortByDefinedOrder = R.sortBy((file) => {
123
+ const filePath = file.destination || "";
124
+ const sortIndex = sortOrder.findIndex((sortElement) => {
125
+ if (sortElement.endsWith("/")) {
126
+ return filePath.includes(sortElement);
127
+ }
128
+ return filePath.includes(`${sortElement}.css`);
129
+ });
130
+ if (sortIndex === -1) {
131
+ console.error(
132
+ chalk.yellow("WARNING: CSS section does not have a defined sort order:", filePath.replace(".css", ""))
133
+ );
134
+ console.log(
135
+ chalk.dim(
136
+ `
137
+ The section will currently be added to the end of the entry file, but the exact
138
+ order may change due to nondeterminism.`.trim()
139
+ )
140
+ );
141
+ return Infinity;
142
+ }
143
+ return sortIndex;
144
+ });
145
+ const header = `@charset "UTF-8";
146
+
147
+ @layer ds.theme, ds.base, ds.utilities, ds.components;
148
+
149
+ /*
150
+ ${fileHeader}
151
+ */
152
+
153
+ `;
154
+ const sortAlphabetically = R.sort(R.ascend((x) => x.destination || ""));
155
+ const pickOutputs = R.map(R.view(R.lensProp("output")));
156
+ const themeCSSFile = R.pipe(
157
+ sortAlphabetically,
158
+ sortByDefinedOrder,
159
+ pickOutputs,
160
+ R.join("\n"),
161
+ (content) => header + content
162
+ );
163
+ const themeCSSFiles = Object.entries(groupedByTheme).map(([theme, files]) => ({
164
+ destination: `${theme}.css`,
165
+ output: themeCSSFile(files)
166
+ }));
167
+ return themeCSSFiles;
168
+ };
169
+ export {
170
+ createThemeCSSFiles,
171
+ defaultFileHeader
172
+ };
@@ -58,4 +58,8 @@ export type OutputFile = {
58
58
  output: string;
59
59
  destination: string | undefined;
60
60
  };
61
+ export type DesignsystemetObject = {
62
+ name: string;
63
+ version: string;
64
+ };
61
65
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tokens/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAE5E,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACjF,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE9C,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;AACrC,MAAM,MAAM,UAAU,GA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C;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC;AAEpD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,SAAS,EAAE,wBAAwB,CAAC;IACpC,0FAA0F;IAC1F,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC;IACxB,0BAA0B;IAC1B,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,2BAA2B,KAAK,MAAM,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IAAE,WAAW,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE9F,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "engines": {
@@ -40,11 +40,12 @@
40
40
  "build:types": "tsc --emitDeclarationOnly --declaration",
41
41
  "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
42
42
  "types": "tsc --noEmit",
43
- "test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 -n #003333 -b 99 -o ./test-tokens-create --theme options-test --clean",
44
- "test:tokens-create-config": "yarn designsystemet tokens create --config ./test-tokens-create-complex.config.json",
45
- "test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens-create -o ./test-tokens-build --clean",
43
+ "test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 -n #003333 -b 99 -o ./test-tokens/options --theme options --clean",
44
+ "test:tokens-create-config": "yarn designsystemet tokens create --config ./test/test-tokens.config.json",
45
+ "test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens/options -o ./test-tokens/options-build --clean",
46
+ "test:tokens-build-config": "yarn designsystemet tokens build -t ./test-tokens/config -o ./test-tokens/config-build --clean",
46
47
  "test:tokens-create-and-build-options": "yarn test:tokens-create-options && yarn test:tokens-build",
47
- "test:tokens-create-and-build-config": "yarn test:tokens-create-config && yarn test:tokens-build",
48
+ "test:tokens-create-and-build-config": "yarn test:tokens-create-config && yarn test:tokens-build-config",
48
49
  "test": "yarn test:tokens-create-and-build-options && yarn test:tokens-create-and-build-config",
49
50
  "internal:tokens-create": "yarn designsystemet tokens create --config ./internal.config.json",
50
51
  "update:template": "tsx ./src/scripts/update-template.ts",