-
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
·106 lines (85 loc) · 2.52 KB
/
build-and-deploy.sh
File metadata and controls
executable file
·106 lines (85 loc) · 2.52 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
#!/bin/bash
# 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://yeladim.church"
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)"