-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·185 lines (155 loc) · 3.84 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·185 lines (155 loc) · 3.84 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
#!/bin/bash
# Awwdio Build Script
# Provides convenience commands for building and running the application
set -e # Exit on error
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Helper function to print colored messages
print_info() {
echo -e "${BLUE}ℹ ${NC}$1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Function to build frontend
build_ui() {
print_info "Building frontend..."
cd web
npm run build
cd ..
print_success "Frontend built successfully → web/build/"
}
# Function to build backend
build_api() {
print_info "Building Go binary..."
go build -o bin/awwdio
print_success "Backend built successfully → bin/awwdio ($(du -h bin/awwdio | cut -f1))"
}
# Function to do full build
build() {
print_info "Starting full build..."
build_ui
build_api
print_success "Full build complete! Run with: ./bin/awwdio"
}
# Function to clean build artifacts
cleanup() {
print_info "Cleaning build artifacts..."
# Clean frontend build (keep .gitkeep)
if [ -d "web/build" ]; then
# Remove all files except .gitkeep
find web/build -mindepth 1 ! -name '.gitkeep' -delete
print_success "Cleaned web/build/ (preserved .gitkeep)"
fi
if [ -d "web/.svelte-kit" ]; then
rm -rf web/.svelte-kit
print_success "Removed web/.svelte-kit/"
fi
# Clean backend build
if [ -f "bin/awwdio" ]; then
rm -f bin/awwdio
print_success "Removed bin/awwdio"
fi
# Clean node_modules (optional, commented out)
# if [ -d "web/node_modules" ]; then
# rm -rf web/node_modules
# print_success "Removed web/node_modules/"
# fi
print_success "Cleanup complete!"
}
# Function to run in development mode
dev() {
print_info "Starting development mode..."
print_warning "Make sure your .env file is configured!"
# Check if .env exists
if [ ! -f ".env" ]; then
print_error ".env file not found!"
echo ""
echo "Create .env from sample:"
echo " cp sample.env .env"
echo " # Edit .env with your Twilio credentials"
echo " source .env"
exit 1
fi
# Source .env
set -a # automatically export all variables
source .env
set +a
print_success "Environment loaded"
print_info "Starting backend server..."
print_warning "Press Ctrl+C to stop"
echo ""
echo "Backend: http://localhost:${PORT:-8080}"
echo "Frontend: Run 'cd web && npm run dev' in another terminal for hot reload"
echo ""
go run main.go
}
# Function to show help
show_help() {
cat << EOF
Awwdio Build Script
Usage: ./build.sh [command]
Commands:
build Build both frontend and backend (production)
build-ui Build frontend only
build-api Build backend only
cleanup Clean all build artifacts
dev Run in development mode (backend only)
help Show this help message
Examples:
# Full production build
./build.sh build
# Build and run
./build.sh build && ./bin/awwdio
# Development workflow (2 terminals)
# Terminal 1:
./build.sh dev
# Terminal 2:
cd web && npm run dev
# Clean rebuild
./build.sh cleanup && ./build.sh build
EOF
}
# Main script logic
case "${1:-}" in
build)
build
;;
build-ui)
build_ui
;;
build-api)
build_api
;;
cleanup|clean)
cleanup
;;
dev)
dev
;;
help|--help|-h)
show_help
;;
"")
print_error "No command specified"
echo ""
show_help
exit 1
;;
*)
print_error "Unknown command: $1"
echo ""
show_help
exit 1
;;
esac