update-embedded-web.sh raw
1 #!/usr/bin/env bash
2 # scripts/update-embedded-web.sh
3 # Build the embedded smesh web client and then install the Go binary.
4 #
5 # This script will:
6 # - Build the Smesh client in app/smesh to app/smesh/dist
7 # - Run `go install` from the repository root so the binary picks up the new
8 # embedded assets.
9 #
10 # Note: The relay dashboard (app/web/) has been merged into smesh.
11 # Both app/web.go and app/smesh.go now serve from smesh/dist.
12 #
13 # Usage:
14 # ./scripts/update-embedded-web.sh
15 #
16 # Requirements:
17 # - Go 1.18+ installed (for `go install` and go:embed support)
18 # - Bun (https://bun.sh) recommended; alternatively Node.js with npm/yarn/pnpm
19 #
20 set -euo pipefail
21
22 # Resolve repo root to allow running from anywhere
23 SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
24 REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
25 SMESH_DIR="${REPO_ROOT}/app/smesh"
26
27 log() { printf "[update-embedded-web] %s\n" "$*"; }
28 err() { printf "[update-embedded-web][ERROR] %s\n" "$*" >&2; }
29
30 # Choose a JS package runner
31 JS_RUNNER=""
32 if command -v bun >/dev/null 2>&1; then
33 JS_RUNNER="bun"
34 elif command -v npm >/dev/null 2>&1; then
35 JS_RUNNER="npm"
36 elif command -v yarn >/dev/null 2>&1; then
37 JS_RUNNER="yarn"
38 elif command -v pnpm >/dev/null 2>&1; then
39 JS_RUNNER="pnpm"
40 else
41 err "No JavaScript package manager found. Install Bun (recommended) or npm/yarn/pnpm."
42 exit 1
43 fi
44
45 log "Using JavaScript runner: ${JS_RUNNER}"
46
47 # Helper: build a JS project in the given directory
48 build_js_project() {
49 local dir="$1"
50 local name="$2"
51
52 if [[ ! -d "${dir}" ]]; then
53 err "Expected ${name} directory at ${dir} not found."
54 exit 1
55 fi
56
57 log "Building ${name}..."
58 pushd "${dir}" >/dev/null
59 case "${JS_RUNNER}" in
60 bun)
61 bun install
62 bun run build
63 ;;
64 npm)
65 npm ci || npm install
66 npm run build
67 ;;
68 yarn)
69 yarn install --frozen-lockfile || yarn install
70 yarn build
71 ;;
72 pnpm)
73 pnpm install --frozen-lockfile || pnpm install
74 pnpm build
75 ;;
76 *)
77 err "Unsupported JS runner: ${JS_RUNNER}"
78 exit 1
79 ;;
80 esac
81 popd >/dev/null
82
83 local dist_dir="${dir}/dist"
84 if [[ ! -d "${dist_dir}" ]]; then
85 err "${name} build did not produce ${dist_dir}. Check the build configuration."
86 exit 1
87 fi
88 log "${name} build complete at ${dist_dir}."
89 }
90
91 # Build smesh client (React) — serves as both the client and the relay dashboard
92 build_js_project "${SMESH_DIR}" "smesh client"
93
94 # Install the Go binary so it embeds the latest files
95 log "Running 'go install' from repo root..."
96 pushd "${REPO_ROOT}" >/dev/null
97 GO111MODULE=on go install ./...
98 popd >/dev/null
99
100 log "Done. Your installed binary now includes the updated embedded smesh client."
101