-
Notifications
You must be signed in to change notification settings - Fork 9
/
build_frontend.sh
59 lines (45 loc) · 1.96 KB
/
build_frontend.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
# build frontend
#!/bin/bash
REPO_URL="https://github.com/sst-product-team/attendance-web-client.git"
DIR_NAME="attendance-web-client"
STATIC_ATTENDANCE_DIR="static/attendance"
# Convert DEBUG to lowercase for case-insensitive comparison
DEBUG_LOWER=$(echo "$DEBUG" | tr '[:upper:]' '[:lower:]')
# Check if the repository directory exists
if [ -d "$DIR_NAME" ]; then
echo "Directory $DIR_NAME already exists. Skipping git clone."
else
# Clone the repository
git clone $REPO_URL
fi
# Navigate to the project directory
cd $DIR_NAME || { echo "Failed to enter $DIR_NAME directory"; exit 1; }
# Install dependencies and build the project with yarn
yarn install && yarn build
# Check if the build was successful
if [ $? -eq 0 ]; then
# Clean the static/attendance directory
rm -rf ../$STATIC_ATTENDANCE_DIR/*
# Copy the built files to the static/attendance directory
cp -r dist/* ../$STATIC_ATTENDANCE_DIR/
echo "Build completed and files copied to $STATIC_ATTENDANCE_DIR."
else
echo "Yarn build failed."
fi
cd ..
# Define the files
source_file="static/attendance/index.html" # The file generated by parcel build
target_file="templates/attendance/index.html" # The file you want to update
# Extract the new filenames from the source file
new_runtime=$(grep -oP 'src="/index\.runtime\.[a-f0-9]+\.js"' "$source_file" | grep -oP 'index\.runtime\.[a-f0-9]+\.js')
new_css=$(grep -oP 'href="/index\.[a-f0-9]+\.css"' "$source_file" | grep -oP 'index\.[a-f0-9]+\.css')
new_index=$(grep -oP 'src="/index\.[a-f0-9]+\.js"' "$source_file" | grep -oP 'index\.[a-f0-9]+\.js' | tail -n 1)
# Update the target file
sed -i "s/index\.runtime\.[a-f0-9]\+\.js/$new_runtime/g" "$target_file"
sed -i "s/index\.[a-f0-9]\+\.css/$new_css/g" "$target_file"
sed -i "s/index\.[a-f0-9]\+\.js/$new_index/g" "$target_file"
echo "File names updated successfully."
if [ "$DEBUG_LOWER" = "false" ]; then
rm -rf ./$DIR_NAME
echo "Directory $STATIC_ATTENDANCE_DIR cleaned."
fi