-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·264 lines (225 loc) · 7.77 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·264 lines (225 loc) · 7.77 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
#!/bin/bash
# Playbot Build Script
# Builds both backend and frontend for production
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo -e "${BLUE}╔═══════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Playbot Build Script ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════╝${NC}"
echo ""
# Get version from pom.xml
VERSION=$(grep -A 1 '<artifactId>playbot</artifactId>' pom.xml | grep '<version>' | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
if [ -z "$VERSION" ]; then
echo -e "${RED}Error: Could not determine version from pom.xml${NC}"
exit 1
fi
# Parse command line arguments
SKIP_TESTS=false
CLEAN=false
PRODUCTION=false
while [[ $# -gt 0 ]]; do
case $1 in
--skip-tests)
SKIP_TESTS=true
shift
;;
--clean)
CLEAN=true
shift
;;
--production)
PRODUCTION=true
shift
;;
--help)
echo "Usage: ./build.sh [options]"
echo ""
echo "Options:"
echo " --skip-tests Skip running tests"
echo " --clean Clean build artifacts before building"
echo " --production Build for production (includes optimization)"
echo " --help Show this help message"
echo ""
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Function to print section headers
print_section() {
echo ""
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${CYAN}$1${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
# Set Java 21 home FIRST (before checking versions)
if [ "$(uname)" == "Darwin" ]; then
# macOS
export JAVA_HOME=$(/usr/libexec/java_home -v 21 2>/dev/null || /usr/libexec/java_home)
elif [ -d "/usr/lib/jvm/java-21-openjdk" ]; then
# Linux (common path)
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk
elif [ -d "/usr/lib/jvm/java-21" ]; then
# Linux (alternate path)
export JAVA_HOME=/usr/lib/jvm/java-21
fi
# Add Java to PATH if JAVA_HOME is set
if [ ! -z "$JAVA_HOME" ]; then
export PATH="$JAVA_HOME/bin:$PATH"
fi
# Check if Java is installed
if ! command -v java &> /dev/null; then
echo -e "${RED}Error: Java is not installed!${NC}"
echo -e "${YELLOW}Please install Java 21 or higher.${NC}"
exit 1
fi
# Check Java version
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d'.' -f1)
if [ "$JAVA_VERSION" -lt 21 ]; then
echo -e "${RED}Error: Java 21 or higher is required!${NC}"
echo -e "${YELLOW}Current version: Java $JAVA_VERSION${NC}"
echo -e "${YELLOW}JAVA_HOME: ${JAVA_HOME:-not set}${NC}"
exit 1
fi
# Check if Maven is installed
if ! command -v mvn &> /dev/null; then
echo -e "${RED}Error: Maven is not installed!${NC}"
echo -e "${YELLOW}Please install Maven 3.6 or higher.${NC}"
exit 1
fi
# Check if Node.js is installed
if ! command -v node &> /dev/null; then
echo -e "${RED}Error: Node.js is not installed!${NC}"
echo -e "${YELLOW}Please install Node.js 18 or higher.${NC}"
exit 1
fi
# Check if npm is installed
if ! command -v npm &> /dev/null; then
echo -e "${RED}Error: npm is not installed!${NC}"
echo -e "${YELLOW}Please install npm.${NC}"
exit 1
fi
echo -e "${GREEN}✓ Environment checks passed${NC}"
echo -e "${YELLOW}Java version:${NC} $(java -version 2>&1 | head -n 1)"
echo -e "${YELLOW}Maven version:${NC} $(mvn -version | head -n 1)"
echo -e "${YELLOW}Node version:${NC} $(node -v)"
echo -e "${YELLOW}npm version:${NC} $(npm -v)"
echo ""
if [ "$CLEAN" = true ]; then
print_section "🧹 Cleaning build artifacts"
echo -e "${YELLOW}Cleaning backend...${NC}"
mvn clean
echo -e "${GREEN}✓ Backend cleaned${NC}"
echo -e "${YELLOW}Cleaning frontend...${NC}"
if [ -d "frontend/node_modules" ]; then
rm -rf frontend/node_modules
echo -e "${GREEN}✓ Removed node_modules${NC}"
fi
if [ -d "frontend/dist" ]; then
rm -rf frontend/dist
echo -e "${GREEN}✓ Removed dist directory${NC}"
fi
echo -e "${GREEN}✓ Frontend cleaned${NC}"
fi
# Build Backend
print_section "🔨 Building Backend"
echo -e "${YELLOW}Building Java application...${NC}"
if [ "$SKIP_TESTS" = true ]; then
echo -e "${BLUE}Skipping tests...${NC}"
mvn package -DskipTests
else
echo -e "${BLUE}Running tests...${NC}"
mvn package
fi
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Backend built successfully${NC}"
# Show JAR info
JAR_FILE="target/playbot-${VERSION}.jar"
if [ -f "$JAR_FILE" ]; then
JAR_SIZE=$(ls -lh "$JAR_FILE" | awk '{print $5}')
echo -e "${YELLOW}JAR file:${NC} $JAR_FILE"
echo -e "${YELLOW}Size:${NC} $JAR_SIZE"
fi
else
echo -e "${RED}✗ Backend build failed${NC}"
exit 1
fi
# Build Frontend
print_section "🎨 Building Frontend"
cd frontend
echo -e "${YELLOW}Installing dependencies...${NC}"
npm install
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Frontend dependency installation failed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Dependencies installed${NC}"
if [ "$SKIP_TESTS" = false ]; then
echo -e "${YELLOW}Running frontend tests...${NC}"
npm run test:unit
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Frontend tests failed${NC}"
cd ..
exit 1
fi
echo -e "${GREEN}✓ Frontend tests passed${NC}"
fi
echo -e "${YELLOW}Building React application...${NC}"
if [ "$PRODUCTION" = true ]; then
echo -e "${BLUE}Building for production...${NC}"
npm run build
else
npm run build
fi
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Frontend built successfully${NC}"
# Show build info
if [ -d "dist" ]; then
DIST_SIZE=$(du -sh dist | awk '{print $1}')
FILE_COUNT=$(find dist -type f | wc -l | tr -d ' ')
echo -e "${YELLOW}Build directory:${NC} frontend/dist"
echo -e "${YELLOW}Size:${NC} $DIST_SIZE"
echo -e "${YELLOW}Files:${NC} $FILE_COUNT"
fi
else
echo -e "${RED}✗ Frontend build failed${NC}"
cd ..
exit 1
fi
cd ..
# Summary
print_section "✅ Build Complete"
echo -e "${GREEN}Both backend and frontend built successfully!${NC}"
echo ""
echo -e "${YELLOW}Backend:${NC}"
echo -e " JAR: target/playbot-${VERSION}.jar"
echo -e " Run: java -jar target/playbot-${VERSION}.jar"
echo ""
echo -e "${YELLOW}Frontend:${NC}"
echo -e " Build: frontend/dist/"
echo -e " Dev: npm run dev (in frontend directory)"
echo ""
if [ "$PRODUCTION" = true ]; then
echo -e "${CYAN}Production build completed!${NC}"
echo -e "${YELLOW}Deployment checklist:${NC}"
echo -e " ☐ Set production environment variables"
echo -e " ☐ Configure production database (if applicable)"
echo -e " ☐ Update OAuth2 redirect URIs in Discord Developer Portal"
echo -e " ☐ Configure reverse proxy (nginx/Apache)"
echo -e " ☐ Set up SSL certificates"
echo ""
fi
echo -e "${BLUE}╔═══════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Build process complete! ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════╝${NC}"