-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
132 lines (110 loc) · 3.59 KB
/
build.sh
File metadata and controls
132 lines (110 loc) · 3.59 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
BUILD_DIR="$ROOT_DIR/build"
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} OpenCode Token Meter Build Script ${NC}"
echo -e "${BLUE}========================================${NC}"
PYTHON="/Users/chwong/miniforge3/envs/opencode/bin/python"
if [ ! -f "$PYTHON" ]; then
PYTHON="$(which python3 || true)"
fi
if [ -z "$PYTHON" ]; then
echo "Error: python3 not found in PATH"
exit 1
fi
echo -e " - Python: ${GREEN}$PYTHON${NC}"
# Install dependencies
echo -e "\n${BLUE}[1/4] Checking dependencies...${NC}"
"$PYTHON" -m pip install --quiet --user --upgrade pyinstaller pywebview pystray pillow pyperclip rumps pyobjc-framework-Cocoa 2>/dev/null || true
echo -e " - Dependencies OK"
# Clean previous builds
echo -e "\n${BLUE}[2/4] Cleaning previous builds...${NC}"
rm -rf "$BUILD_DIR" dist build
echo -e " - Cleaned"
# Build using unified spec file
echo -e "\n${BLUE}[3/4] Building application...${NC}"
cd "$ROOT_DIR"
# Run PyInstaller in background and show spinner
TEMP_LOG=$(mktemp)
"$PYTHON" -m PyInstaller --clean --noconfirm --log-level=ERROR OpenCodeTokenMeter.spec > "$TEMP_LOG" 2>&1 &
PID=$!
# Spinner
SPIN_CHARS='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
i=0
while kill -0 $PID 2>/dev/null; do
i=$(( (i+1) % ${#SPIN_CHARS} ))
printf "\r - Building... ${YELLOW}${SPIN_CHARS:$i:1}${NC} "
sleep 0.1
done
wait $PID
BUILD_EXIT=$?
printf "\r"
if [ $BUILD_EXIT -ne 0 ]; then
echo -e " - ${YELLOW}Build log:${NC}"
cat "$TEMP_LOG" | sed 's/^[0-9]* INFO:/ -/g' | head -20
rm -f "$TEMP_LOG"
echo "ERROR: Build failed"
exit 1
fi
# Show key info from log
grep "^[0-9]* INFO:" "$TEMP_LOG" | sed 's/^[0-9]* INFO:/ -/g' | head -4
rm -f "$TEMP_LOG"
# Verify the .app was created
APP_BUNDLE="$ROOT_DIR/dist/OpenCode Token Meter.app"
if [ ! -d "$APP_BUNDLE" ]; then
echo "ERROR: .app bundle not created"
exit 1
fi
APP_SIZE=$(du -sh "$APP_BUNDLE" | cut -f1 | xargs)
echo -e " - App Bundle: ${GREEN}${APP_SIZE}${NC}"
# Create DMG installer (optional)
DMG_SCRIPT="$ROOT_DIR/create_dmg.sh"
if [ -f "$DMG_SCRIPT" ]; then
echo -e "\n${BLUE}[4/4] Creating DMG installer...${NC}"
# Run DMG creation in background
TEMP_DMG_LOG=$(mktemp)
bash "$DMG_SCRIPT" > "$TEMP_DMG_LOG" 2>&1 &
DMG_PID=$!
# Spinner
SPIN_CHARS='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
j=0
while kill -0 $DMG_PID 2>/dev/null; do
j=$(( (j+1) % ${#SPIN_CHARS} ))
printf "\r - Creating DMG... ${YELLOW}${SPIN_CHARS:$j:1}${NC} "
sleep 0.1
done
wait $DMG_PID
DMG_EXIT=$?
printf "\r"
if [ $DMG_EXIT -ne 0 ]; then
echo -e " - ${YELLOW}DMG creation failed:${NC}"
head -20 "$TEMP_DMG_LOG"
rm -f "$TEMP_DMG_LOG"
exit 1
fi
DMG_OUTPUT=$(cat "$TEMP_DMG_LOG")
rm -f "$TEMP_DMG_LOG"
DMG_PATH=$(echo "$DMG_OUTPUT" | grep "created:" | tail -1 | sed 's/.*created: //')
if [ -n "$DMG_PATH" ] && [ -f "$DMG_PATH" ]; then
DMG_SIZE=$(du -sh "$DMG_PATH" | cut -f1 | xargs)
echo -e " - DMG: ${GREEN}${DMG_SIZE}${NC}"
else
echo -e " - DMG created"
fi
else
echo -e "\n${BLUE}[4/4] Skipping DMG (script not found)${NC}"
fi
echo -e "\n${GREEN}========================================${NC}"
echo -e "${GREEN} Build Complete! ${NC}"
echo -e "${GREEN}========================================${NC}"
echo -e " App: ${GREEN}${APP_SIZE}${NC} → dist/OpenCode Token Meter.app"
if [ -n "${DMG_PATH:-}" ] && [ -f "$DMG_PATH" ]; then
echo -e " DMG: ${GREEN}${DMG_SIZE}${NC} → $(basename "$DMG_PATH")"
fi
exit 0