@imaginario27/air-ui-ds 1.0.12 → 1.0.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imaginario27/air-ui-ds",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "author": "imaginario27",
5
5
  "type": "module",
6
6
  "homepage": "https://air-ui.netlify.app/",
@@ -19,6 +19,7 @@
19
19
  "postinstall": "nuxt prepare",
20
20
  "test": "vitest",
21
21
  "generate-theme": "ts-node scripts/generate-theme.ts",
22
+ "update-theme-colors": "ts-node app/scripts/update-ui-theme-colors.ts",
22
23
  "typecheck": "vue-tsc --noEmit -p tsconfig.typecheck.json"
23
24
  },
24
25
  "dependencies": {
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs"
4
+ import path from "node:path"
5
+ import readline from "node:readline"
6
+
7
+ // ----------------------------------------------------
8
+ // CONFIGURATION
9
+ // ----------------------------------------------------
10
+ const ASSETS_THEME_PATH = "assets/css/theme"
11
+ const UI_THEME_FILE = "ui-theme.css"
12
+ const COLORS_FILE = "colors.css"
13
+
14
+ const THEMES = [
15
+ "primary-brand",
16
+ "secondary-brand",
17
+ "neutral",
18
+ "success",
19
+ "warning",
20
+ "info",
21
+ "danger",
22
+ ] as const
23
+
24
+ type Theme = typeof THEMES[number]
25
+
26
+ interface Replacement {
27
+ theme: Theme
28
+ from: string
29
+ to: string
30
+ }
31
+
32
+ // ----------------------------------------------------
33
+ // HELPERS
34
+ // ----------------------------------------------------
35
+ const rl = readline.createInterface({
36
+ input: process.stdin,
37
+ output: process.stdout,
38
+ })
39
+
40
+ const ask = (question: string): Promise<string> =>
41
+ new Promise(resolve => rl.question(question, answer => resolve(answer.trim())))
42
+
43
+ const readFile = (filePath: string): string =>
44
+ fs.readFileSync(filePath, "utf8")
45
+
46
+ const writeFile = (filePath: string, content: string): void =>
47
+ fs.writeFileSync(filePath, content)
48
+
49
+ const getColorSchemesFromColorsCss = (content: string): Set<string> => {
50
+ const regex = /--color-([a-z0-9-]+)-50:/g
51
+ const schemes = new Set<string>()
52
+
53
+ let match: RegExpExecArray | null
54
+ while ((match = regex.exec(content))) {
55
+ const scheme = match[1]
56
+
57
+ if (scheme) {
58
+ schemes.add(scheme)
59
+ }
60
+ }
61
+
62
+ return schemes
63
+ }
64
+
65
+ const extractCurrentSchemeForTheme = (
66
+ css: string,
67
+ theme: Theme
68
+ ): string | null => {
69
+ const regex = new RegExp(
70
+ String.raw`--color-theme-${theme}-\d+:\s*var\(--([a-z0-9-]+)-\d+\)`,
71
+ "i"
72
+ )
73
+
74
+ const match = regex.exec(css)
75
+ return match?.[1] ?? null
76
+ }
77
+
78
+ // ----------------------------------------------------
79
+ // MAIN
80
+ // ----------------------------------------------------
81
+ const run = async (): Promise<void> => {
82
+ const themePath = path.resolve(process.cwd(), ASSETS_THEME_PATH)
83
+ const uiThemePath = path.join(themePath, UI_THEME_FILE)
84
+ const colorsPath = path.join(themePath, COLORS_FILE)
85
+
86
+ if (!fs.existsSync(uiThemePath)) {
87
+ console.error(`❌ ui-theme.css not found at ${uiThemePath}`)
88
+ process.exit(1)
89
+ }
90
+
91
+ if (!fs.existsSync(colorsPath)) {
92
+ console.error(`❌ colors.css not found at ${colorsPath}`)
93
+ process.exit(1)
94
+ }
95
+
96
+ let uiThemeCss = readFile(uiThemePath)
97
+ const colorsCss = readFile(colorsPath)
98
+ const availableSchemes = getColorSchemesFromColorsCss(colorsCss)
99
+
100
+ const replacements: Replacement[] = []
101
+
102
+ console.log("\n🎨 UI Theme color scheme configuration\n")
103
+
104
+ for (const theme of THEMES) {
105
+ const currentScheme = extractCurrentSchemeForTheme(uiThemeCss, theme)
106
+
107
+ if (!currentScheme) {
108
+ console.log(`⚠️ Could not detect current scheme for "${theme}", skipping`)
109
+ continue
110
+ }
111
+
112
+ const answer = await ask(
113
+ `Do you want to replace "${theme}" color scheme? (current: ${currentScheme}) [y/N]: `
114
+ )
115
+
116
+ if (answer.toLowerCase() !== "y") {
117
+ continue
118
+ }
119
+
120
+ const newScheme = await ask(
121
+ `→ Enter new color scheme name (must exist in colors.css, ex.: lavender): `
122
+ )
123
+
124
+ if (!availableSchemes.has(newScheme)) {
125
+ console.error(
126
+ `❌ Color scheme "${newScheme}" does not exist in colors.css — skipping "${theme}"`
127
+ )
128
+ continue
129
+ }
130
+
131
+ replacements.push({
132
+ theme,
133
+ from: currentScheme,
134
+ to: newScheme,
135
+ })
136
+ }
137
+
138
+ rl.close()
139
+
140
+ if (replacements.length === 0) {
141
+ console.log("\nℹ️ No changes applied")
142
+ return
143
+ }
144
+
145
+ // Apply replacements AFTER all questions
146
+ for (const { theme, from, to } of replacements) {
147
+ const regex = new RegExp(
148
+ String.raw`(--color-theme-${theme}-\d+:\s*var\()--${from}-(\d+\))`,
149
+ "g"
150
+ )
151
+
152
+ uiThemeCss = uiThemeCss.replace(regex, `$1--${to}-$2`)
153
+ }
154
+
155
+ writeFile(uiThemePath, uiThemeCss)
156
+
157
+ console.log("\n✅ ui-theme.css updated successfully\n")
158
+ }
159
+
160
+ run()