Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·329 lines (274 loc) · 7.75 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·329 lines (274 loc) · 7.75 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
#!/bin/bash
# PVADE Designer Deployment Script
# This script sets up and deploys the complete PVADE Designer platform
set -e
echo "🎨 PVADE Designer - Enterprise Document Automation Platform"
echo "======================================================"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# Check prerequisites
check_prerequisites() {
print_header "Checking prerequisites..."
# Check Node.js
if ! command -v node &> /dev/null; then
print_error "Node.js is not installed. Please install Node.js 18+ first."
exit 1
fi
NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 18 ]; then
print_error "Node.js version 18+ is required. Current version: $(node -v)"
exit 1
fi
print_status "Node.js $(node -v) ✓"
# Check npm
if ! command -v npm &> /dev/null; then
print_error "npm is not installed."
exit 1
fi
print_status "npm $(npm -v) ✓"
# Check .NET
if ! command -v dotnet &> /dev/null; then
print_error ".NET SDK is not installed. Please install .NET 8.0+ first."
exit 1
fi
DOTNET_VERSION=$(dotnet --version | cut -d'.' -f1)
if [ "$DOTNET_VERSION" -lt 8 ]; then
print_error ".NET SDK version 8.0+ is required. Current version: $(dotnet --version)"
exit 1
fi
print_status ".NET SDK $(dotnet --version) ✓"
# Check git
if ! command -v git &> /dev/null; then
print_warning "Git is not installed. Some features may not work properly."
else
print_status "Git $(git --version | cut -d' ' -f3) ✓"
fi
}
# Setup frontend
setup_frontend() {
print_header "Setting up PVADE Designer (Frontend)..."
cd pvad-designer
# Install dependencies
print_status "Installing dependencies..."
npm install
# Build for production (optional)
if [ "$BUILD_FRONTEND" = "true" ]; then
print_status "Building for production..."
npm run build
fi
cd ..
print_status "Frontend setup complete ✓"
}
# Setup backend
setup_backend() {
print_header "Setting up API Server (Backend)..."
cd PVAD.WebApi
# Restore packages
print_status "Restoring .NET packages..."
dotnet restore
# Build
print_status "Building backend..."
dotnet build --configuration Release
cd ..
print_status "Backend setup complete ✓"
}
# Run tests
run_tests() {
if [ "$SKIP_TESTS" = "true" ]; then
print_warning "Skipping tests as requested"
return
fi
print_header "Running tests..."
# Frontend tests
print_status "Running frontend tests..."
cd pvad-designer
if npm test -- --watchAll=false --passWithNoTests; then
print_status "Frontend tests passed ✓"
else
print_warning "Some frontend tests failed, but continuing..."
fi
cd ..
# Backend tests
print_status "Running backend tests..."
if dotnet test PVAD.sln --configuration Release --no-build; then
print_status "Backend tests passed ✓"
else
print_warning "Some backend tests failed, but continuing..."
fi
}
# Start services
start_services() {
print_header "Starting services..."
# Start backend in background
print_status "Starting API server..."
cd PVAD.WebApi
dotnet run --configuration Release > ../api.log 2>&1 &
API_PID=$!
echo $API_PID > ../api.pid
cd ..
# Wait for API to start
print_status "Waiting for API server to start..."
sleep 5
# Check if API is running
if curl -s http://localhost:5000/health > /dev/null 2>&1; then
print_status "API server started successfully ✓"
else
print_warning "API server may not be ready yet"
fi
# Start frontend
print_status "Starting PVADE Designer..."
cd pvad-designer
if [ "$BUILD_FRONTEND" = "true" ]; then
# Serve built files
npx serve -s dist -l 5173 > ../ui.log 2>&1 &
UI_PID=$!
else
# Development server
npm run dev > ../ui.log 2>&1 &
UI_PID=$!
fi
echo $UI_PID > ../ui.pid
cd ..
print_status "Services started successfully ✓"
}
# Show usage information
show_info() {
print_header "Deployment Complete!"
echo ""
echo "🎉 PVADE Designer is now running!"
echo ""
echo "📱 Frontend (PVADE Designer): http://localhost:5173"
echo "🔧 Backend (API Server): http://localhost:5000"
echo "📚 API Documentation: http://localhost:5000/swagger"
echo ""
echo "📋 Demo Templates:"
echo " • Professional Invoice Template"
echo " • Achievement Certificate Template"
echo " • Business Report Template"
echo ""
echo "🛠️ Useful commands:"
echo " • View API logs: tail -f api.log"
echo " • View UI logs: tail -f ui.log"
echo " • Stop services: ./stop.sh"
echo " • Restart services: ./restart.sh"
echo ""
echo "📖 Documentation: README.md"
echo ""
}
# Stop services
stop_services() {
print_header "Stopping services..."
if [ -f api.pid ]; then
API_PID=$(cat api.pid)
if kill -0 $API_PID 2>/dev/null; then
print_status "Stopping API server..."
kill $API_PID
fi
rm -f api.pid
fi
if [ -f ui.pid ]; then
UI_PID=$(cat ui.pid)
if kill -0 $UI_PID 2>/dev/null; then
print_status "Stopping PVADE Designer..."
kill $UI_PID
fi
rm -f ui.pid
fi
print_status "Services stopped ✓"
}
# Cleanup function
cleanup() {
print_status "Cleaning up..."
stop_services
rm -f api.log ui.log
}
# Parse command line arguments
BUILD_FRONTEND=false
SKIP_TESTS=false
CLEANUP=false
while [[ $# -gt 0 ]]; do
case $1 in
--build-frontend)
BUILD_FRONTEND=true
shift
;;
--skip-tests)
SKIP_TESTS=true
shift
;;
--cleanup)
CLEANUP=true
shift
;;
--stop)
stop_services
exit 0
;;
--help)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --build-frontend Build frontend for production"
echo " --skip-tests Skip running tests"
echo " --cleanup Clean up log files and stop services"
echo " --stop Stop running services"
echo " --help Show this help"
echo ""
echo "Examples:"
echo " $0 # Deploy with default settings"
echo " $0 --build-frontend # Deploy with production build"
echo " $0 --skip-tests # Skip tests for faster deployment"
exit 0
;;
*)
print_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Main deployment
main() {
if [ "$CLEANUP" = "true" ]; then
cleanup
exit 0
fi
print_status "Starting PVADE Designer deployment..."
echo ""
check_prerequisites
echo ""
setup_frontend
echo ""
setup_backend
echo ""
run_tests
echo ""
start_services
echo ""
show_info
# Setup cleanup on script exit
trap cleanup EXIT
# Wait for user interrupt
print_status "Press Ctrl+C to stop services"
wait
}
# Run main function
main "$@"