-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.sh
More file actions
666 lines (586 loc) · 17.2 KB
/
Copy pathrun.sh
File metadata and controls
666 lines (586 loc) · 17.2 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#!/bin/bash
# =============================================================================
# 🚀 PetCare AI Tasks - Run Script
# =============================================================================
# Script para executar o aplicativo em diferentes modos e plataformas
# Suporta desenvolvimento, testes, build e deployment
# =============================================================================
set -e # Exit on any error
# Colors and emojis
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
CHECK_MARK="✅"
CROSS_MARK="❌"
WARNING="⚠️"
INFO="ℹ️"
ROCKET="🚀"
WRENCH="🔧"
GEAR="⚙️"
PHONE="📱"
COMPUTER="💻"
PACKAGE="📦"
# Script version
SCRIPT_VERSION="1.0.0"
# Default values
PLATFORM=""
MODE="development"
CLEAR_CACHE=false
VERBOSE=false
PORT="19000"
# =============================================================================
# Helper Functions
# =============================================================================
print_header() {
echo ""
echo -e "${BLUE}=================================================================${NC}"
echo -e "${CYAN} ${ROCKET} PetCare AI Tasks - Run Script v${SCRIPT_VERSION}${NC}"
echo -e "${BLUE}=================================================================${NC}"
echo ""
}
print_step() {
echo -e "\n${BLUE}${ROCKET} $1${NC}"
echo "-----------------------------------------------------------"
}
print_success() {
echo -e "${GREEN}${CHECK_MARK} $1${NC}"
}
print_error() {
echo -e "${RED}${CROSS_MARK} $1${NC}"
}
print_warning() {
echo -e "${YELLOW}${WARNING} $1${NC}"
}
print_info() {
echo -e "${CYAN}${INFO} $1${NC}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if we're in the correct directory
check_project_root() {
if [ ! -f "package.json" ]; then
print_error "package.json not found!"
print_info "Please run this script from the project root directory"
exit 1
fi
if [ ! -f "app.json" ]; then
print_error "app.json not found!"
print_info "This doesn't appear to be an Expo project"
exit 1
fi
}
# Check prerequisites
check_prerequisites() {
print_step "Checking prerequisites"
local errors=0
# Check Node.js
if command_exists node; then
local node_version=$(node --version | cut -d'v' -f2)
local major_version=$(echo $node_version | cut -d'.' -f1)
if [ "$major_version" -ge 18 ]; then
print_success "Node.js $node_version"
else
print_error "Node.js $node_version (Minimum required: 18.x)"
errors=$((errors + 1))
fi
else
print_error "Node.js not found"
errors=$((errors + 1))
fi
# Check npm
if command_exists npm; then
print_success "npm $(npm --version)"
else
print_error "npm not found"
errors=$((errors + 1))
fi
# Check Expo CLI
if command_exists npx; then
print_success "npx available (Expo will use npx)"
else
print_error "npx not found"
errors=$((errors + 1))
fi
# Check dependencies
if [ -d "node_modules" ]; then
print_success "Dependencies installed"
else
print_warning "Dependencies not installed"
print_info "Running npm install..."
npm install
print_success "Dependencies installed"
fi
# Check .env file
if [ -f ".env" ]; then
print_success "Environment configuration found"
else
print_warning ".env file not found"
print_info "Run ./configure.sh to create environment configuration"
fi
if [ $errors -gt 0 ]; then
print_error "$errors error(s) found. Please fix them before continuing."
exit 1
fi
print_success "All prerequisites met!"
}
# Clear caches
clear_caches() {
if [ "$CLEAR_CACHE" = true ]; then
print_step "Clearing caches"
# Clear npm cache
print_info "Clearing npm cache..."
npm cache clean --force
# Clear Expo cache
print_info "Clearing Expo cache..."
npx expo r -c >/dev/null 2>&1 || true
# Clear Metro cache
print_info "Clearing Metro cache..."
rm -rf /tmp/metro-* || true
rm -rf /tmp/haste-map-* || true
# Clear React Native cache
print_info "Clearing React Native cache..."
rm -rf /tmp/react-* || true
print_success "Caches cleared"
fi
}
# Start development server
start_dev_server() {
print_step "Starting development server"
local expo_args=""
# Add port if specified
if [ "$PORT" != "19000" ]; then
expo_args="$expo_args --port $PORT"
fi
# Add clear cache if requested
if [ "$CLEAR_CACHE" = true ]; then
expo_args="$expo_args --clear"
fi
print_info "Starting Expo development server..."
print_info "Port: $PORT"
print_info "Mode: $MODE"
if [ "$VERBOSE" = true ]; then
print_info "Verbose mode enabled"
fi
echo ""
echo -e "${CYAN}🔗 Development URLs will be displayed below:${NC}"
echo ""
# Start Expo
npx expo start $expo_args
}
# Run on specific platform
run_platform() {
print_step "Running on $PLATFORM"
case $PLATFORM in
"ios")
print_info "Starting iOS simulator..."
if command_exists xcrun; then
npx expo run:ios
else
print_error "iOS development tools not found"
print_info "Install Xcode from App Store (macOS only)"
exit 1
fi
;;
"android")
print_info "Starting Android emulator..."
npx expo run:android
;;
"web")
print_info "Starting web version..."
npx expo start --web
;;
*)
print_error "Unknown platform: $PLATFORM"
print_info "Available platforms: ios, android, web"
exit 1
;;
esac
}
# Build for production
build_production() {
print_step "Building for production"
# Check EAS CLI
if ! command_exists eas; then
print_warning "EAS CLI not found. Installing..."
npm install -g @expo/eas-cli
fi
case $PLATFORM in
"ios")
print_info "Building iOS app..."
eas build --platform ios
;;
"android")
print_info "Building Android app..."
eas build --platform android
;;
"all")
print_info "Building for all platforms..."
eas build --platform all
;;
*)
print_error "Invalid platform for build: $PLATFORM"
print_info "Available platforms: ios, android, all"
exit 1
;;
esac
}
# Run tests
run_tests() {
print_step "Running tests"
if npm run | grep -q "test"; then
npm run test
else
print_warning "No test script found in package.json"
print_info "Add test script to package.json to enable testing"
fi
}
# Run linting
run_lint() {
print_step "Running linter"
if npm run | grep -q "lint"; then
npm run lint
else
print_warning "No lint script found in package.json"
print_info "Add lint script to package.json to enable linting"
fi
}
# Run type checking
run_typecheck() {
print_step "Running type check"
if command_exists tsc; then
tsc --noEmit
else
print_warning "TypeScript not found"
print_info "Install TypeScript to enable type checking"
fi
}
# Show device status
show_device_status() {
print_step "Device Status"
echo -e "${CYAN}📱 iOS Simulators:${NC}"
if command_exists xcrun; then
xcrun simctl list devices | grep "iPhone" | head -5
else
echo " iOS development not available on this platform"
fi
echo ""
echo -e "${CYAN}🤖 Android Devices:${NC}"
if command_exists adb; then
adb devices
else
echo " Android SDK not found (install Android Studio)"
fi
echo ""
echo -e "${CYAN}🌐 Network:${NC}"
if command_exists ifconfig; then
local ip=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -1)
echo " Local IP: $ip"
elif command_exists ip; then
local ip=$(ip route get 1 | awk '{print $NF;exit}')
echo " Local IP: $ip"
else
echo " Network info not available"
fi
}
# Show app info
show_app_info() {
print_step "App Information"
if [ -f "app.json" ]; then
echo -e "${CYAN}📱 App Details:${NC}"
echo " Name: $(cat app.json | grep '"name"' | cut -d'"' -f4)"
echo " Version: $(cat app.json | grep '"version"' | cut -d'"' -f4)"
echo " Slug: $(cat app.json | grep '"slug"' | cut -d'"' -f4)"
echo ""
fi
if [ -f "package.json" ]; then
echo -e "${CYAN}📦 Package Details:${NC}"
echo " Version: $(cat package.json | grep '"version"' | cut -d'"' -f4)"
echo " Main: $(cat package.json | grep '"main"' | cut -d'"' -f4)"
echo ""
fi
if [ -f ".env" ]; then
echo -e "${CYAN}⚙️ Environment:${NC}"
echo " NODE_ENV: $(grep "NODE_ENV=" .env | cut -d'=' -f2 || echo "not set")"
echo " APP_ENV: $(grep "APP_ENV=" .env | cut -d'=' -f2 || echo "not set")"
echo ""
fi
}
# Print usage information
print_usage() {
echo "PetCare AI Tasks - Run Script"
echo ""
echo "Usage: $0 [command] [options]"
echo ""
echo "Commands:"
echo " start Start development server (default)"
echo " ios Run on iOS simulator"
echo " android Run on Android emulator/device"
echo " web Run web version"
echo " build <platform> Build for production (ios|android|all)"
echo " test Run tests"
echo " lint Run linter"
echo " typecheck Run TypeScript type checking"
echo " info Show app and device information"
echo " status Show device status"
echo " doctor Run diagnostics"
echo ""
echo "Options:"
echo " -c, --clear Clear caches before starting"
echo " -p, --port <port> Specify port for dev server (default: 19000)"
echo " -v, --verbose Verbose output"
echo " -h, --help Show this help message"
echo " --version Show script version"
echo ""
echo "Examples:"
echo " $0 start # Start development server"
echo " $0 ios # Run on iOS simulator"
echo " $0 android -c # Run on Android with cache clear"
echo " $0 build ios # Build iOS app for production"
echo " $0 test # Run all tests"
echo ""
echo "Environment Variables:"
echo " PORT Default port for dev server"
echo " NODE_ENV Node environment (development|production)"
echo ""
}
# Run diagnostics
run_diagnostics() {
print_step "Running diagnostics"
echo -e "${CYAN}🩺 System Check:${NC}"
echo ""
# OS Info
echo -e "${YELLOW}Operating System:${NC}"
case "$(uname -s)" in
Darwin*) echo " macOS $(sw_vers -productVersion)" ;;
Linux*) echo " Linux $(uname -r)" ;;
CYGWIN*|MINGW*|MSYS*) echo " Windows" ;;
*) echo " Unknown" ;;
esac
echo ""
# Node.js
echo -e "${YELLOW}Node.js Environment:${NC}"
if command_exists node; then
echo " Node.js: $(node --version)"
echo " npm: $(npm --version)"
echo " npx: $(npx --version)"
else
echo " ❌ Node.js not installed"
fi
echo ""
# React Native environment
echo -e "${YELLOW}React Native Environment:${NC}"
if command_exists npx; then
echo " Expo CLI: Available via npx"
# Check Expo version
local expo_version=$(npx expo --version 2>/dev/null || echo "unknown")
echo " Expo Version: $expo_version"
else
echo " ❌ Expo CLI not available"
fi
echo ""
# iOS development (macOS only)
if [[ "$(uname -s)" == "Darwin" ]]; then
echo -e "${YELLOW}iOS Development:${NC}"
if command_exists xcrun; then
echo " ✅ Xcode command line tools installed"
echo " Xcode: $(xcodebuild -version | head -1)"
else
echo " ❌ Xcode command line tools not installed"
fi
echo ""
fi
# Android development
echo -e "${YELLOW}Android Development:${NC}"
if [ -n "$ANDROID_HOME" ]; then
echo " ✅ Android SDK: $ANDROID_HOME"
if command_exists adb; then
echo " ✅ ADB available"
else
echo " ⚠️ ADB not in PATH"
fi
else
echo " ❌ ANDROID_HOME not set"
fi
echo ""
# Project status
echo -e "${YELLOW}Project Status:${NC}"
if [ -f "package.json" ]; then
echo " ✅ package.json found"
else
echo " ❌ package.json missing"
fi
if [ -d "node_modules" ]; then
echo " ✅ Dependencies installed"
else
echo " ❌ Dependencies not installed"
fi
if [ -f ".env" ]; then
echo " ✅ Environment configuration"
else
echo " ⚠️ .env file missing"
fi
echo ""
# Network
echo -e "${YELLOW}Network:${NC}"
if ping -c 1 google.com >/dev/null 2>&1; then
echo " ✅ Internet connection"
else
echo " ❌ No internet connection"
fi
if command_exists ifconfig; then
local ip=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -1)
echo " Local IP: $ip"
elif command_exists ip; then
local ip=$(ip route get 1 | awk '{print $NF;exit}')
echo " Local IP: $ip"
fi
echo ""
print_success "Diagnostics complete!"
}
# Parse command line arguments
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
start)
COMMAND="start"
shift
;;
ios)
COMMAND="platform"
PLATFORM="ios"
shift
;;
android)
COMMAND="platform"
PLATFORM="android"
shift
;;
web)
COMMAND="platform"
PLATFORM="web"
shift
;;
build)
COMMAND="build"
if [[ $# -gt 1 ]] && [[ $2 != -* ]]; then
PLATFORM="$2"
shift
else
PLATFORM="all"
fi
shift
;;
test)
COMMAND="test"
shift
;;
lint)
COMMAND="lint"
shift
;;
typecheck)
COMMAND="typecheck"
shift
;;
info)
COMMAND="info"
shift
;;
status)
COMMAND="status"
shift
;;
doctor)
COMMAND="doctor"
shift
;;
-c|--clear)
CLEAR_CACHE=true
shift
;;
-p|--port)
if [[ $# -gt 1 ]]; then
PORT="$2"
shift 2
else
print_error "Port value required"
exit 1
fi
;;
-v|--verbose)
VERBOSE=true
shift
;;
-h|--help)
print_usage
exit 0
;;
--version)
echo "Run Script v$SCRIPT_VERSION"
exit 0
;;
*)
print_error "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Default command
if [ -z "$COMMAND" ]; then
COMMAND="start"
fi
}
# Main execution function
main() {
print_header
# Check prerequisites first
check_project_root
check_prerequisites
# Clear caches if requested
clear_caches
# Execute command
case $COMMAND in
"start")
start_dev_server
;;
"platform")
run_platform
;;
"build")
build_production
;;
"test")
run_tests
;;
"lint")
run_lint
;;
"typecheck")
run_typecheck
;;
"info")
show_app_info
;;
"status")
show_device_status
;;
"doctor")
run_diagnostics
;;
*)
print_error "Unknown command: $COMMAND"
print_usage
exit 1
;;
esac
}
# Parse arguments and run
parse_args "$@"
main