@digdir/designsystemet 1.0.2 → 1.0.4
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 +4264 -45
- package/dist/bin/options.js +5 -4
- package/dist/src/colors/colorMetadata.d.ts.map +1 -1
- package/dist/src/colors/colorMetadata.js +84 -35
- package/dist/src/colors/index.js +470 -4
- package/dist/src/colors/theme.d.ts.map +1 -1
- package/dist/src/colors/theme.js +290 -18
- package/dist/src/colors/types.d.ts +4 -1
- package/dist/src/colors/types.d.ts.map +1 -1
- package/dist/src/colors/utils.js +16 -15
- package/dist/{bin → src}/config.d.ts +46 -1
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +377 -0
- package/dist/src/index.js +3666 -2
- package/dist/src/migrations/beta-to-v1.js +85 -4
- package/dist/src/migrations/codemods/css/plugins.js +5 -4
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
- package/dist/src/migrations/codemods/css/run.js +18 -4
- package/dist/src/migrations/color-rename-next49.js +77 -6
- package/dist/src/migrations/index.d.ts +0 -1
- package/dist/src/migrations/index.d.ts.map +1 -1
- package/dist/src/migrations/index.js +461 -6
- package/dist/src/scripts/createJsonSchema.js +1608 -4
- package/dist/src/scripts/update-design-tokens.d.ts +2 -0
- package/dist/src/scripts/update-design-tokens.d.ts.map +1 -0
- package/dist/src/scripts/update-design-tokens.js +36 -0
- package/dist/src/{tokens/template.d.ts → scripts/update-template.d.ts} +1 -1
- package/dist/src/scripts/update-template.d.ts.map +1 -0
- package/dist/src/scripts/update-template.js +1200 -0
- package/dist/src/tokens/build.d.ts +2 -19
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +1511 -70
- package/dist/src/tokens/create/defaults.d.ts +7 -0
- package/dist/src/tokens/create/defaults.d.ts.map +1 -0
- package/dist/src/tokens/create/defaults.js +994 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.js +100 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
- package/dist/src/tokens/{write/generate$metadata.js → create/generators/$metadata.js} +3 -2
- package/dist/src/tokens/create/generators/$themes.d.ts +12 -0
- package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$themes.js +333 -0
- package/dist/src/tokens/create/generators/color.d.ts +5 -0
- package/dist/src/tokens/create/generators/color.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/color.js +374 -0
- package/dist/src/tokens/create/generators/semantic.d.ts +296 -0
- package/dist/src/tokens/create/generators/semantic.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic.js +483 -0
- package/dist/src/tokens/create/generators/theme.d.ts +3 -0
- package/dist/src/tokens/create/generators/theme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/theme.js +168 -0
- package/dist/src/tokens/create/generators/typography.d.ts +3 -0
- package/dist/src/tokens/create/generators/typography.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/typography.js +33 -0
- package/dist/src/tokens/{write.d.ts → create/write.d.ts} +2 -2
- package/dist/src/tokens/create/write.d.ts.map +1 -0
- package/dist/src/tokens/create/write.js +546 -0
- package/dist/src/tokens/create.d.ts +4 -2
- package/dist/src/tokens/create.d.ts.map +1 -1
- package/dist/src/tokens/create.js +2049 -59
- package/dist/src/tokens/format.d.ts +16 -0
- package/dist/src/tokens/format.d.ts.map +1 -0
- package/dist/src/tokens/format.js +3514 -0
- package/dist/src/tokens/index.d.ts +1 -0
- package/dist/src/tokens/index.d.ts.map +1 -1
- package/dist/src/tokens/index.js +3526 -2
- package/dist/src/tokens/process/configs/color.d.ts +12 -0
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/color.js +823 -0
- package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/semantic.js +367 -0
- package/dist/src/tokens/process/configs/shared.d.ts +10 -0
- package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/shared.js +99 -0
- package/dist/src/tokens/process/configs/storefront.d.ts +3 -0
- package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/storefront.js +220 -0
- package/dist/src/tokens/process/configs/typography.d.ts +3 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/typography.js +369 -0
- package/dist/src/tokens/{build → process}/configs.d.ts +3 -11
- package/dist/src/tokens/process/configs.d.ts.map +1 -0
- package/dist/src/tokens/process/configs.js +976 -0
- package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/color.js +128 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts +17 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.js +109 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.js +32 -0
- package/dist/src/tokens/process/formats/css.d.ts +8 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/{build → process}/formats/css.js +94 -57
- package/dist/src/tokens/process/formats/js-tokens.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/js-tokens.js +109 -0
- package/dist/src/tokens/process/platform.d.ts +87 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -0
- package/dist/src/tokens/process/platform.js +1090 -0
- package/dist/src/tokens/process/transformers.d.ts.map +1 -0
- package/dist/src/tokens/{build → process}/transformers.js +29 -6
- package/dist/src/tokens/{build → process}/utils/getMultidimensionalThemes.d.ts +3 -3
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +922 -0
- package/dist/src/tokens/template/design-tokens/primitives/globals.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/large.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/medium.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/small.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/large.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/medium.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/small.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/typography.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/color.base.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/color.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/modes/color.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/style.js +5 -0
- package/dist/src/tokens/template/design-tokens/themes/theme.base.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/themes/theme.template.js +5 -0
- package/dist/src/tokens/types.d.ts +54 -38
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/tokens/types.js +8 -0
- package/dist/src/tokens/utils.d.ts +30 -5
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/dist/src/tokens/utils.js +36 -50
- package/dist/src/utils.d.ts +18 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +63 -0
- package/dist/typography.template-4N5YLH7F.json +22 -0
- package/package.json +17 -16
- package/dist/bin/config.d.ts.map +0 -1
- package/dist/bin/config.js +0 -71
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
- package/dist/src/migrations/codemods/jsx/classname-prefix.js +0 -64
- package/dist/src/migrations/codemods/jsx/run.d.ts +0 -7
- package/dist/src/migrations/codemods/jsx/run.d.ts.map +0 -1
- package/dist/src/migrations/codemods/jsx/run.js +0 -22
- package/dist/src/migrations/react-beta-to-v1.d.ts +0 -3
- package/dist/src/migrations/react-beta-to-v1.d.ts.map +0 -1
- package/dist/src/migrations/react-beta-to-v1.js +0 -5
- package/dist/src/scripts/copy-internal-tokens.d.ts +0 -2
- package/dist/src/scripts/copy-internal-tokens.d.ts.map +0 -1
- package/dist/src/scripts/copy-internal-tokens.js +0 -28
- package/dist/src/tokens/build/configs.d.ts.map +0 -1
- package/dist/src/tokens/build/configs.js +0 -280
- package/dist/src/tokens/build/formats/css.d.ts +0 -53
- package/dist/src/tokens/build/formats/css.d.ts.map +0 -1
- package/dist/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
- package/dist/src/tokens/build/formats/js-tokens.js +0 -48
- package/dist/src/tokens/build/transformers.d.ts.map +0 -1
- package/dist/src/tokens/build/types.d.ts +0 -48
- package/dist/src/tokens/build/types.d.ts.map +0 -1
- package/dist/src/tokens/build/types.js +0 -7
- package/dist/src/tokens/build/utils/entryfile.d.ts +0 -12
- package/dist/src/tokens/build/utils/entryfile.d.ts.map +0 -1
- package/dist/src/tokens/build/utils/entryfile.js +0 -67
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +0 -1
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +0 -112
- package/dist/src/tokens/design-tokens/template/$metadata.json +0 -25
- package/dist/src/tokens/design-tokens/template/$themes.json +0 -1498
- package/dist/src/tokens/template.d.ts.map +0 -1
- package/dist/src/tokens/template.js +0 -99
- package/dist/src/tokens/write/generate$metadata.d.ts +0 -9
- package/dist/src/tokens/write/generate$metadata.d.ts.map +0 -1
- package/dist/src/tokens/write/generate$themes.d.ts +0 -12
- package/dist/src/tokens/write/generate$themes.d.ts.map +0 -1
- package/dist/src/tokens/write/generate$themes.js +0 -161
- package/dist/src/tokens/write.d.ts.map +0 -1
- package/dist/src/tokens/write.js +0 -177
- /package/dist/{src/tokens/design-tokens/template/semantic/color-base-file.json → color.base.template-M7BHS4OV.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json → color.template-LMPUQ72A.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/semantic/semantic-color-template.json → color.template-XQNSHLTU.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/global.json → global-XVXVBKM6.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/globals.json → globals-76VAFMDF.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/large.json → large-CIIHO7AY.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/large.json → large-UUOZ6DYI.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/medium.json → medium-OQ7S7P4P.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json → medium-VSB2S4X3.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/small.json → small-AEXJ6U7Z.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/small.json → small-ZY4KOJWX.json} +0 -0
- /package/dist/src/tokens/{build → process}/formats/js-tokens.d.ts +0 -0
- /package/dist/src/tokens/{build → process}/transformers.d.ts +0 -0
- /package/dist/{src/tokens/design-tokens/default/semantic/style.json → style-FP5XVCUD.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/themes/theme-base-file.json → theme.base.template-Y4RMFBQY.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/themes/theme-color-template.json → theme.template-CTQRNOMO.json} +0 -0
|
@@ -1,7 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/migrations/codemods/css/plugins.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import hash from "object-hash";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
var printDelete = (text) => console.log(`${chalk.red("Deleted:")} ${text}`.replace(/"|'/g, ""));
|
|
6
|
+
var deleteMsg = (decl, from) => `${chalk.yellow(from)} @ ${chalk.gray(`${JSON.stringify(decl.source?.input.file)}:${decl.source?.start?.line}:${decl.source?.start?.column}`)}`;
|
|
7
|
+
var cssClassRename = (dictionary) => ({
|
|
8
|
+
postcssPlugin: `Renames CSS classes ${hash(dictionary)}`,
|
|
9
|
+
Rule(rule) {
|
|
10
|
+
const selector = rule.selector;
|
|
11
|
+
if (!selector) return;
|
|
12
|
+
for (const [from, to] of Object.entries(dictionary)) {
|
|
13
|
+
if (!selector.includes(from)) return;
|
|
14
|
+
const newSelector = selector.replace(new RegExp(from, "g"), to);
|
|
15
|
+
rule.selector = newSelector;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var cssVarRename = (dictionary) => ({
|
|
20
|
+
postcssPlugin: `Replaces CSS variables ${hash(dictionary)}`,
|
|
21
|
+
Declaration(decl) {
|
|
22
|
+
const { value, prop } = decl;
|
|
23
|
+
const deleted = /* @__PURE__ */ new Set();
|
|
24
|
+
for (const [from, to] of Object.entries(dictionary)) {
|
|
25
|
+
if (R.isNotEmpty(to)) {
|
|
26
|
+
if (to === "[delete]") {
|
|
27
|
+
deleted.add(deleteMsg(decl, from));
|
|
28
|
+
}
|
|
29
|
+
if (R.includes(from, value)) {
|
|
30
|
+
decl.value = value.replace(from, to);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (R.includes(from, prop) && decl.variable) {
|
|
34
|
+
decl.prop = prop.replace(from, to);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (deleted.size > 0) {
|
|
39
|
+
Array.from(deleted).forEach(printDelete);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// src/migrations/codemods/css/run.ts
|
|
45
|
+
import fs2 from "node:fs";
|
|
46
|
+
import glob from "fast-glob";
|
|
47
|
+
import postcss from "postcss";
|
|
48
|
+
|
|
49
|
+
// src/utils.ts
|
|
50
|
+
import fs from "node:fs/promises";
|
|
51
|
+
import chalk2 from "chalk";
|
|
52
|
+
var readFile = async (path, dry) => {
|
|
53
|
+
if (dry) {
|
|
54
|
+
console.log(`${chalk2.blue("readFile")} ${path}`);
|
|
55
|
+
return Promise.resolve("");
|
|
56
|
+
}
|
|
57
|
+
return fs.readFile(path, "utf-8");
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/migrations/codemods/css/run.ts
|
|
61
|
+
var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
62
|
+
const processor = postcss(plugins);
|
|
63
|
+
const transform = async () => {
|
|
64
|
+
console.log(`Running migration in ${globPattern}`);
|
|
65
|
+
const files = await glob([globPattern], {
|
|
66
|
+
ignore: ["**/node_modules/**", "**/dist/**"],
|
|
67
|
+
// TODO: Not working as expected
|
|
68
|
+
absolute: true
|
|
69
|
+
});
|
|
70
|
+
const filePromises = files.map(async (file) => {
|
|
71
|
+
if (file.includes("node_modules") || file.includes("dist")) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const contents = readFile(file).toString();
|
|
75
|
+
const result = await processor.process(contents, { from: file });
|
|
76
|
+
fs2.writeFileSync(file, result.css);
|
|
77
|
+
});
|
|
78
|
+
await Promise.all(filePromises);
|
|
79
|
+
};
|
|
80
|
+
return transform();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/migrations/beta-to-v1.ts
|
|
84
|
+
var beta_to_v1_default = (glob2) => runCssCodemod({
|
|
85
|
+
globPattern: glob2,
|
|
5
86
|
plugins: [
|
|
6
87
|
cssClassRename({
|
|
7
88
|
".fds-": ".ds-"
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
// src/migrations/codemods/css/plugins.ts
|
|
1
2
|
import chalk from "chalk";
|
|
2
3
|
import hash from "object-hash";
|
|
3
4
|
import * as R from "ramda";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
var printDelete = (text) => console.log(`${chalk.red("Deleted:")} ${text}`.replace(/"|'/g, ""));
|
|
6
|
+
var deleteMsg = (decl, from) => `${chalk.yellow(from)} @ ${chalk.gray(`${JSON.stringify(decl.source?.input.file)}:${decl.source?.start?.line}:${decl.source?.start?.column}`)}`;
|
|
7
|
+
var cssClassRename = (dictionary) => ({
|
|
7
8
|
postcssPlugin: `Renames CSS classes ${hash(dictionary)}`,
|
|
8
9
|
Rule(rule) {
|
|
9
10
|
const selector = rule.selector;
|
|
@@ -15,7 +16,7 @@ const cssClassRename = (dictionary) => ({
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
+
var cssVarRename = (dictionary) => ({
|
|
19
20
|
postcssPlugin: `Replaces CSS variables ${hash(dictionary)}`,
|
|
20
21
|
Declaration(decl) {
|
|
21
22
|
const { value, prop } = decl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../../src/migrations/codemods/css/run.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../../src/migrations/codemods/css/run.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,0BAA8C,eAAe,kBA0BhG,CAAC"}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
// src/migrations/codemods/css/run.ts
|
|
2
|
+
import fs2 from "node:fs";
|
|
2
3
|
import glob from "fast-glob";
|
|
3
4
|
import postcss from "postcss";
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
// src/utils.ts
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
var readFile = async (path, dry) => {
|
|
10
|
+
if (dry) {
|
|
11
|
+
console.log(`${chalk.blue("readFile")} ${path}`);
|
|
12
|
+
return Promise.resolve("");
|
|
13
|
+
}
|
|
14
|
+
return fs.readFile(path, "utf-8");
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/migrations/codemods/css/run.ts
|
|
18
|
+
var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
5
19
|
const processor = postcss(plugins);
|
|
6
20
|
const transform = async () => {
|
|
7
21
|
console.log(`Running migration in ${globPattern}`);
|
|
@@ -14,9 +28,9 @@ const runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
|
14
28
|
if (file.includes("node_modules") || file.includes("dist")) {
|
|
15
29
|
return;
|
|
16
30
|
}
|
|
17
|
-
const contents =
|
|
31
|
+
const contents = readFile(file).toString();
|
|
18
32
|
const result = await processor.process(contents, { from: file });
|
|
19
|
-
|
|
33
|
+
fs2.writeFileSync(file, result.css);
|
|
20
34
|
});
|
|
21
35
|
await Promise.all(filePromises);
|
|
22
36
|
};
|
|
@@ -1,7 +1,78 @@
|
|
|
1
|
+
// src/migrations/color-rename-next49.ts
|
|
2
|
+
import * as R2 from "ramda";
|
|
3
|
+
|
|
4
|
+
// src/migrations/codemods/css/plugins.ts
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import hash from "object-hash";
|
|
1
7
|
import * as R from "ramda";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
8
|
+
var printDelete = (text) => console.log(`${chalk.red("Deleted:")} ${text}`.replace(/"|'/g, ""));
|
|
9
|
+
var deleteMsg = (decl, from) => `${chalk.yellow(from)} @ ${chalk.gray(`${JSON.stringify(decl.source?.input.file)}:${decl.source?.start?.line}:${decl.source?.start?.column}`)}`;
|
|
10
|
+
var cssVarRename = (dictionary) => ({
|
|
11
|
+
postcssPlugin: `Replaces CSS variables ${hash(dictionary)}`,
|
|
12
|
+
Declaration(decl) {
|
|
13
|
+
const { value, prop } = decl;
|
|
14
|
+
const deleted = /* @__PURE__ */ new Set();
|
|
15
|
+
for (const [from, to] of Object.entries(dictionary)) {
|
|
16
|
+
if (R.isNotEmpty(to)) {
|
|
17
|
+
if (to === "[delete]") {
|
|
18
|
+
deleted.add(deleteMsg(decl, from));
|
|
19
|
+
}
|
|
20
|
+
if (R.includes(from, value)) {
|
|
21
|
+
decl.value = value.replace(from, to);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (R.includes(from, prop) && decl.variable) {
|
|
25
|
+
decl.prop = prop.replace(from, to);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (deleted.size > 0) {
|
|
30
|
+
Array.from(deleted).forEach(printDelete);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// src/migrations/codemods/css/run.ts
|
|
36
|
+
import fs2 from "node:fs";
|
|
37
|
+
import glob from "fast-glob";
|
|
38
|
+
import postcss from "postcss";
|
|
39
|
+
|
|
40
|
+
// src/utils.ts
|
|
41
|
+
import fs from "node:fs/promises";
|
|
42
|
+
import chalk2 from "chalk";
|
|
43
|
+
var readFile = async (path, dry) => {
|
|
44
|
+
if (dry) {
|
|
45
|
+
console.log(`${chalk2.blue("readFile")} ${path}`);
|
|
46
|
+
return Promise.resolve("");
|
|
47
|
+
}
|
|
48
|
+
return fs.readFile(path, "utf-8");
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/migrations/codemods/css/run.ts
|
|
52
|
+
var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
53
|
+
const processor = postcss(plugins);
|
|
54
|
+
const transform = async () => {
|
|
55
|
+
console.log(`Running migration in ${globPattern}`);
|
|
56
|
+
const files = await glob([globPattern], {
|
|
57
|
+
ignore: ["**/node_modules/**", "**/dist/**"],
|
|
58
|
+
// TODO: Not working as expected
|
|
59
|
+
absolute: true
|
|
60
|
+
});
|
|
61
|
+
const filePromises = files.map(async (file) => {
|
|
62
|
+
if (file.includes("node_modules") || file.includes("dist")) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const contents = readFile(file).toString();
|
|
66
|
+
const result = await processor.process(contents, { from: file });
|
|
67
|
+
fs2.writeFileSync(file, result.css);
|
|
68
|
+
});
|
|
69
|
+
await Promise.all(filePromises);
|
|
70
|
+
};
|
|
71
|
+
return transform();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/migrations/color-rename-next49.ts
|
|
75
|
+
var replace = (oldTemplate, newTemplate, colors2, placeholder = "[color]") => R2.reduce(
|
|
5
76
|
(acc, color) => {
|
|
6
77
|
acc[oldTemplate.replace(placeholder, color)] = newTemplate.replace(placeholder, color);
|
|
7
78
|
return acc;
|
|
@@ -9,8 +80,8 @@ const replace = (oldTemplate, newTemplate, colors2, placeholder = "[color]") =>
|
|
|
9
80
|
{},
|
|
10
81
|
colors2
|
|
11
82
|
);
|
|
12
|
-
|
|
13
|
-
var color_rename_next49_default = (
|
|
83
|
+
var colors = ["neutral", "accent", "brand1", "brand2", "brand3", "danger", "warning", "success", "info"];
|
|
84
|
+
var color_rename_next49_default = (glob2) => {
|
|
14
85
|
const renames = {
|
|
15
86
|
// Background
|
|
16
87
|
"--ds-color-background-subtle": "--ds-color-background-tinted",
|
|
@@ -26,7 +97,7 @@ var color_rename_next49_default = (glob) => {
|
|
|
26
97
|
};
|
|
27
98
|
console.log(`Renaming ${Object.keys(renames).length} variables`, renames);
|
|
28
99
|
return runCssCodemod({
|
|
29
|
-
globPattern:
|
|
100
|
+
globPattern: glob2,
|
|
30
101
|
plugins: [
|
|
31
102
|
// https://github.com/digdir/designsystemet/issues/3046
|
|
32
103
|
cssVarRename(renames)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/index.ts"],"names":[],"mappings":";;;;AAGA,wBAGE"}
|