-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-and-deploy.sh
More file actions
executable file
ยท112 lines (90 loc) ยท 2.67 KB
/
build-and-deploy.sh
File metadata and controls
executable file
ยท112 lines (90 loc) ยท 2.67 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
#!/bin/bash
# Always run from the script's directory (project root)
cd "$(dirname "$0")"
# Build and Deploy Script
# Clears old build files, builds new ones, deploys to server, then handles git operations
set -e # Exit on error
echo "๐ Build and Deploy Script"
echo "=========================="
echo ""
# Step 1: Clear old build cache
echo "๐งน Clearing build cache..."
rm -rf dist
rm -rf node_modules/.vite
echo "โ
Build cache cleared"
echo ""
# Step 2: Clear old deployed files in assets directory
echo "๐งน Clearing old deployed assets..."
rm -f assets/*.js assets/*.css 2>/dev/null
echo "โ
Old deployed assets cleared"
echo ""
# Step 3: Build new files
echo "๐จ Building new files..."
npm run build
if [ $? -ne 0 ]; then
echo "โ Build failed. Aborting deployment."
exit 1
fi
echo "โ
Build successful!"
echo ""
# Step 4: Deploy to web server
echo "๐ฆ Deploying to web server..."
cp -r dist/assets/* assets/ 2>/dev/null
cp dist/index.html . 2>/dev/null
# Fix ownership and permissions
echo "๐ Setting permissions..."
chown -R ishaglcy:ishaglcy index.html assets .htaccess 2>/dev/null
chmod 644 index.html .htaccess 2>/dev/null
chmod 755 assets 2>/dev/null
chmod 644 assets/* 2>/dev/null
echo "โ
Deployment complete!"
echo ""
echo "๐ Your app is now live at: https://yahudim.app"
echo ""
echo "Backend API status:"
curl -s http://localhost:3001/health
echo ""
# Step 5: Git operations
echo "๐ Git operations..."
echo ""
# Check if there are changes to commit
if [ -z "$(git status --porcelain)" ]; then
echo "โน๏ธ No changes to commit"
else
echo "๐ Staging changes..."
git add .
echo ""
echo "๐ฌ Enter commit message (or press Enter for default):"
read -r commit_message
if [ -z "$commit_message" ]; then
commit_message="Build and deploy: $(date +'%Y-%m-%d %H:%M:%S')"
fi
echo ""
echo "๐ Committing changes..."
git commit -m "$commit_message"
if [ $? -ne 0 ]; then
echo "โ Commit failed. Aborting."
exit 1
fi
echo "โ
Changes committed"
echo ""
fi
# Step 6: Push to remote
echo "๐ค Pushing to remote..."
if git remote | grep -q "origin"; then
git push origin main
if [ $? -eq 0 ]; then
echo "โ
Successfully pushed to remote"
else
echo "โ ๏ธ Push failed or no changes to push"
fi
else
echo "โน๏ธ No remote 'origin' configured. Skipping push."
echo " Run ./push-to-github.sh to set up remote"
fi
echo ""
echo "๐ Build and deploy process complete!"
echo ""
echo "๐ Deployed files:"
echo " - index.html (root)"
echo " - assets/ ($(ls -1 assets/*.js assets/*.css 2>/dev/null | wc -l) files)"