-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintegrate-local-center.sh
More file actions
executable file
·98 lines (83 loc) · 2.53 KB
/
Copy pathintegrate-local-center.sh
File metadata and controls
executable file
·98 lines (83 loc) · 2.53 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
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
./integrate-local-center.sh <path-to-local-center-repo> [build|serve] [hugo-server-args...]
Examples:
./integrate-local-center.sh /Users/adam/code/aipin/openPin/center
./integrate-local-center.sh /Users/adam/code/aipin/openPin/center build
./integrate-local-center.sh /Users/adam/code/aipin/openPin/center serve
./integrate-local-center.sh /Users/adam/code/aipin/openPin/center serve --disableFastRender
Modes:
build Build center artifacts, stage them into Hugo static/, then run ./setup.sh
serve Build center artifacts, stage them into Hugo static/, then run hugo server
EOF
}
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
CENTER_REPO_INPUT="$1"
MODE="${2:-build}"
shift || true
if [[ $# -gt 0 ]]; then
shift || true
fi
HUGO_SERVER_ARGS=("$@")
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CENTER_REPO="$(cd "$CENTER_REPO_INPUT" && pwd)"
if [[ ! -d "$CENTER_REPO" ]]; then
echo "Center repo path does not exist: $CENTER_REPO_INPUT" >&2
exit 1
fi
if [[ ! -f "$CENTER_REPO/package.json" ]]; then
echo "Center repo path does not contain package.json: $CENTER_REPO" >&2
exit 1
fi
if [[ ! -f "$SCRIPT_DIR/setup.sh" ]]; then
echo "Expected setup.sh in website repo root: $SCRIPT_DIR" >&2
exit 1
fi
if [[ "$MODE" != "build" && "$MODE" != "serve" ]]; then
echo "Invalid mode: $MODE" >&2
usage
exit 1
fi
INSTALL_TARGET="$SCRIPT_DIR/static/install"
CENTER_TARGET="$SCRIPT_DIR/static/center"
DIST_HUGO_DIR="$CENTER_REPO/dist-hugo"
printf '\n==> Building center Hugo artifacts from %s\n' "$CENTER_REPO"
(
cd "$CENTER_REPO"
npm run build:hugo-static
)
if [[ ! -d "$DIST_HUGO_DIR/install" || ! -d "$DIST_HUGO_DIR/center" ]]; then
echo "Expected dist-hugo/install and dist-hugo/center after build." >&2
exit 1
fi
printf '\n==> Staging generated app artifacts into website/static\n'
rm -rf "$INSTALL_TARGET" "$CENTER_TARGET"
mkdir -p "$INSTALL_TARGET" "$CENTER_TARGET"
cp -R "$DIST_HUGO_DIR/install/." "$INSTALL_TARGET/"
cp -R "$DIST_HUGO_DIR/center/." "$CENTER_TARGET/"
if [[ "$MODE" == "build" ]]; then
printf '\n==> Building website and Pagefind index\n'
(
cd "$SCRIPT_DIR"
./setup.sh
)
printf '\nBuild complete. Validate these outputs locally:\n'
printf ' %s/public/install/\n' "$SCRIPT_DIR"
printf ' %s/public/center/\n' "$SCRIPT_DIR"
else
printf '\n==> Starting Hugo server\n'
(
cd "$SCRIPT_DIR"
if [[ ${#HUGO_SERVER_ARGS[@]} -gt 0 ]]; then
hugo server "${HUGO_SERVER_ARGS[@]}"
else
hugo server
fi
)
fi