build.sh
1.08 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
#!/usr/bin/env bash
set -u
set -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$SCRIPT_DIR"
DIST_DIR="$PROJECT_DIR/dist"
DEPLOY_DIR="$PROJECT_DIR/../runing/html/dist"
echo "[1/3] Building frontend..."
if ! yarn build:ci; then
echo "Build failed."
exit 1
fi
if [[ ! -d "$DIST_DIR" ]]; then
echo "Build output not found: \"$DIST_DIR\""
exit 1
fi
echo "[2/3] Preparing deploy directory..."
if [[ -d "$DEPLOY_DIR" ]]; then
rm -rf "$DEPLOY_DIR"
if [[ -d "$DEPLOY_DIR" ]]; then
echo "Failed to remove old deploy directory: \"$DEPLOY_DIR\""
exit 1
fi
fi
if ! mkdir -p "$DEPLOY_DIR"; then
echo "Failed to create deploy directory: \"$DEPLOY_DIR\""
exit 1
fi
echo "[3/3] Copying dist to deploy directory..."
if command -v rsync >/dev/null 2>&1; then
if ! rsync -a "$DIST_DIR"/ "$DEPLOY_DIR"/; then
echo "Deploy copy failed."
exit 1
fi
else
if ! cp -a "$DIST_DIR"/. "$DEPLOY_DIR"/; then
echo "Deploy copy failed."
exit 1
fi
fi
echo "Deploy completed."
echo "Source: \"$DIST_DIR\""
echo "Target: \"$DEPLOY_DIR\""
exit 0