@imaginario27/air-ui-ds 1.0.2 → 1.0.3
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/package.json +1 -1
- package/scripts/generate-theme.ts +104 -0
package/package.json
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readFileSync,
|
|
3
|
+
writeFileSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
unlinkSync,
|
|
7
|
+
} from "fs"
|
|
8
|
+
import { resolve, dirname } from "path"
|
|
9
|
+
|
|
10
|
+
const inputPath = resolve("assets/css/theme/ui-theme.css")
|
|
11
|
+
const outputPath = resolve("assets/css/main.css")
|
|
12
|
+
|
|
13
|
+
ensureOutputDir(outputPath)
|
|
14
|
+
deleteIfExists(outputPath)
|
|
15
|
+
|
|
16
|
+
const content = readFileSync(inputPath, "utf-8")
|
|
17
|
+
const { colorVars, otherVars } = extractThemeVars(content)
|
|
18
|
+
|
|
19
|
+
const finalOutput = generateThemeFile(colorVars, otherVars)
|
|
20
|
+
writeFileSync(outputPath, finalOutput, "utf-8")
|
|
21
|
+
|
|
22
|
+
console.log("✅ Tailwind theme file generated in assets/css/")
|
|
23
|
+
|
|
24
|
+
function ensureOutputDir(filePath: string) {
|
|
25
|
+
const dir = dirname(filePath)
|
|
26
|
+
if (!existsSync(dir)) {
|
|
27
|
+
mkdirSync(dir, { recursive: true })
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function deleteIfExists(filePath: string) {
|
|
32
|
+
if (existsSync(filePath)) {
|
|
33
|
+
unlinkSync(filePath)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function extractThemeVars(content: string) {
|
|
38
|
+
const colorVars: string[] = []
|
|
39
|
+
const otherVars: string[] = []
|
|
40
|
+
|
|
41
|
+
const lines = content.split("\n")
|
|
42
|
+
let inRoot = false
|
|
43
|
+
let inDark = false
|
|
44
|
+
|
|
45
|
+
for (const rawLine of lines) {
|
|
46
|
+
const line = rawLine.trim()
|
|
47
|
+
|
|
48
|
+
if (line.startsWith(":root {")) {
|
|
49
|
+
inRoot = true
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
if (line.startsWith(".dark {")) {
|
|
53
|
+
inDark = true
|
|
54
|
+
continue
|
|
55
|
+
}
|
|
56
|
+
if (line.startsWith("}")) {
|
|
57
|
+
inRoot = false
|
|
58
|
+
inDark = false
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!inRoot || inDark) continue
|
|
63
|
+
|
|
64
|
+
const key = extractVarKey(line)
|
|
65
|
+
if (!key || key.startsWith("--ds-")) continue
|
|
66
|
+
|
|
67
|
+
const declaration = ` ${key}: var(${key});`
|
|
68
|
+
if (key.startsWith("--color-")) {
|
|
69
|
+
colorVars.push(declaration)
|
|
70
|
+
} else {
|
|
71
|
+
otherVars.push(declaration)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { colorVars, otherVars }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function extractVarKey(line: string): string | null {
|
|
79
|
+
const match = line.match(/^--[\w-]+:\s*[^;]+;/)
|
|
80
|
+
if (!match) return null
|
|
81
|
+
const [key] = line.split(":").map(s => s.trim().replace(/;$/, ""))
|
|
82
|
+
return key || null
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function generateThemeFile(colorVars: string[], otherVars: string[]): string {
|
|
86
|
+
return [
|
|
87
|
+
`@import "tailwindcss";`,
|
|
88
|
+
`@source "../../node_modules/@imaginario27/air-ui-ds";`,
|
|
89
|
+
`@source "../../node_modules/@imaginario27/air-ui-utils";`,
|
|
90
|
+
``,
|
|
91
|
+
`@import "./theme/primitives.css";`,
|
|
92
|
+
`@import "./theme/colors.css";`,
|
|
93
|
+
`@import "./theme/ui-theme.css";`,
|
|
94
|
+
``,
|
|
95
|
+
`@theme {`,
|
|
96
|
+
` /* Disables Tailwind default colors */`,
|
|
97
|
+
` --color-*: initial;`,
|
|
98
|
+
``,
|
|
99
|
+
...colorVars,
|
|
100
|
+
``,
|
|
101
|
+
...otherVars,
|
|
102
|
+
`}`,
|
|
103
|
+
].join("\n")
|
|
104
|
+
}
|