-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·362 lines (316 loc) · 10.1 KB
/
setup.sh
File metadata and controls
executable file
·362 lines (316 loc) · 10.1 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
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/bin/bash
# cf-dev-toolkit Web Performance Tools Setup
# Automated installation script for Lighthouse, Puppeteer, and dependencies
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Emojis
ROCKET="🚀"
CHECK="✅"
CROSS="❌"
INFO="ℹ️"
PACKAGE="📦"
WRENCH="🔧"
SPARKLES="✨"
echo -e "${BLUE}${ROCKET} cf-dev-toolkit Web Performance Tools Setup${NC}"
echo -e "${BLUE}================================================${NC}\n"
# Detect platform
OS="$(uname -s)"
case "${OS}" in
Linux*) PLATFORM="Linux";;
Darwin*) PLATFORM="macOS";;
CYGWIN*|MINGW*|MSYS*) PLATFORM="Windows";;
*) PLATFORM="Unknown";;
esac
echo -e "${INFO} Platform detected: ${PLATFORM}\n"
# Function to check if command exists
command_exists() {
command -v "$1" &> /dev/null
}
# Function to check npm package
npm_package_exists() {
npm list -g "$1" &> /dev/null
}
# Check Node.js
echo -e "${WRENCH} Checking prerequisites..."
echo ""
if ! command_exists node; then
echo -e "${CROSS} Node.js not found\n"
echo -e "Please install Node.js 18+ first:"
echo ""
case "${PLATFORM}" in
macOS)
echo " Using Homebrew:"
echo " brew install node"
echo ""
echo " Or download from: https://nodejs.org"
;;
Linux)
echo " Ubuntu/Debian:"
echo " curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -"
echo " sudo apt-get install -y nodejs"
echo ""
echo " Fedora/RHEL:"
echo " curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -"
echo " sudo dnf install -y nodejs"
;;
Windows)
echo " Download from: https://nodejs.org"
echo " Or use winget: winget install OpenJS.NodeJS"
;;
esac
exit 1
else
NODE_VERSION=$(node -v)
echo -e "${CHECK} Node.js ${NODE_VERSION} found"
fi
# Check npm
if ! command_exists npm; then
echo -e "${CROSS} npm not found (should come with Node.js)"
exit 1
else
NPM_VERSION=$(npm -v)
echo -e "${CHECK} npm ${NPM_VERSION} found"
fi
echo ""
# Check current installation status
echo -e "${WRENCH} Checking current installation status..."
echo ""
LIGHTHOUSE_INSTALLED=false
PUPPETEER_INSTALLED=false
if command_exists lighthouse; then
LIGHTHOUSE_VERSION=$(lighthouse --version 2>&1)
echo -e "${CHECK} Lighthouse already installed: ${LIGHTHOUSE_VERSION}"
LIGHTHOUSE_INSTALLED=true
else
echo -e "${CROSS} Lighthouse not installed"
fi
if npm_package_exists puppeteer; then
PUPPETEER_VERSION=$(npm list -g puppeteer 2>&1 | grep puppeteer@ | head -n1 || echo "installed")
echo -e "${CHECK} Puppeteer already installed"
PUPPETEER_INSTALLED=true
else
echo -e "${CROSS} Puppeteer not installed"
fi
echo ""
# If everything is already installed
if [ "$LIGHTHOUSE_INSTALLED" = true ] && [ "$PUPPETEER_INSTALLED" = true ]; then
echo -e "${SPARKLES} All tools are already installed!"
echo ""
echo "You're ready to use the web-performance-agent."
echo ""
read -p "Would you like to reinstall/update? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Setup complete. No changes made."
exit 0
fi
echo ""
fi
# Install system dependencies for Puppeteer (Linux only)
if [ "$PLATFORM" = "Linux" ]; then
echo -e "${PACKAGE} Checking system dependencies for Puppeteer..."
echo ""
if command_exists apt-get; then
echo "Ubuntu/Debian detected. System dependencies may be required for Puppeteer."
read -p "Install system dependencies? (recommended) (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Installing system dependencies..."
sudo apt-get update
sudo apt-get install -y \
libnss3 \
libxss1 \
libasound2 \
libatk-bridge2.0-0 \
libgtk-3-0 \
libgbm1 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxrandr2 \
ca-certificates \
fonts-liberation
echo -e "${CHECK} System dependencies installed"
fi
fi
echo ""
fi
# Offer installation choices
echo -e "${WRENCH} Choose installation method:"
echo ""
echo " 1) ${GREEN}Global${NC} (Recommended for frequent use)"
echo " - Fastest performance"
echo " - Available system-wide"
echo " - Requires npm global permissions"
echo ""
echo " 2) ${BLUE}Plugin-local${NC} (Isolated installation)"
echo " - Isolated to this plugin"
echo " - Slightly slower startup"
echo " - No global permissions needed"
echo ""
echo " 3) ${YELLOW}Use npx only${NC} (No installation)"
echo " - No installation needed"
echo " - Downloads on each first use"
echo " - Slowest option"
echo ""
read -p "Enter choice [1-3] (default: 1): " choice
choice=${choice:-1}
echo ""
case $choice in
1)
echo -e "${PACKAGE} Installing globally..."
echo ""
# Check if we need sudo (Linux/macOS with system npm)
NPM_PREFIX=$(npm config get prefix)
NEED_SUDO=false
if [ "$PLATFORM" != "Windows" ] && [[ "$NPM_PREFIX" == "/usr"* ]]; then
echo -e "${INFO} Global npm location requires sudo"
NEED_SUDO=true
fi
# Install Lighthouse
if [ "$NEED_SUDO" = true ]; then
echo "Installing Lighthouse (may require password)..."
sudo npm install -g lighthouse
else
echo "Installing Lighthouse..."
npm install -g lighthouse
fi
echo -e "${CHECK} Lighthouse installed"
# Install Puppeteer
if [ "$NEED_SUDO" = true ]; then
echo "Installing Puppeteer (may require password)..."
sudo npm install -g puppeteer
else
echo "Installing Puppeteer..."
npm install -g puppeteer
fi
echo -e "${CHECK} Puppeteer installed"
echo ""
echo -e "${SPARKLES} Global installation complete!"
;;
2)
echo -e "${PACKAGE} Installing in plugin directory..."
echo ""
# Create package.json if it doesn't exist
if [ ! -f "package.json" ]; then
cat > package.json << 'EOF'
{
"name": "cf-dev-toolkit-web-perf",
"version": "1.0.0",
"description": "Web performance analysis dependencies for cf-dev-toolkit",
"private": true,
"dependencies": {
"lighthouse": "^11.0.0",
"puppeteer": "^21.0.0",
"chrome-launcher": "^1.0.0"
}
}
EOF
echo -e "${CHECK} Created package.json"
fi
# Install dependencies
echo "Installing dependencies..."
npm install
echo ""
echo -e "${SPARKLES} Plugin-local installation complete!"
echo -e "${INFO} Dependencies installed in: $(pwd)/node_modules"
;;
3)
echo -e "${INFO} No installation needed for npx mode"
echo ""
# Create config file to remember preference
mkdir -p ~/.config/cf-dev-toolkit
echo "USE_NPX=true" > ~/.config/cf-dev-toolkit/web-perf.conf
echo -e "${CHECK} Configuration saved"
echo ""
echo "The web-performance-agent will use 'npx lighthouse' automatically."
echo "First run will download Lighthouse (~50MB), then it's cached."
;;
*)
echo -e "${CROSS} Invalid choice"
exit 1
;;
esac
# Test installation
echo ""
echo -e "${WRENCH} Testing installation..."
echo ""
case $choice in
1)
# Test global installation
if command_exists lighthouse; then
VERSION=$(lighthouse --version 2>&1)
echo -e "${CHECK} Lighthouse test: ${VERSION}"
else
echo -e "${CROSS} Lighthouse test failed"
fi
;;
2)
# Test local installation
if [ -f "node_modules/.bin/lighthouse" ]; then
VERSION=$(./node_modules/.bin/lighthouse --version 2>&1)
echo -e "${CHECK} Lighthouse test: ${VERSION}"
else
echo -e "${CROSS} Lighthouse test failed"
fi
;;
3)
# Test npx
echo "Testing npx (this may take a moment on first run)..."
if npx -y lighthouse --version &> /dev/null; then
echo -e "${CHECK} npx lighthouse test passed"
else
echo -e "${CROSS} npx test failed - check internet connection"
fi
;;
esac
# Final success message
echo ""
echo -e "${GREEN}${SPARKLES}============================================${NC}"
echo -e "${GREEN}${SPARKLES} Setup Complete!${NC}"
echo -e "${GREEN}${SPARKLES}============================================${NC}"
echo ""
echo "You can now use the web-performance-agent!"
echo ""
echo "Example usage:"
echo " Ask: \"Analyze the performance of https://example.com\""
echo " Command: /analyze-performance https://example.com"
echo ""
echo "Check your setup anytime with:"
echo " /check-web-perf"
echo ""
echo "For troubleshooting, see:"
echo " ~/.claude/plugins/cf-dev-toolkit/README.md"
echo ""
# Offer to run test analysis
read -p "Would you like to run a test analysis now? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
TEST_URL="https://example.com"
echo -e "${WRENCH} Running test analysis on ${TEST_URL}..."
echo ""
case $choice in
1)
lighthouse "$TEST_URL" --output=json --quiet --only-categories=performance --chrome-flags="--headless --no-sandbox"
;;
2)
./node_modules/.bin/lighthouse "$TEST_URL" --output=json --quiet --only-categories=performance --chrome-flags="--headless --no-sandbox"
;;
3)
npx -y lighthouse "$TEST_URL" --output=json --quiet --only-categories=performance --chrome-flags="--headless --no-sandbox"
;;
esac
echo ""
echo -e "${CHECK} Test analysis complete!"
fi
echo ""
echo "Happy performance optimization! 🚀"