Skip to content

Commit 995c552

Browse files
author
Ivo Bellin Salarin
committed
feat: cli and gitignore
1 parent e563def commit 995c552

File tree

2 files changed

+224
-1
lines changed

2 files changed

+224
-1
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,9 @@ fastlane/test_output
9090
iOSInjectionProject/
9191

9292
# Mac OS
93-
.DS_Store
93+
.DS_Store
94+
95+
# Archive outputs
96+
Archives/
97+
*.xcarchive
98+
Recap.app

cli

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
#!/bin/bash
2+
3+
# Recap macOS App Build Script
4+
# This script handles building, running, testing, and archiving the Recap app
5+
6+
set -e # Exit on any error
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
BLUE='\033[0;34m'
13+
NC='\033[0m' # No Color
14+
15+
# Configuration
16+
PROJECT_NAME="Recap"
17+
SCHEME_NAME="Recap"
18+
PROJECT_FILE="Recap.xcodeproj"
19+
ARCHIVE_DIR="Archives"
20+
ARCHIVE_NAME="Recap-$(date +%Y-%m-%d-%H-%M-%S).xcarchive"
21+
22+
# Resolve project root from this script's location (works from anywhere)
23+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
25+
# Locate the Xcode project file, even if it's within a subfolder like "Recap/"
26+
resolve_project_file() {
27+
local start_dir="$1"
28+
local found_path=""
29+
30+
# First, try within the script directory up to a few levels deep
31+
found_path=$(find "$start_dir" -maxdepth 3 -type d -name "$PROJECT_FILE" -print -quit 2>/dev/null || true)
32+
if [[ -n "$found_path" ]]; then
33+
echo "$found_path"
34+
return 0
35+
fi
36+
37+
# Next, walk upwards and search shallowly in each ancestor
38+
local dir="$start_dir"
39+
while [[ "$dir" != "/" ]]; do
40+
found_path=$(find "$dir" -maxdepth 2 -type d -name "$PROJECT_FILE" -print -quit 2>/dev/null || true)
41+
if [[ -n "$found_path" ]]; then
42+
echo "$found_path"
43+
return 0
44+
fi
45+
dir="$(dirname "$dir")"
46+
done
47+
48+
# Finally, try current working directory as a fallback
49+
found_path=$(find "$(pwd)" -maxdepth 3 -type d -name "$PROJECT_FILE" -print -quit 2>/dev/null || true)
50+
if [[ -n "$found_path" ]]; then
51+
echo "$found_path"
52+
return 0
53+
fi
54+
55+
return 1
56+
}
57+
58+
PROJECT_FILE_PATH="$(resolve_project_file "$SCRIPT_DIR" || true)"
59+
if [[ -z "$PROJECT_FILE_PATH" ]]; then
60+
echo -e "\033[0;31m[ERROR]\033[0m Could not locate $PROJECT_FILE. Ensure it exists (e.g., Recap/$PROJECT_FILE)."
61+
exit 1
62+
fi
63+
PROJECT_ROOT="$(dirname "$PROJECT_FILE_PATH")"
64+
cd "$PROJECT_ROOT"
65+
PROJECT_FILE="$(basename "$PROJECT_FILE_PATH")"
66+
67+
# Function to print colored output
68+
print_status() {
69+
echo -e "${BLUE}[INFO]${NC} $1"
70+
}
71+
72+
print_success() {
73+
echo -e "${GREEN}[SUCCESS]${NC} $1"
74+
}
75+
76+
print_warning() {
77+
echo -e "${YELLOW}[WARNING]${NC} $1"
78+
}
79+
80+
print_error() {
81+
echo -e "${RED}[ERROR]${NC} $1"
82+
}
83+
84+
# Function to check if Xcode is installed
85+
check_xcode() {
86+
if ! command -v xcodebuild &> /dev/null; then
87+
print_error "Xcode command line tools not found. Please install Xcode and command line tools."
88+
exit 1
89+
fi
90+
print_success "Xcode command line tools found"
91+
}
92+
93+
# Function to clean build folder
94+
clean_build() {
95+
print_status "Cleaning build folder..."
96+
xcodebuild clean -project "$PROJECT_FILE" -scheme "$SCHEME_NAME" -configuration Debug
97+
print_success "Build folder cleaned"
98+
}
99+
100+
# Function to build the app
101+
build_app() {
102+
print_status "Building $PROJECT_NAME..."
103+
xcodebuild build -project "$PROJECT_FILE" -scheme "$SCHEME_NAME" -configuration Debug -destination "platform=macOS"
104+
print_success "Build completed successfully"
105+
}
106+
107+
# Function to run the app
108+
run_app() {
109+
print_status "Running $PROJECT_NAME..."
110+
# Find the built app
111+
APP_PATH=$(find ~/Library/Developer/Xcode/DerivedData -name "Recap.app" -type d | head -1)
112+
113+
if [ -z "$APP_PATH" ]; then
114+
print_error "Could not find built Recap.app. Please build the app first."
115+
exit 1
116+
fi
117+
118+
print_status "Found app at: $APP_PATH"
119+
open "$APP_PATH"
120+
print_success "App launched successfully"
121+
}
122+
123+
# Function to run tests
124+
run_tests() {
125+
print_status "Running tests..."
126+
# Use the scheme's default test configuration (no hardcoded test plan)
127+
xcodebuild test -project "$PROJECT_FILE" -scheme "$SCHEME_NAME" -destination "platform=macOS"
128+
print_success "Tests completed successfully"
129+
}
130+
131+
# Function to archive the app
132+
archive_app() {
133+
print_status "Creating archive..."
134+
135+
# Create archives directory if it doesn't exist
136+
mkdir -p "$ARCHIVE_DIR"
137+
138+
# Archive the app
139+
xcodebuild archive \
140+
-project "$PROJECT_FILE" \
141+
-scheme "$SCHEME_NAME" \
142+
-configuration Release \
143+
-destination "platform=macOS" \
144+
-archivePath "$ARCHIVE_DIR/$ARCHIVE_NAME"
145+
146+
print_success "Archive created: $ARCHIVE_DIR/$ARCHIVE_NAME"
147+
}
148+
149+
# Function to show help
150+
show_help() {
151+
echo "Recap macOS App Build Script"
152+
echo ""
153+
echo "Usage: $0 [OPTIONS]"
154+
echo ""
155+
echo "Options:"
156+
echo " build Build the app"
157+
echo " run Run the app"
158+
echo " test Run tests"
159+
echo " archive Create archive"
160+
echo " all Build, test, and archive (in that order)"
161+
echo " clean Clean build folder"
162+
echo " help Show this help message"
163+
echo ""
164+
echo "Examples:"
165+
echo " $0 build"
166+
echo " $0 all"
167+
echo " $0 clean && $0 build"
168+
}
169+
170+
# Main script logic
171+
main() {
172+
# We already cd'ed into project root; re-validate presence of project file
173+
if [ ! -d "$PROJECT_FILE" ] && [ ! -f "$PROJECT_FILE" ]; then
174+
print_error "Project file $PROJECT_FILE not found in $PROJECT_ROOT."
175+
exit 1
176+
fi
177+
178+
# Check Xcode installation
179+
check_xcode
180+
181+
# Parse command line arguments
182+
case "${1:-all}" in
183+
"build")
184+
clean_build
185+
build_app
186+
;;
187+
"run")
188+
run_app
189+
;;
190+
"test")
191+
run_tests
192+
;;
193+
"archive")
194+
archive_app
195+
;;
196+
"all")
197+
clean_build
198+
build_app
199+
run_tests
200+
archive_app
201+
print_success "All operations completed successfully!"
202+
;;
203+
"clean")
204+
clean_build
205+
;;
206+
"help"|"-h"|"--help")
207+
show_help
208+
;;
209+
*)
210+
print_error "Unknown option: $1"
211+
show_help
212+
exit 1
213+
;;
214+
esac
215+
}
216+
217+
# Run main function with all arguments
218+
main "$@"

0 commit comments

Comments
 (0)