-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-for-deploy.sh
executable file
·157 lines (137 loc) · 4.55 KB
/
copy-for-deploy.sh
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
#!/bin/bash
echo "Preparing files for GitHub Pages deployment..."
# Store the current build assets
echo "Backing up build assets..."
mkdir -p temp_assets
if [ -d "dist/assets" ]; then
cp -rf dist/assets/* temp_assets/
fi
# Ensure dist directory exists and is clean
rm -rf dist
mkdir -p dist
mkdir -p dist/assets
# Restore the build assets
echo "Restoring build assets..."
cp -rf temp_assets/* dist/assets/ 2>/dev/null || :
rm -rf temp_assets
# Create .nojekyll file to prevent GitHub Pages from ignoring files that begin with underscore
touch dist/.nojekyll
# Copy favicon if it exists
if [ -f "favicon.ico" ]; then
echo "Copying favicon.ico..."
cp -f favicon.ico dist/
fi
# Copy 404.html to dist directory
if [ -f "public/404.html" ]; then
echo "Copying 404.html..."
cp -f public/404.html dist/
elif [ -f "404.html" ]; then
echo "Copying 404.html from root..."
cp -f 404.html dist/
fi
# Copy the entire public directory structure
if [ -d "public" ]; then
echo "Copying public directory structure..."
cp -rf public/* dist/ 2>/dev/null || :
fi
# Copy the entire src directory structure for static files
echo "Copying src directory structure..."
mkdir -p dist/src
# Copy react-learning directory
if [ -d "src/react-learning" ]; then
echo "Copying src/react-learning directory..."
mkdir -p dist/src/react-learning
cp -rf src/react-learning/* dist/src/react-learning/
fi
# Run the update-deployment-info script to generate fresh deployment info
echo "Updating deployment information..."
./update-deployment-info.sh
# Copy deployment-info.txt to dist directory
if [ -f "public/deployment-info.txt" ]; then
echo "Copying deployment-info.txt..."
cp -f public/deployment-info.txt dist/
fi
# Copy talks directory
if [ -d "src/talks" ]; then
echo "Copying src/talks directory..."
mkdir -p dist/src/talks
cp -rf src/talks/* dist/src/talks/
fi
# Copy assets directory with all subdirectories
if [ -d "src/assets" ]; then
echo "Copying src/assets directory with all subdirectories..."
mkdir -p dist/src/assets
cp -rf src/assets/* dist/src/assets/
fi
# Copy images directory if it exists at the root level
if [ -d "images" ]; then
echo "Copying images directory..."
mkdir -p dist/images
cp -rf images/* dist/images/ 2>/dev/null || :
fi
# Get the latest JS file name
JS_FILE=$(find dist/assets -name "main-*.js" | head -n 1)
if [ -z "$JS_FILE" ]; then
JS_FILE=$(find dist/assets -name "index-*.js" | head -n 1)
fi
if [ -n "$JS_FILE" ]; then
JS_FILENAME=$(basename "$JS_FILE")
echo "Found JS file: $JS_FILENAME"
else
echo "Warning: No JS file found!"
exit 1
fi
# Get the latest CSS file name
CSS_FILE=$(find dist/assets -name "main-*.css" | head -n 1)
if [ -z "$CSS_FILE" ]; then
CSS_FILE=$(find dist/assets -name "index-*.css" | head -n 1)
fi
if [ -n "$CSS_FILE" ]; then
CSS_FILENAME=$(basename "$CSS_FILE")
echo "Found CSS file: $CSS_FILENAME"
else
echo "Warning: No CSS file found!"
exit 1
fi
# Directly edit the index.html file to ensure correct paths
echo "Directly editing index.html file..."
cat > dist/index.html << EOL
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="/awesome-scalability-talks/favicon.ico" />
<!-- Handle GitHub Pages routing -->
<script>
// Store the URL if we came from a redirect
(function () {
const redirect = sessionStorage.redirect;
delete sessionStorage.redirect;
if (redirect && redirect !== location.href) {
history.replaceState(null, null, redirect);
}
})();
</script>
<title>Awesome scalability talks</title>
<script type="module" crossorigin src="/awesome-scalability-talks/assets/${JS_FILENAME}"></script>
<link rel="stylesheet" href="/awesome-scalability-talks/assets/${CSS_FILENAME}">
</head>
<body>
<div id="root"></div>
</body>
</html>
EOL
echo "Files prepared for deployment!"
echo "Contents of dist directory:"
ls -la dist/
echo "Contents of dist/assets directory:"
ls -la dist/assets/ 2>/dev/null || echo "No assets directory found"
echo "Contents of dist/src directory:"
ls -la dist/src/ 2>/dev/null || echo "No src directory found"
echo "Contents of dist/src/assets directory:"
ls -la dist/src/assets/ 2>/dev/null || echo "No src/assets directory found"
echo "Contents of dist/src/react-learning directory:"
ls -la dist/src/react-learning/ 2>/dev/null || echo "No src/react-learning directory found"
echo "Contents of dist/src/talks directory:"
ls -la dist/src/talks/ 2>/dev/null || echo "No src/talks directory found"