-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtransform.ts
More file actions
executable file
·44 lines (35 loc) · 1.33 KB
/
Copy pathtransform.ts
File metadata and controls
executable file
·44 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
/**
* Script to transform utilities which depend on spacing values to use the spacing function.
* This ensures prefixes are applied correctly when using the `@import 'tailwindcss' prefix(...)` syntax.
*/
import { readFileSync, writeFileSync } from "fs";
import { resolve } from "path";
function main() {
const args = process.argv.slice(2);
if (args.length !== 2) {
console.error("Usage: node transform.ts <input-file> <output-file>");
process.exit(1);
}
const inputFile = resolve(args[0]);
const outputFile = resolve(args[1]);
try {
let content = readFileSync(inputFile, "utf-8");
// First regex: calc(--value(integer|number) * var(--spacing)) -> --spacing(--value($1))
content = content.replace(
/calc\(--value\((integer|number)\) ?\* ?var\(--spacing\)\)/g,
"--spacing(--value($1))",
);
// Second regex: calc(--value(integer|number) * var(--spacing) * -1) -> --spacing(--value($1 * -1))
content = content.replace(
/calc\(--value\((integer|number)\) ?\* ?var\(--spacing\)( ?)\*( ?)-1\)/g,
"--spacing(--value($1)$2*$3-1)",
);
writeFileSync(outputFile, content, "utf-8");
console.log(`Transformed ${inputFile} -> ${outputFile}`);
} catch (error) {
console.error(`Error processing file ${inputFile}:`, error);
process.exit(1);
}
}
main();