-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildTwSafelist.js
89 lines (81 loc) · 3.44 KB
/
buildTwSafelist.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const { writeFile } = require("fs/promises");
const themeColors = ["primary", "secondary", "accent", "neutral"];
const statusColors = ["info", "warning", "error", "success"];
const baseColors = ["base-100", "base-200", "base-300"];
const allColors = [...baseColors, ...statusColors, ...themeColors];
const sizes = ["xs", "sm", "md", "lg"];
const buttonSizes = ["block", "wide", ...sizes];
const colorVariants = [
"base-content",
...allColors.reduce((acc, color) => {
acc.push(color);
if (!baseColors.includes(color)) {
acc.push(`${color}-content`);
}
if (themeColors.includes(color)) {
acc.push(`${color}-focus`);
}
return acc;
}, [])
];
const builtColors = colorVariants.reduce((acc, variant) => {
acc.push(`"bg-${variant}";`);
if (!baseColors.includes(variant) || variant === "base" || variant === "base-content") {
acc.push(`"text-${variant}";`);
}
return acc;
}, []);
const buildClasses = (colors, sizes, prefix)=>{
return {
variants: colors.map(variant => `"${prefix}-${variant}";`),
sizes: sizes ? sizes.map(variant => `"${prefix}-${variant}";`) : null
};
};
const buttonClasses = buildClasses([...themeColors, ...statusColors], buttonSizes, "btn");
const alertClasses = buildClasses(statusColors, sizes, "alert");
const badgeClasses = buildClasses([...themeColors, ...statusColors], sizes, "badge");
const checkboxClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "checkbox");
const fileInputClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "file-input");
const radioClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "radio");
const rangeClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "range");
const selectClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "select");
const inputClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "input");
const textareaClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "textarea");
const toggleClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], sizes, "toggle");
const progressClasses = buildClasses([...themeColors.filter(c=>c!=="neutral"), ...statusColors], null, "progress");
const builtVariants = [
...builtColors,
...buttonClasses.variants,
...buttonClasses.sizes,
...alertClasses.variants,
...alertClasses.sizes,
...badgeClasses.variants,
...badgeClasses.sizes,
...checkboxClasses.variants,
...checkboxClasses.sizes,
...fileInputClasses.variants,
...fileInputClasses.sizes,
...radioClasses.variants,
...radioClasses.sizes,
...rangeClasses.variants,
...rangeClasses.sizes,
...selectClasses.variants,
...selectClasses.sizes,
...inputClasses.variants,
...inputClasses.sizes,
...textareaClasses.variants,
...textareaClasses.sizes,
...toggleClasses.variants,
...toggleClasses.sizes,
...progressClasses.variants,
];
async function buildFile(clrs) {
try {
await writeFile("src/tw-safelist.js", `${clrs.join(",").replace(/,/g, "\n")}\n`);
console.log(`The file "${"src/tw-safelist.js"}" was successfully generated!`);
}
catch (error) {
console.error(error);
}
}
buildFile(builtVariants);