summaryrefslogtreecommitdiff
path: root/ui/tailwindcss/.claude/hooks/post-install
blob: b25dfcc8f8c83adb7faa7dbdc6fe95babb828c2b (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/bin/bash

# TailwindCSS Post-install Hook
# Runs after dependencies are installed to ensure optimal TailwindCSS setup

set -e

echo "🎨 Running TailwindCSS post-install setup..."

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Function to print colored output
print_status() {
    local color=$1
    local message=$2
    echo -e "${color}${message}${NC}"
}

# Check TailwindCSS installation
check_tailwind_installation() {
    print_status $BLUE "Checking TailwindCSS installation..."
    
    if npm list tailwindcss >/dev/null 2>&1; then
        local version=$(npm list tailwindcss --depth=0 2>/dev/null | grep tailwindcss | sed -E 's/.*tailwindcss@([0-9.]+).*/\1/')
        print_status $GREEN "✅ TailwindCSS v${version} installed"
        
        # Check for v3+ features
        if [[ "$(echo "$version" | cut -d. -f1)" -ge 3 ]]; then
            print_status $GREEN "✅ Using TailwindCSS v3+ with modern features"
        else
            print_status $YELLOW "⚠️  Consider upgrading to TailwindCSS v3+ for better performance"
        fi
    else
        print_status $RED "❌ TailwindCSS not found in dependencies"
        print_status $YELLOW "Run: npm install -D tailwindcss"
        exit 1
    fi
}

# Verify essential plugins
verify_recommended_plugins() {
    print_status $BLUE "Checking for recommended plugins..."
    
    local plugins=(
        "@tailwindcss/typography:Typography support"
        "@tailwindcss/forms:Enhanced form styling"
        "@tailwindcss/aspect-ratio:Aspect ratio utilities"
        "autoprefixer:CSS vendor prefixes"
        "postcss:CSS processing"
    )
    
    for plugin_info in "${plugins[@]}"; do
        local plugin=$(echo "$plugin_info" | cut -d: -f1)
        local description=$(echo "$plugin_info" | cut -d: -f2)
        
        if npm list "$plugin" >/dev/null 2>&1; then
            print_status $GREEN "✅ $plugin installed"
        else
            print_status $YELLOW "⚠️  Consider installing $plugin for $description"
        fi
    done
}

# Initialize configuration if missing
initialize_config() {
    print_status $BLUE "Checking TailwindCSS configuration..."
    
    if [[ ! -f "tailwind.config.js" && ! -f "tailwind.config.ts" ]]; then
        print_status $YELLOW "⚠️  No TailwindCSS config found. Initializing..."
        
        if command -v npx >/dev/null 2>&1; then
            npx tailwindcss init -p
            print_status $GREEN "✅ Created tailwind.config.js and postcss.config.js"
        else
            print_status $RED "❌ npx not available. Please run 'npx tailwindcss init -p' manually"
        fi
    else
        print_status $GREEN "✅ TailwindCSS configuration exists"
    fi
}

# Check PostCSS configuration
verify_postcss_config() {
    print_status $BLUE "Verifying PostCSS configuration..."
    
    if [[ -f "postcss.config.js" ]]; then
        if grep -q "tailwindcss" postcss.config.js; then
            print_status $GREEN "✅ PostCSS configured with TailwindCSS"
        else
            print_status $YELLOW "⚠️  PostCSS config exists but may not include TailwindCSS"
        fi
    else
        print_status $YELLOW "⚠️  No PostCSS config found. Consider creating one for optimal build setup"
        
        # Create basic PostCSS config
        cat > postcss.config.js << EOF
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}
EOF
        print_status $GREEN "✅ Created basic postcss.config.js"
    fi
}

# Optimize package.json scripts
optimize_package_scripts() {
    print_status $BLUE "Checking package.json scripts..."
    
    if [[ -f "package.json" ]]; then
        local has_build_css=$(npm run --silent 2>/dev/null | grep -q "build:css" && echo "true" || echo "false")
        local has_watch_css=$(npm run --silent 2>/dev/null | grep -q "watch:css" && echo "true" || echo "false")
        
        if [[ "$has_build_css" == "false" ]]; then
            print_status $YELLOW "⚠️  Consider adding a build:css script to package.json"
            print_status $BLUE "Example: \"build:css\": \"tailwindcss -i ./src/input.css -o ./dist/output.css --minify\""
        else
            print_status $GREEN "✅ Build CSS script available"
        fi
        
        if [[ "$has_watch_css" == "false" ]]; then
            print_status $YELLOW "⚠️  Consider adding a watch:css script for development"
            print_status $BLUE "Example: \"watch:css\": \"tailwindcss -i ./src/input.css -o ./dist/output.css --watch\""
        else
            print_status $GREEN "✅ Watch CSS script available"
        fi
    fi
}

# Create default CSS entry point
create_css_entry() {
    print_status $BLUE "Checking CSS entry point..."
    
    local css_files=("src/styles.css" "src/input.css" "src/globals.css" "styles/globals.css")
    local css_exists=false
    
    for css_file in "${css_files[@]}"; do
        if [[ -f "$css_file" ]]; then
            css_exists=true
            print_status $GREEN "✅ CSS entry point found: $css_file"
            break
        fi
    done
    
    if [[ "$css_exists" == "false" ]]; then
        print_status $YELLOW "⚠️  No CSS entry point found. Creating src/styles.css..."
        
        mkdir -p src
        cat > src/styles.css << EOF
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  html {
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  }
  
  body {
    @apply bg-background text-foreground;
  }
}

@layer components {
  .btn {
    @apply inline-flex items-center justify-center rounded-md px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50;
  }
  
  .btn-primary {
    @apply bg-primary text-primary-foreground hover:bg-primary/90;
  }
  
  .btn-secondary {
    @apply bg-secondary text-secondary-foreground hover:bg-secondary/80;
  }
  
  .card {
    @apply rounded-lg border bg-card text-card-foreground shadow-sm;
  }
}

@layer utilities {
  .text-balance {
    text-wrap: balance;
  }
}
EOF
        print_status $GREEN "✅ Created src/styles.css with TailwindCSS directives"
    fi
}

# Optimize TailwindCSS configuration
optimize_config() {
    print_status $BLUE "Checking TailwindCSS configuration optimization..."
    
    local config_file="tailwind.config.js"
    if [[ -f "tailwind.config.ts" ]]; then
        config_file="tailwind.config.ts"
    fi
    
    if [[ -f "$config_file" ]]; then
        # Check for content configuration
        if ! grep -q "content:" "$config_file"; then
            print_status $YELLOW "⚠️  No content configuration found in $config_file"
            print_status $YELLOW "Add content paths for proper CSS purging"
        fi
        
        # Check for dark mode configuration
        if ! grep -q "darkMode" "$config_file"; then
            print_status $YELLOW "⚠️  Consider adding dark mode support"
            print_status $BLUE "Add: darkMode: 'class'"
        fi
        
        print_status $GREEN "✅ Configuration file checked"
    fi
}

# Set up development environment
setup_dev_environment() {
    print_status $BLUE "Setting up development environment..."
    
    # Create .gitignore entries if needed
    if [[ -f ".gitignore" ]]; then
        if ! grep -q "# TailwindCSS" .gitignore; then
            echo "" >> .gitignore
            echo "# TailwindCSS" >> .gitignore
            echo "dist/" >> .gitignore
            echo "build/" >> .gitignore
            print_status $GREEN "✅ Added TailwindCSS entries to .gitignore"
        fi
    fi
    
    # Create VSCode settings for better TailwindCSS support
    if [[ ! -d ".vscode" ]]; then
        mkdir -p .vscode
    fi
    
    if [[ ! -f ".vscode/settings.json" ]]; then
        cat > .vscode/settings.json << 'EOF'
{
  "tailwindCSS.includeLanguages": {
    "javascript": "javascript",
    "typescript": "typescript"
  },
  "tailwindCSS.experimental.classRegex": [
    ["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
    ["cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
    ["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
  ],
  "css.validate": false,
  "scss.validate": false,
  "editor.quickSuggestions": {
    "strings": true
  }
}
EOF
        print_status $GREEN "✅ Created .vscode/settings.json for TailwindCSS support"
    fi
}

# Generate usage report
generate_usage_report() {
    print_status $BLUE "Generating TailwindCSS setup report..."
    
    local report_file=".tailwindcss-setup-report.txt"
    
    cat > "$report_file" << EOF
TailwindCSS Setup Report
========================
Generated: $(date)

Installation Status:
- TailwindCSS: $(npm list tailwindcss --depth=0 2>/dev/null | grep tailwindcss || echo "Not installed")
- PostCSS: $(npm list postcss --depth=0 2>/dev/null | grep postcss || echo "Not installed")
- Autoprefixer: $(npm list autoprefixer --depth=0 2>/dev/null | grep autoprefixer || echo "Not installed")

Configuration Files:
- tailwind.config.js: $([ -f "tailwind.config.js" ] && echo "✅ Present" || echo "❌ Missing")
- postcss.config.js: $([ -f "postcss.config.js" ] && echo "✅ Present" || echo "❌ Missing")
- CSS Entry Point: $(ls src/*.css styles/*.css 2>/dev/null | head -1 || echo "❌ Not found")

Recommended Plugins:
- @tailwindcss/typography: $(npm list @tailwindcss/typography >/dev/null 2>&1 && echo "✅ Installed" || echo "⚠️  Not installed")
- @tailwindcss/forms: $(npm list @tailwindcss/forms >/dev/null 2>&1 && echo "✅ Installed" || echo "⚠️  Not installed")
- @tailwindcss/aspect-ratio: $(npm list @tailwindcss/aspect-ratio >/dev/null 2>&1 && echo "✅ Installed" || echo "⚠️  Not installed")

Package Scripts:
$(npm run --silent 2>/dev/null | grep -E "(build|css|watch)" | sed 's/^/- /' || echo "- No relevant scripts found")

Next Steps:
1. Configure content paths in tailwind.config.js
2. Set up your design system tokens
3. Add dark mode support if needed
4. Install recommended plugins as needed
5. Set up build/watch scripts in package.json

For detailed configuration examples, check the TailwindCSS documentation:
https://tailwindcss.com/docs/installation
EOF
    
    print_status $GREEN "✅ Setup report saved to $report_file"
}

# Main execution
main() {
    local start_time=$(date +%s)
    
    print_status $BLUE "🎨 TailwindCSS Post-Install Setup"
    print_status $BLUE "=================================="
    
    # Run all setup tasks
    check_tailwind_installation
    verify_recommended_plugins
    initialize_config
    verify_postcss_config
    optimize_package_scripts
    create_css_entry
    optimize_config
    setup_dev_environment
    generate_usage_report
    
    local end_time=$(date +%s)
    local duration=$((end_time - start_time))
    
    print_status $GREEN "✅ TailwindCSS post-install setup completed in ${duration}s"
    print_status $BLUE "🚀 You're ready to start building with TailwindCSS!"
    print_status $YELLOW "💡 Run 'cat .tailwindcss-setup-report.txt' to see your setup summary"
}

# Run the main function
main