-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·80 lines (69 loc) · 1.44 KB
/
build.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
#!/bin/bash
BUILD_DIR="./target"
BACKEND_DIR="./backend"
BACKEND_BUILD_BIN="$BACKEND_DIR/target/release/hyde-backend"
FRONTEND_DIR="./frontend"
FRONTEND_BUILD="$FRONTEND_DIR/build"
check_target() {
if [ -d $BUILD_DIR ]; then
echo "Target folder exists, clearing for rebuild"
rm -rf "${BUILD_DIR:?}/"*
return
fi
mkdir $BUILD_DIR
}
build_frontend() {
echo "Building frontend"
(
cd $FRONTEND_DIR || exit && npm i && npm run build
)
}
build_backend() {
echo "Building backend"
(
cd $BACKEND_DIR || exit
cargo build --release
)
}
copy_build() {
echo "Copying builds to target build folder"
mkdir -p "$BUILD_DIR/web" && cp -r "$FRONTEND_BUILD/"* "$BUILD_DIR/web"
cp "$BACKEND_BUILD_BIN" "$BUILD_DIR/hyde"
}
copy_hyde_data() {
echo "Copying hyde data"
cp -r "$1" "$BUILD_DIR"
}
main() {
check_target
build_frontend
build_backend
copy_build
}
while getopts ":c:h" opt; do
case ${opt} in
c )
if [ ! -d "$OPTARG" ]; then
echo "Error: The specified directory '$OPTARG' does not exist."
exit 1
fi
main
copy_hyde_data "$OPTARG"
;;
h )
echo "Options: build.sh [-c {hyde-data folder}]"
;;
: )
echo "Error: Option -$OPTARG requires an argument."
exit 1
;;
\? )
echo "Invalid option: -$OPTARG"
exit 1
;;
esac
done
# If no options were provided, run the main function
if [ $OPTIND -eq 1 ]; then
main
fi