-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·719 lines (596 loc) · 23.1 KB
/
build.sh
File metadata and controls
executable file
·719 lines (596 loc) · 23.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
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#!/bin/bash
#===============================================================================
# Pomodoro Timer - Flutter Build Script
#===============================================================================
# A comprehensive build script for the Pomodoro Timer Flutter application.
# Supports Release/Debug builds for Android, iOS, iPadOS, macOS, and Windows.
#
# Usage: ./build.sh [options]
# Options:
# -h, --help Show this help message
# -m, --mode Build mode: debug|release (default: debug)
# -p, --platform Platform: android|ios|ipados|macos|windows (default: ios)
# -i, --install Install on connected device (default: false)
# -f, --format Format code before building (default: true)
# -a, --analyze Run analysis before building (default: true)
# --skip-format Skip code formatting
# --skip-analyze Skip code analysis
# --interactive Run in interactive mode (prompts for options)
#===============================================================================
set -e
# Colors for output
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
BOLD='\033[1m'
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FLUTTER_PROJECT_DIR="$SCRIPT_DIR/flutter/pomodoro_timer"
# Default values
BUILD_MODE="debug"
PLATFORM="ios"
INSTALL_ON_DEVICE=false
FORMAT_CODE=true
ANALYZE_CODE=true
INTERACTIVE=false
#===============================================================================
# Helper Functions
#===============================================================================
print_banner() {
echo -e "${PURPLE}"
echo "╔═══════════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ 🍅 Pomodoro Timer Build Script 🍅 ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
print_step() {
echo -e "\n${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${CYAN}${BOLD}▶ $1${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_info() {
echo -e "${CYAN}ℹ $1${NC}"
}
show_help() {
echo -e "${BOLD}Pomodoro Timer - Flutter Build Script${NC}"
echo ""
echo -e "${BOLD}Usage:${NC} ./build.sh [options]"
echo ""
echo -e "${BOLD}Options:${NC}"
echo " -h, --help Show this help message"
echo " -m, --mode Build mode: debug|release (default: debug)"
echo " -p, --platform Platform: android|ios|ipados|macos|windows (default: ios)"
echo " -i, --install Install on connected device"
echo " -f, --format Format code before building (default: true)"
echo " -a, --analyze Run analysis before building (default: true)"
echo " --skip-format Skip code formatting"
echo " --skip-analyze Skip code analysis"
echo " --interactive Run in interactive mode (prompts for options)"
echo ""
echo -e "${BOLD}Examples:${NC}"
echo " ./build.sh # Default: iOS debug build"
echo " ./build.sh -m release -p android # Release build for Android"
echo " ./build.sh -m debug -p ios -i # Debug build for iOS with install"
echo " ./build.sh -m release -p macos # Release build for macOS"
echo " ./build.sh -m debug -p ipados -i # Debug build for iPadOS with install"
echo " ./build.sh -m release -p windows # Release build for Windows"
echo " ./build.sh --interactive # Interactive mode with prompts"
echo ""
}
check_prerequisites() {
print_step "Checking Prerequisites"
local has_error=false
# Check if Flutter is installed
if command -v flutter &> /dev/null; then
local flutter_version=$(flutter --version | head -n 1)
print_success "Flutter found: $flutter_version"
else
print_error "Flutter is not installed or not in PATH"
has_error=true
fi
# Check if Dart is installed
if command -v dart &> /dev/null; then
local dart_version=$(dart --version 2>&1)
print_success "Dart found: $dart_version"
else
print_error "Dart is not installed or not in PATH"
has_error=true
fi
# Check Flutter project directory
if [ -d "$FLUTTER_PROJECT_DIR" ]; then
print_success "Flutter project directory found: $FLUTTER_PROJECT_DIR"
else
print_error "Flutter project directory not found: $FLUTTER_PROJECT_DIR"
has_error=true
fi
# Check pubspec.yaml
if [ -f "$FLUTTER_PROJECT_DIR/pubspec.yaml" ]; then
print_success "pubspec.yaml found"
else
print_error "pubspec.yaml not found in Flutter project"
has_error=true
fi
# Platform-specific checks
if [[ "$PLATFORM" == "ios" || "$PLATFORM" == "ipados" || "$PLATFORM" == "macos" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
if command -v xcodebuild &> /dev/null; then
print_success "Xcode found for $PLATFORM builds"
else
print_error "Xcode not found - required for $PLATFORM builds"
has_error=true
fi
else
print_error "$PLATFORM builds require macOS"
has_error=true
fi
fi
if [[ "$PLATFORM" == "android" ]]; then
if [ -n "$ANDROID_HOME" ] || [ -n "$ANDROID_SDK_ROOT" ]; then
print_success "Android SDK found"
else
print_warning "ANDROID_HOME or ANDROID_SDK_ROOT not set - Android build may fail"
fi
fi
if [[ "$PLATFORM" == "windows" ]]; then
if [[ "$(uname)" == "MINGW"* || "$(uname)" == "MSYS"* || "$(uname)" == "CYGWIN"* ]]; then
print_success "Windows build environment detected"
else
print_warning "Windows builds are best run on Windows - cross-compilation not supported"
fi
fi
if [ "$has_error" = true ]; then
print_error "Prerequisites check failed. Please fix the issues above."
exit 1
fi
echo ""
print_success "All prerequisites satisfied!"
}
#===============================================================================
# Interactive Menu Functions
#===============================================================================
select_build_mode() {
echo -e "\n${BOLD}Select Build Mode:${NC}"
echo ""
echo -e " ${CYAN}1)${NC} Debug - Development build with debugging enabled"
echo -e " ${CYAN}2)${NC} Release - Optimized production build"
echo ""
while true; do
read -p "$(echo -e ${YELLOW}Enter choice [1-2]: ${NC})" choice
case $choice in
1) BUILD_MODE="debug"; break;;
2) BUILD_MODE="release"; break;;
*) print_error "Invalid choice. Please enter 1 or 2.";;
esac
done
print_success "Selected: $BUILD_MODE mode"
}
select_platform() {
echo -e "\n${BOLD}Select Target Platform:${NC}"
echo ""
echo -e " ${CYAN}1)${NC} Android - Build for Android devices"
echo -e " ${CYAN}2)${NC} iOS - Build for iPhone (macOS only)"
echo -e " ${CYAN}3)${NC} iPadOS - Build for iPad (macOS only)"
echo -e " ${CYAN}4)${NC} macOS - Build for Mac desktop (macOS only)"
echo -e " ${CYAN}5)${NC} Windows - Build for Windows desktop"
echo ""
while true; do
read -p "$(echo -e ${YELLOW}Enter choice [1-5]: ${NC})" choice
case $choice in
1) PLATFORM="android"; break;;
2) PLATFORM="ios"; break;;
3) PLATFORM="ipados"; break;;
4) PLATFORM="macos"; break;;
5) PLATFORM="windows"; break;;
*) print_error "Invalid choice. Please enter 1, 2, 3, 4, or 5.";;
esac
done
print_success "Selected: $PLATFORM platform"
}
select_install() {
# Install option not available for desktop platforms
if [[ "$PLATFORM" == "macos" || "$PLATFORM" == "windows" ]]; then
print_info "Install option not applicable for $PLATFORM - app will be built and can be run directly"
INSTALL_ON_DEVICE=false
return
fi
echo -e "\n${BOLD}Install on Connected Device?${NC}"
echo ""
echo -e " ${CYAN}1)${NC} Yes - Install the built app on a connected device"
echo -e " ${CYAN}2)${NC} No - Only build the app (don't install)"
echo ""
while true; do
read -p "$(echo -e ${YELLOW}Enter choice [1-2]: ${NC})" choice
case $choice in
1) INSTALL_ON_DEVICE=true; break;;
2) INSTALL_ON_DEVICE=false; break;;
*) print_error "Invalid choice. Please enter 1 or 2.";;
esac
done
if [ "$INSTALL_ON_DEVICE" = true ]; then
print_success "Will install on connected device"
else
print_info "Will only build (no installation)"
fi
}
#===============================================================================
# Build Functions
#===============================================================================
get_dependencies() {
print_step "Getting Dependencies"
cd "$FLUTTER_PROJECT_DIR"
flutter pub get
print_success "Dependencies fetched successfully!"
}
format_code() {
if [ "$FORMAT_CODE" = false ]; then
print_info "Skipping code formatting (--skip-format)"
return
fi
print_step "Formatting Code (Pipeline Verification)"
cd "$FLUTTER_PROJECT_DIR"
# Format code
print_info "Running dart format..."
dart format .
# Verify formatting would pass pipeline
print_info "Verifying formatting matches pipeline requirements..."
if dart format --output=none --set-exit-if-changed .; then
print_success "Code formatting verified - pipeline check will pass!"
else
print_error "Code formatting verification failed!"
exit 1
fi
}
analyze_code() {
if [ "$ANALYZE_CODE" = false ]; then
print_info "Skipping code analysis (--skip-analyze)"
return
fi
print_step "Analyzing Code"
cd "$FLUTTER_PROJECT_DIR"
print_info "Running flutter analyze..."
if flutter analyze --no-fatal-infos; then
print_success "Code analysis passed!"
else
print_warning "Code analysis found issues (non-fatal)"
fi
}
build_android() {
print_step "Building for Android ($BUILD_MODE)"
cd "$FLUTTER_PROJECT_DIR"
local build_command="flutter build apk"
if [ "$BUILD_MODE" = "release" ]; then
build_command="$build_command --release"
else
build_command="$build_command --debug"
fi
print_info "Running: $build_command"
eval $build_command
# Show output location
if [ "$BUILD_MODE" = "release" ]; then
local apk_path="$FLUTTER_PROJECT_DIR/build/app/outputs/flutter-apk/app-release.apk"
else
local apk_path="$FLUTTER_PROJECT_DIR/build/app/outputs/flutter-apk/app-debug.apk"
fi
if [ -f "$apk_path" ]; then
print_success "Android APK built successfully!"
print_info "Output: $apk_path"
fi
}
build_ios() {
print_step "Building for iOS/iPhone ($BUILD_MODE)"
if [[ "$(uname)" != "Darwin" ]]; then
print_error "iOS builds are only supported on macOS"
return 1
fi
cd "$FLUTTER_PROJECT_DIR"
# Install CocoaPods dependencies
print_info "Installing CocoaPods dependencies..."
cd ios
pod install --repo-update || print_warning "Pod install had warnings"
cd ..
local build_command="flutter build ios"
if [ "$BUILD_MODE" = "release" ]; then
build_command="$build_command --release --no-codesign"
else
build_command="$build_command --debug --no-codesign"
fi
print_info "Running: $build_command"
eval $build_command
print_success "iOS build completed!"
print_info "Note: For App Store distribution, open Xcode and archive the project."
}
build_ipados() {
print_step "Building for iPadOS ($BUILD_MODE)"
if [[ "$(uname)" != "Darwin" ]]; then
print_error "iPadOS builds are only supported on macOS"
return 1
fi
cd "$FLUTTER_PROJECT_DIR"
# Install CocoaPods dependencies
print_info "Installing CocoaPods dependencies..."
cd ios
pod install --repo-update || print_warning "Pod install had warnings"
cd ..
# iPadOS uses the same iOS build but targets iPad
local build_command="flutter build ios"
if [ "$BUILD_MODE" = "release" ]; then
build_command="$build_command --release --no-codesign"
else
build_command="$build_command --debug --no-codesign"
fi
print_info "Running: $build_command"
print_info "Note: iPadOS uses the iOS build - app supports both iPhone and iPad"
eval $build_command
print_success "iPadOS build completed!"
print_info "Note: For App Store distribution, open Xcode and archive the project."
}
build_macos() {
print_step "Building for macOS ($BUILD_MODE)"
if [[ "$(uname)" != "Darwin" ]]; then
print_error "macOS builds are only supported on macOS"
return 1
fi
cd "$FLUTTER_PROJECT_DIR"
# Install CocoaPods dependencies for macOS
print_info "Installing CocoaPods dependencies..."
cd macos
pod install --repo-update || print_warning "Pod install had warnings"
cd ..
local build_command="flutter build macos"
if [ "$BUILD_MODE" = "release" ]; then
build_command="$build_command --release"
else
build_command="$build_command --debug"
fi
print_info "Running: $build_command"
eval $build_command
print_success "macOS build completed!"
# Show output location
local app_path="$FLUTTER_PROJECT_DIR/build/macos/Build/Products"
if [ "$BUILD_MODE" = "release" ]; then
app_path="$app_path/Release"
else
app_path="$app_path/Debug"
fi
print_info "Output: $app_path/"
print_info "You can run the app directly from the build folder."
}
build_windows() {
print_step "Building for Windows ($BUILD_MODE)"
cd "$FLUTTER_PROJECT_DIR"
local build_command="flutter build windows"
if [ "$BUILD_MODE" = "release" ]; then
build_command="$build_command --release"
else
build_command="$build_command --debug"
fi
print_info "Running: $build_command"
eval $build_command
print_success "Windows build completed!"
# Show output location
local exe_path="$FLUTTER_PROJECT_DIR/build/windows/x64/runner"
if [ "$BUILD_MODE" = "release" ]; then
exe_path="$exe_path/Release"
else
exe_path="$exe_path/Debug"
fi
print_info "Output: $exe_path/"
print_info "You can run the .exe file directly from the build folder."
}
install_android() {
print_step "Installing on Android Device"
cd "$FLUTTER_PROJECT_DIR"
# Check for connected devices
local devices=$(flutter devices | grep -i android)
if [ -z "$devices" ]; then
print_warning "No Android device connected. Skipping installation."
return
fi
print_info "Found Android device(s):"
echo "$devices"
local install_command="flutter install"
print_info "Running: $install_command"
eval $install_command
print_success "App installed on Android device!"
}
install_ios() {
print_step "Installing on iOS Device"
if [[ "$(uname)" != "Darwin" ]]; then
print_error "iOS installation is only supported on macOS"
return
fi
cd "$FLUTTER_PROJECT_DIR"
# Check for connected devices
local devices=$(flutter devices | grep -i -E "iphone|ipad")
if [ -z "$devices" ]; then
print_warning "No iOS/iPadOS device connected. Skipping installation."
return
fi
print_info "Found iOS/iPadOS device(s):"
echo "$devices"
local install_command="flutter install"
print_info "Running: $install_command"
eval $install_command
print_success "App installed on iOS device!"
}
#===============================================================================
# Summary Functions
#===============================================================================
print_build_summary() {
echo -e "\n${PURPLE}╔═══════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${PURPLE}║ BUILD SUMMARY ║${NC}"
echo -e "${PURPLE}╚═══════════════════════════════════════════════════════════════════╝${NC}\n"
echo -e " ${BOLD}Build Mode:${NC} $BUILD_MODE"
echo -e " ${BOLD}Platform:${NC} $PLATFORM"
echo -e " ${BOLD}Install:${NC} $INSTALL_ON_DEVICE"
echo -e " ${BOLD}Format Code:${NC} $FORMAT_CODE"
echo -e " ${BOLD}Analyze Code:${NC} $ANALYZE_CODE"
echo ""
}
print_completion() {
echo -e "\n${GREEN}╔═══════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ BUILD COMPLETED! 🎉 ║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════════╝${NC}\n"
case "$PLATFORM" in
android)
if [ "$BUILD_MODE" = "release" ]; then
print_info "Android APK: $FLUTTER_PROJECT_DIR/build/app/outputs/flutter-apk/app-release.apk"
else
print_info "Android APK: $FLUTTER_PROJECT_DIR/build/app/outputs/flutter-apk/app-debug.apk"
fi
;;
ios|ipados)
print_info "iOS/iPadOS Build: $FLUTTER_PROJECT_DIR/build/ios/iphoneos/"
;;
macos)
if [ "$BUILD_MODE" = "release" ]; then
print_info "macOS App: $FLUTTER_PROJECT_DIR/build/macos/Build/Products/Release/"
else
print_info "macOS App: $FLUTTER_PROJECT_DIR/build/macos/Build/Products/Debug/"
fi
;;
windows)
if [ "$BUILD_MODE" = "release" ]; then
print_info "Windows Exe: $FLUTTER_PROJECT_DIR/build/windows/x64/runner/Release/"
else
print_info "Windows Exe: $FLUTTER_PROJECT_DIR/build/windows/x64/runner/Debug/"
fi
;;
esac
echo ""
}
#===============================================================================
# Main Execution
#===============================================================================
parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
exit 0
;;
-m|--mode)
BUILD_MODE="$2"
if [[ "$BUILD_MODE" != "debug" && "$BUILD_MODE" != "release" ]]; then
print_error "Invalid build mode: $BUILD_MODE (must be 'debug' or 'release')"
exit 1
fi
shift 2
;;
-p|--platform)
PLATFORM="$2"
if [[ "$PLATFORM" != "android" && "$PLATFORM" != "ios" && "$PLATFORM" != "ipados" && "$PLATFORM" != "macos" && "$PLATFORM" != "windows" ]]; then
print_error "Invalid platform: $PLATFORM (must be 'android', 'ios', 'ipados', 'macos', or 'windows')"
exit 1
fi
shift 2
;;
-i|--install)
INSTALL_ON_DEVICE=true
shift
;;
-f|--format)
FORMAT_CODE=true
shift
;;
-a|--analyze)
ANALYZE_CODE=true
shift
;;
--skip-format)
FORMAT_CODE=false
shift
;;
--skip-analyze)
ANALYZE_CODE=false
shift
;;
--interactive)
INTERACTIVE=true
shift
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
}
main() {
# Parse command line arguments
parse_arguments "$@"
# Print banner
print_banner
# Interactive mode if explicitly requested
if [ "$INTERACTIVE" = true ]; then
select_build_mode
select_platform
select_install
# Print build summary
print_build_summary
# Confirm before proceeding
echo ""
read -p "$(echo -e ${YELLOW}Proceed with build? [Y/n]: ${NC})" confirm
case $confirm in
[Nn]*)
print_info "Build cancelled."
exit 0
;;
esac
else
# Print build summary (using defaults or provided options)
print_build_summary
fi
# Run build steps
check_prerequisites
get_dependencies
format_code
analyze_code
# Build for selected platform
case "$PLATFORM" in
android)
build_android
if [ "$INSTALL_ON_DEVICE" = true ]; then
install_android
fi
;;
ios)
build_ios
if [ "$INSTALL_ON_DEVICE" = true ]; then
install_ios
fi
;;
ipados)
build_ipados
if [ "$INSTALL_ON_DEVICE" = true ]; then
install_ios
fi
;;
macos)
build_macos
;;
windows)
build_windows
;;
esac
# Print completion message
print_completion
}
# Run main function
main "$@"