@digdir/designsystemet 1.12.1 → 1.13.0
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 +4 -4
- package/dist/bin/config.d.ts.map +1 -1
- package/dist/bin/config.js +133 -28
- package/dist/bin/designsystemet.d.ts.map +1 -1
- package/dist/bin/designsystemet.js +208 -149
- package/dist/src/config.d.ts +2 -2
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +4 -4
- package/dist/src/index.js +5 -5
- package/dist/src/migrations/beta-to-v1.js +122 -16
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
- package/dist/src/migrations/codemods/css/run.js +122 -16
- package/dist/src/migrations/color-rename-next49.js +122 -16
- package/dist/src/migrations/index.js +122 -16
- package/dist/src/scripts/update-preview-tokens.d.ts.map +1 -1
- package/dist/src/scripts/update-preview-tokens.js +122 -45
- package/dist/src/tokens/build.d.ts +2 -1
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +128 -62
- package/dist/src/tokens/create/files.d.ts +10 -0
- package/dist/src/tokens/create/files.d.ts.map +1 -0
- package/dist/src/tokens/create/{write.js → files.js} +143 -61
- package/dist/src/tokens/create/generators/$designsystemet.js +5 -5
- package/dist/src/tokens/format.js +5 -5
- package/dist/src/tokens/generate-config.d.ts +0 -1
- package/dist/src/tokens/generate-config.d.ts.map +1 -1
- package/dist/src/tokens/generate-config.js +145 -26
- package/dist/src/tokens/index.js +5 -5
- package/dist/src/tokens/process/output/declarations.js +5 -5
- package/dist/src/tokens/process/output/theme.js +5 -5
- package/dist/src/tokens/process/platform.d.ts +0 -4
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/types.d.ts +2 -0
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/utils/filesystem.d.ts +40 -0
- package/dist/src/utils/filesystem.d.ts.map +1 -0
- package/dist/src/utils/filesystem.js +127 -0
- package/package.json +6 -6
- package/dist/src/tokens/create/write.d.ts +0 -12
- package/dist/src/tokens/create/write.d.ts.map +0 -1
- package/dist/src/utils.d.ts +0 -18
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -70
package/dist/src/index.js
CHANGED
|
@@ -2138,11 +2138,11 @@ import * as R9 from "ramda";
|
|
|
2138
2138
|
// package.json
|
|
2139
2139
|
var package_default = {
|
|
2140
2140
|
name: "@digdir/designsystemet",
|
|
2141
|
-
version: "1.
|
|
2141
|
+
version: "1.13.0",
|
|
2142
2142
|
description: "CLI for Designsystemet",
|
|
2143
2143
|
author: "Designsystemet team",
|
|
2144
2144
|
engines: {
|
|
2145
|
-
node: ">=20
|
|
2145
|
+
node: ">=20.20.1"
|
|
2146
2146
|
},
|
|
2147
2147
|
repository: {
|
|
2148
2148
|
type: "git",
|
|
@@ -2206,16 +2206,16 @@ var package_default = {
|
|
|
2206
2206
|
hsluv: "^1.0.1",
|
|
2207
2207
|
"object-hash": "^3.0.0",
|
|
2208
2208
|
picocolors: "^1.1.1",
|
|
2209
|
-
postcss: "^8.5.
|
|
2209
|
+
postcss: "^8.5.8",
|
|
2210
2210
|
ramda: "^0.32.0",
|
|
2211
|
-
"style-dictionary": "^5.3.
|
|
2211
|
+
"style-dictionary": "^5.3.3",
|
|
2212
2212
|
zod: "^4.3.6",
|
|
2213
2213
|
"zod-validation-error": "^5.0.0"
|
|
2214
2214
|
},
|
|
2215
2215
|
devDependencies: {
|
|
2216
2216
|
"@tokens-studio/types": "0.5.2",
|
|
2217
2217
|
"@types/chroma-js": "^3.1.2",
|
|
2218
|
-
"@types/node": "^24.
|
|
2218
|
+
"@types/node": "^24.12.0",
|
|
2219
2219
|
"@types/object-hash": "^3.0.6",
|
|
2220
2220
|
"@types/ramda": "^0.31.1",
|
|
2221
2221
|
tsup: "^8.5.1",
|
|
@@ -42,27 +42,133 @@ var cssVarRename = (dictionary) => ({
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// src/migrations/codemods/css/run.ts
|
|
45
|
-
import fs2 from "fs";
|
|
46
45
|
import glob from "fast-glob";
|
|
47
46
|
import postcss from "postcss";
|
|
48
47
|
|
|
49
|
-
// src/utils.ts
|
|
48
|
+
// src/utils/filesystem.ts
|
|
50
49
|
import fs from "fs/promises";
|
|
50
|
+
import path from "path";
|
|
51
51
|
import pc2 from "picocolors";
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
var FileSystem = class {
|
|
53
|
+
isInitialized = false;
|
|
54
|
+
dry = false;
|
|
55
|
+
verbose = false;
|
|
56
|
+
/** Default working directory is where the process was started */
|
|
57
|
+
workingDir = process.cwd();
|
|
58
|
+
outDir = this.workingDir;
|
|
59
|
+
/** Initialize the file system */
|
|
60
|
+
init({ dry, outdir, verbose }) {
|
|
61
|
+
if (this.isInitialized) {
|
|
62
|
+
console.warn(pc2.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (dry) {
|
|
66
|
+
console.log(pc2.blue("Initializing FileSystem in dry-run mode. No files will be written."));
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
this.dry = dry ?? false;
|
|
69
|
+
this.verbose = verbose ?? false;
|
|
70
|
+
this.outDir = outdir ? path.isAbsolute(outdir) ? outdir : path.join(this.workingDir, outdir) : this.workingDir;
|
|
71
|
+
if (this.verbose) {
|
|
72
|
+
console.log(
|
|
73
|
+
`FileSystem initialized with workingDir: ${pc2.green(this.workingDir)}, outDir: ${pc2.green(this.outDir)}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
this.isInitialized = true;
|
|
64
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a directory if it does not already exist.
|
|
80
|
+
*
|
|
81
|
+
* @param dir - The path of the directory to create.
|
|
82
|
+
*
|
|
83
|
+
* @returns A promise that resolves when the operation is complete.
|
|
84
|
+
* If the directory already exists or `dry` is `true`, the promise resolves immediately.
|
|
85
|
+
*/
|
|
86
|
+
mkdir = async (dir) => {
|
|
87
|
+
if (this.dry) {
|
|
88
|
+
console.log(`${pc2.blue("mkdir")} ${dir}`);
|
|
89
|
+
return Promise.resolve();
|
|
90
|
+
}
|
|
91
|
+
const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
92
|
+
if (exists) {
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
return fs.mkdir(dir, { recursive: true });
|
|
96
|
+
};
|
|
97
|
+
writeFile = async (path2, data) => {
|
|
98
|
+
if (this.dry) {
|
|
99
|
+
console.log(`${pc2.blue("writeFile")} ${path2}`);
|
|
100
|
+
return Promise.resolve();
|
|
101
|
+
}
|
|
102
|
+
return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
|
|
103
|
+
console.error(pc2.red(`Error writing file: ${path2}`));
|
|
104
|
+
console.error(pc2.red(error));
|
|
105
|
+
throw error;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
cp = async (src, dest, filter) => {
|
|
109
|
+
if (this.dry) {
|
|
110
|
+
console.log(`${pc2.blue("cp")} ${src} ${dest}`);
|
|
111
|
+
return Promise.resolve();
|
|
112
|
+
}
|
|
113
|
+
return fs.cp(src, dest, { recursive: true, filter });
|
|
114
|
+
};
|
|
115
|
+
copyFile = async (src, dest) => {
|
|
116
|
+
if (this.dry) {
|
|
117
|
+
console.log(`${pc2.blue("copyFile")} ${src} to ${dest}`);
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
}
|
|
120
|
+
return fs.copyFile(src, dest);
|
|
121
|
+
};
|
|
122
|
+
cleanDir = async (dir) => {
|
|
123
|
+
if (this.dry) {
|
|
124
|
+
console.log(`${pc2.blue("cleanDir")} ${dir}`);
|
|
125
|
+
return Promise.resolve();
|
|
126
|
+
}
|
|
127
|
+
console.log(`
|
|
128
|
+
\u{1F525} Cleaning dir ${pc2.red(`${dir.trim()}`)} `);
|
|
129
|
+
return fs.rm(dir, { recursive: true, force: true });
|
|
130
|
+
};
|
|
131
|
+
readFile = async (path2, allowFileNotFound) => {
|
|
132
|
+
if (this.dry) {
|
|
133
|
+
console.log(`${pc2.blue("readFile")} ${path2}`);
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
return await fs.readFile(path2, "utf-8");
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (allowFileNotFound && error.code === "ENOENT") {
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
readdir = async (path2) => {
|
|
145
|
+
if (this.dry) {
|
|
146
|
+
console.log(`${pc2.blue("readdir")} ${path2}`);
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
return await fs.readdir(path2);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error.code === "ENOENT") {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
writeFiles = async (files, outDir, log) => {
|
|
158
|
+
for (const { destination: filename, output } of files) {
|
|
159
|
+
if (filename) {
|
|
160
|
+
const filePath = path.join(outDir, filename);
|
|
161
|
+
const fileDir = path.dirname(filePath);
|
|
162
|
+
if (log) {
|
|
163
|
+
console.log(filename);
|
|
164
|
+
}
|
|
165
|
+
await this.mkdir(fileDir);
|
|
166
|
+
await this.writeFile(filePath, output);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
65
170
|
};
|
|
171
|
+
var dsfs = new FileSystem();
|
|
66
172
|
|
|
67
173
|
// src/migrations/codemods/css/run.ts
|
|
68
174
|
var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
@@ -78,9 +184,9 @@ var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
|
78
184
|
if (file.includes("node_modules") || file.includes("dist")) {
|
|
79
185
|
return;
|
|
80
186
|
}
|
|
81
|
-
const contents = readFile(file)
|
|
82
|
-
const result = await processor.process(contents, { from: file });
|
|
83
|
-
|
|
187
|
+
const contents = await dsfs.readFile(file);
|
|
188
|
+
const result = await processor.process(contents.toString(), { from: file });
|
|
189
|
+
await dsfs.writeFile(file, result.css);
|
|
84
190
|
});
|
|
85
191
|
await Promise.all(filePromises);
|
|
86
192
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../../src/migrations/codemods/css/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../../src/migrations/codemods/css/run.ts"],"names":[],"mappings":"AACA,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,25 +1,131 @@
|
|
|
1
1
|
// src/migrations/codemods/css/run.ts
|
|
2
|
-
import fs2 from "fs";
|
|
3
2
|
import glob from "fast-glob";
|
|
4
3
|
import postcss from "postcss";
|
|
5
4
|
|
|
6
|
-
// src/utils.ts
|
|
5
|
+
// src/utils/filesystem.ts
|
|
7
6
|
import fs from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
8
|
import pc from "picocolors";
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
var FileSystem = class {
|
|
10
|
+
isInitialized = false;
|
|
11
|
+
dry = false;
|
|
12
|
+
verbose = false;
|
|
13
|
+
/** Default working directory is where the process was started */
|
|
14
|
+
workingDir = process.cwd();
|
|
15
|
+
outDir = this.workingDir;
|
|
16
|
+
/** Initialize the file system */
|
|
17
|
+
init({ dry, outdir, verbose }) {
|
|
18
|
+
if (this.isInitialized) {
|
|
19
|
+
console.warn(pc.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (dry) {
|
|
23
|
+
console.log(pc.blue("Initializing FileSystem in dry-run mode. No files will be written."));
|
|
19
24
|
}
|
|
20
|
-
|
|
25
|
+
this.dry = dry ?? false;
|
|
26
|
+
this.verbose = verbose ?? false;
|
|
27
|
+
this.outDir = outdir ? path.isAbsolute(outdir) ? outdir : path.join(this.workingDir, outdir) : this.workingDir;
|
|
28
|
+
if (this.verbose) {
|
|
29
|
+
console.log(
|
|
30
|
+
`FileSystem initialized with workingDir: ${pc.green(this.workingDir)}, outDir: ${pc.green(this.outDir)}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
this.isInitialized = true;
|
|
21
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a directory if it does not already exist.
|
|
37
|
+
*
|
|
38
|
+
* @param dir - The path of the directory to create.
|
|
39
|
+
*
|
|
40
|
+
* @returns A promise that resolves when the operation is complete.
|
|
41
|
+
* If the directory already exists or `dry` is `true`, the promise resolves immediately.
|
|
42
|
+
*/
|
|
43
|
+
mkdir = async (dir) => {
|
|
44
|
+
if (this.dry) {
|
|
45
|
+
console.log(`${pc.blue("mkdir")} ${dir}`);
|
|
46
|
+
return Promise.resolve();
|
|
47
|
+
}
|
|
48
|
+
const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
49
|
+
if (exists) {
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
}
|
|
52
|
+
return fs.mkdir(dir, { recursive: true });
|
|
53
|
+
};
|
|
54
|
+
writeFile = async (path2, data) => {
|
|
55
|
+
if (this.dry) {
|
|
56
|
+
console.log(`${pc.blue("writeFile")} ${path2}`);
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
}
|
|
59
|
+
return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
|
|
60
|
+
console.error(pc.red(`Error writing file: ${path2}`));
|
|
61
|
+
console.error(pc.red(error));
|
|
62
|
+
throw error;
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
cp = async (src, dest, filter) => {
|
|
66
|
+
if (this.dry) {
|
|
67
|
+
console.log(`${pc.blue("cp")} ${src} ${dest}`);
|
|
68
|
+
return Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
return fs.cp(src, dest, { recursive: true, filter });
|
|
71
|
+
};
|
|
72
|
+
copyFile = async (src, dest) => {
|
|
73
|
+
if (this.dry) {
|
|
74
|
+
console.log(`${pc.blue("copyFile")} ${src} to ${dest}`);
|
|
75
|
+
return Promise.resolve();
|
|
76
|
+
}
|
|
77
|
+
return fs.copyFile(src, dest);
|
|
78
|
+
};
|
|
79
|
+
cleanDir = async (dir) => {
|
|
80
|
+
if (this.dry) {
|
|
81
|
+
console.log(`${pc.blue("cleanDir")} ${dir}`);
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
}
|
|
84
|
+
console.log(`
|
|
85
|
+
\u{1F525} Cleaning dir ${pc.red(`${dir.trim()}`)} `);
|
|
86
|
+
return fs.rm(dir, { recursive: true, force: true });
|
|
87
|
+
};
|
|
88
|
+
readFile = async (path2, allowFileNotFound) => {
|
|
89
|
+
if (this.dry) {
|
|
90
|
+
console.log(`${pc.blue("readFile")} ${path2}`);
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
return await fs.readFile(path2, "utf-8");
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (allowFileNotFound && error.code === "ENOENT") {
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
readdir = async (path2) => {
|
|
102
|
+
if (this.dry) {
|
|
103
|
+
console.log(`${pc.blue("readdir")} ${path2}`);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return await fs.readdir(path2);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (error.code === "ENOENT") {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
writeFiles = async (files, outDir, log) => {
|
|
115
|
+
for (const { destination: filename, output } of files) {
|
|
116
|
+
if (filename) {
|
|
117
|
+
const filePath = path.join(outDir, filename);
|
|
118
|
+
const fileDir = path.dirname(filePath);
|
|
119
|
+
if (log) {
|
|
120
|
+
console.log(filename);
|
|
121
|
+
}
|
|
122
|
+
await this.mkdir(fileDir);
|
|
123
|
+
await this.writeFile(filePath, output);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
22
127
|
};
|
|
128
|
+
var dsfs = new FileSystem();
|
|
23
129
|
|
|
24
130
|
// src/migrations/codemods/css/run.ts
|
|
25
131
|
var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
@@ -35,9 +141,9 @@ var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
|
35
141
|
if (file.includes("node_modules") || file.includes("dist")) {
|
|
36
142
|
return;
|
|
37
143
|
}
|
|
38
|
-
const contents = readFile(file)
|
|
39
|
-
const result = await processor.process(contents, { from: file });
|
|
40
|
-
|
|
144
|
+
const contents = await dsfs.readFile(file);
|
|
145
|
+
const result = await processor.process(contents.toString(), { from: file });
|
|
146
|
+
await dsfs.writeFile(file, result.css);
|
|
41
147
|
});
|
|
42
148
|
await Promise.all(filePromises);
|
|
43
149
|
};
|
|
@@ -33,27 +33,133 @@ var cssVarRename = (dictionary) => ({
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// src/migrations/codemods/css/run.ts
|
|
36
|
-
import fs2 from "fs";
|
|
37
36
|
import glob from "fast-glob";
|
|
38
37
|
import postcss from "postcss";
|
|
39
38
|
|
|
40
|
-
// src/utils.ts
|
|
39
|
+
// src/utils/filesystem.ts
|
|
41
40
|
import fs from "fs/promises";
|
|
41
|
+
import path from "path";
|
|
42
42
|
import pc2 from "picocolors";
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
var FileSystem = class {
|
|
44
|
+
isInitialized = false;
|
|
45
|
+
dry = false;
|
|
46
|
+
verbose = false;
|
|
47
|
+
/** Default working directory is where the process was started */
|
|
48
|
+
workingDir = process.cwd();
|
|
49
|
+
outDir = this.workingDir;
|
|
50
|
+
/** Initialize the file system */
|
|
51
|
+
init({ dry, outdir, verbose }) {
|
|
52
|
+
if (this.isInitialized) {
|
|
53
|
+
console.warn(pc2.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (dry) {
|
|
57
|
+
console.log(pc2.blue("Initializing FileSystem in dry-run mode. No files will be written."));
|
|
53
58
|
}
|
|
54
|
-
|
|
59
|
+
this.dry = dry ?? false;
|
|
60
|
+
this.verbose = verbose ?? false;
|
|
61
|
+
this.outDir = outdir ? path.isAbsolute(outdir) ? outdir : path.join(this.workingDir, outdir) : this.workingDir;
|
|
62
|
+
if (this.verbose) {
|
|
63
|
+
console.log(
|
|
64
|
+
`FileSystem initialized with workingDir: ${pc2.green(this.workingDir)}, outDir: ${pc2.green(this.outDir)}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
this.isInitialized = true;
|
|
55
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a directory if it does not already exist.
|
|
71
|
+
*
|
|
72
|
+
* @param dir - The path of the directory to create.
|
|
73
|
+
*
|
|
74
|
+
* @returns A promise that resolves when the operation is complete.
|
|
75
|
+
* If the directory already exists or `dry` is `true`, the promise resolves immediately.
|
|
76
|
+
*/
|
|
77
|
+
mkdir = async (dir) => {
|
|
78
|
+
if (this.dry) {
|
|
79
|
+
console.log(`${pc2.blue("mkdir")} ${dir}`);
|
|
80
|
+
return Promise.resolve();
|
|
81
|
+
}
|
|
82
|
+
const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
83
|
+
if (exists) {
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
return fs.mkdir(dir, { recursive: true });
|
|
87
|
+
};
|
|
88
|
+
writeFile = async (path2, data) => {
|
|
89
|
+
if (this.dry) {
|
|
90
|
+
console.log(`${pc2.blue("writeFile")} ${path2}`);
|
|
91
|
+
return Promise.resolve();
|
|
92
|
+
}
|
|
93
|
+
return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
|
|
94
|
+
console.error(pc2.red(`Error writing file: ${path2}`));
|
|
95
|
+
console.error(pc2.red(error));
|
|
96
|
+
throw error;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
cp = async (src, dest, filter) => {
|
|
100
|
+
if (this.dry) {
|
|
101
|
+
console.log(`${pc2.blue("cp")} ${src} ${dest}`);
|
|
102
|
+
return Promise.resolve();
|
|
103
|
+
}
|
|
104
|
+
return fs.cp(src, dest, { recursive: true, filter });
|
|
105
|
+
};
|
|
106
|
+
copyFile = async (src, dest) => {
|
|
107
|
+
if (this.dry) {
|
|
108
|
+
console.log(`${pc2.blue("copyFile")} ${src} to ${dest}`);
|
|
109
|
+
return Promise.resolve();
|
|
110
|
+
}
|
|
111
|
+
return fs.copyFile(src, dest);
|
|
112
|
+
};
|
|
113
|
+
cleanDir = async (dir) => {
|
|
114
|
+
if (this.dry) {
|
|
115
|
+
console.log(`${pc2.blue("cleanDir")} ${dir}`);
|
|
116
|
+
return Promise.resolve();
|
|
117
|
+
}
|
|
118
|
+
console.log(`
|
|
119
|
+
\u{1F525} Cleaning dir ${pc2.red(`${dir.trim()}`)} `);
|
|
120
|
+
return fs.rm(dir, { recursive: true, force: true });
|
|
121
|
+
};
|
|
122
|
+
readFile = async (path2, allowFileNotFound) => {
|
|
123
|
+
if (this.dry) {
|
|
124
|
+
console.log(`${pc2.blue("readFile")} ${path2}`);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return await fs.readFile(path2, "utf-8");
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (allowFileNotFound && error.code === "ENOENT") {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
readdir = async (path2) => {
|
|
136
|
+
if (this.dry) {
|
|
137
|
+
console.log(`${pc2.blue("readdir")} ${path2}`);
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
return await fs.readdir(path2);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error.code === "ENOENT") {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
writeFiles = async (files, outDir, log) => {
|
|
149
|
+
for (const { destination: filename, output } of files) {
|
|
150
|
+
if (filename) {
|
|
151
|
+
const filePath = path.join(outDir, filename);
|
|
152
|
+
const fileDir = path.dirname(filePath);
|
|
153
|
+
if (log) {
|
|
154
|
+
console.log(filename);
|
|
155
|
+
}
|
|
156
|
+
await this.mkdir(fileDir);
|
|
157
|
+
await this.writeFile(filePath, output);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
56
161
|
};
|
|
162
|
+
var dsfs = new FileSystem();
|
|
57
163
|
|
|
58
164
|
// src/migrations/codemods/css/run.ts
|
|
59
165
|
var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
@@ -69,9 +175,9 @@ var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
|
69
175
|
if (file.includes("node_modules") || file.includes("dist")) {
|
|
70
176
|
return;
|
|
71
177
|
}
|
|
72
|
-
const contents = readFile(file)
|
|
73
|
-
const result = await processor.process(contents, { from: file });
|
|
74
|
-
|
|
178
|
+
const contents = await dsfs.readFile(file);
|
|
179
|
+
const result = await processor.process(contents.toString(), { from: file });
|
|
180
|
+
await dsfs.writeFile(file, result.css);
|
|
75
181
|
});
|
|
76
182
|
await Promise.all(filePromises);
|
|
77
183
|
};
|
|
@@ -42,27 +42,133 @@ var cssVarRename = (dictionary) => ({
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// src/migrations/codemods/css/run.ts
|
|
45
|
-
import fs2 from "fs";
|
|
46
45
|
import glob from "fast-glob";
|
|
47
46
|
import postcss from "postcss";
|
|
48
47
|
|
|
49
|
-
// src/utils.ts
|
|
48
|
+
// src/utils/filesystem.ts
|
|
50
49
|
import fs from "fs/promises";
|
|
50
|
+
import path from "path";
|
|
51
51
|
import pc2 from "picocolors";
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
var FileSystem = class {
|
|
53
|
+
isInitialized = false;
|
|
54
|
+
dry = false;
|
|
55
|
+
verbose = false;
|
|
56
|
+
/** Default working directory is where the process was started */
|
|
57
|
+
workingDir = process.cwd();
|
|
58
|
+
outDir = this.workingDir;
|
|
59
|
+
/** Initialize the file system */
|
|
60
|
+
init({ dry, outdir, verbose }) {
|
|
61
|
+
if (this.isInitialized) {
|
|
62
|
+
console.warn(pc2.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (dry) {
|
|
66
|
+
console.log(pc2.blue("Initializing FileSystem in dry-run mode. No files will be written."));
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
this.dry = dry ?? false;
|
|
69
|
+
this.verbose = verbose ?? false;
|
|
70
|
+
this.outDir = outdir ? path.isAbsolute(outdir) ? outdir : path.join(this.workingDir, outdir) : this.workingDir;
|
|
71
|
+
if (this.verbose) {
|
|
72
|
+
console.log(
|
|
73
|
+
`FileSystem initialized with workingDir: ${pc2.green(this.workingDir)}, outDir: ${pc2.green(this.outDir)}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
this.isInitialized = true;
|
|
64
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a directory if it does not already exist.
|
|
80
|
+
*
|
|
81
|
+
* @param dir - The path of the directory to create.
|
|
82
|
+
*
|
|
83
|
+
* @returns A promise that resolves when the operation is complete.
|
|
84
|
+
* If the directory already exists or `dry` is `true`, the promise resolves immediately.
|
|
85
|
+
*/
|
|
86
|
+
mkdir = async (dir) => {
|
|
87
|
+
if (this.dry) {
|
|
88
|
+
console.log(`${pc2.blue("mkdir")} ${dir}`);
|
|
89
|
+
return Promise.resolve();
|
|
90
|
+
}
|
|
91
|
+
const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
92
|
+
if (exists) {
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
return fs.mkdir(dir, { recursive: true });
|
|
96
|
+
};
|
|
97
|
+
writeFile = async (path2, data) => {
|
|
98
|
+
if (this.dry) {
|
|
99
|
+
console.log(`${pc2.blue("writeFile")} ${path2}`);
|
|
100
|
+
return Promise.resolve();
|
|
101
|
+
}
|
|
102
|
+
return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
|
|
103
|
+
console.error(pc2.red(`Error writing file: ${path2}`));
|
|
104
|
+
console.error(pc2.red(error));
|
|
105
|
+
throw error;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
cp = async (src, dest, filter) => {
|
|
109
|
+
if (this.dry) {
|
|
110
|
+
console.log(`${pc2.blue("cp")} ${src} ${dest}`);
|
|
111
|
+
return Promise.resolve();
|
|
112
|
+
}
|
|
113
|
+
return fs.cp(src, dest, { recursive: true, filter });
|
|
114
|
+
};
|
|
115
|
+
copyFile = async (src, dest) => {
|
|
116
|
+
if (this.dry) {
|
|
117
|
+
console.log(`${pc2.blue("copyFile")} ${src} to ${dest}`);
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
}
|
|
120
|
+
return fs.copyFile(src, dest);
|
|
121
|
+
};
|
|
122
|
+
cleanDir = async (dir) => {
|
|
123
|
+
if (this.dry) {
|
|
124
|
+
console.log(`${pc2.blue("cleanDir")} ${dir}`);
|
|
125
|
+
return Promise.resolve();
|
|
126
|
+
}
|
|
127
|
+
console.log(`
|
|
128
|
+
\u{1F525} Cleaning dir ${pc2.red(`${dir.trim()}`)} `);
|
|
129
|
+
return fs.rm(dir, { recursive: true, force: true });
|
|
130
|
+
};
|
|
131
|
+
readFile = async (path2, allowFileNotFound) => {
|
|
132
|
+
if (this.dry) {
|
|
133
|
+
console.log(`${pc2.blue("readFile")} ${path2}`);
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
return await fs.readFile(path2, "utf-8");
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (allowFileNotFound && error.code === "ENOENT") {
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
readdir = async (path2) => {
|
|
145
|
+
if (this.dry) {
|
|
146
|
+
console.log(`${pc2.blue("readdir")} ${path2}`);
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
return await fs.readdir(path2);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error.code === "ENOENT") {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
writeFiles = async (files, outDir, log) => {
|
|
158
|
+
for (const { destination: filename, output } of files) {
|
|
159
|
+
if (filename) {
|
|
160
|
+
const filePath = path.join(outDir, filename);
|
|
161
|
+
const fileDir = path.dirname(filePath);
|
|
162
|
+
if (log) {
|
|
163
|
+
console.log(filename);
|
|
164
|
+
}
|
|
165
|
+
await this.mkdir(fileDir);
|
|
166
|
+
await this.writeFile(filePath, output);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
65
170
|
};
|
|
171
|
+
var dsfs = new FileSystem();
|
|
66
172
|
|
|
67
173
|
// src/migrations/codemods/css/run.ts
|
|
68
174
|
var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
@@ -78,9 +184,9 @@ var runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
|
|
|
78
184
|
if (file.includes("node_modules") || file.includes("dist")) {
|
|
79
185
|
return;
|
|
80
186
|
}
|
|
81
|
-
const contents = readFile(file)
|
|
82
|
-
const result = await processor.process(contents, { from: file });
|
|
83
|
-
|
|
187
|
+
const contents = await dsfs.readFile(file);
|
|
188
|
+
const result = await processor.process(contents.toString(), { from: file });
|
|
189
|
+
await dsfs.writeFile(file, result.css);
|
|
84
190
|
});
|
|
85
191
|
await Promise.all(filePromises);
|
|
86
192
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-preview-tokens.d.ts","sourceRoot":"","sources":["../../../src/scripts/update-preview-tokens.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-preview-tokens.d.ts","sourceRoot":"","sources":["../../../src/scripts/update-preview-tokens.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAa,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAkB3D,eAAO,MAAM,WAAW,GAAU,aAAa,KAAK,kBAqEnD,CAAC"}
|