62 lines
1.6 KiB
Bash
Executable File
62 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build release Flutter web for VM hosting.
|
|
# API URL: shell API_BASE_URL > hosting/hosting.env API_PUBLIC_URL >
|
|
# server/.env API_BASE_URL > default https://cyberhybridhub.com
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
if [ -f "$ROOT/scripts/flutter-env.sh" ]; then
|
|
# shellcheck source=/dev/null
|
|
source "$ROOT/scripts/flutter-env.sh"
|
|
fi
|
|
|
|
if ! command -v flutter >/dev/null 2>&1; then
|
|
echo "flutter not found. Install Flutter or set FLUTTER_ROOT, then:" >&2
|
|
echo " source scripts/flutter-env.sh" >&2
|
|
exit 1
|
|
fi
|
|
|
|
_CLI_OVERRIDE="${API_BASE_URL:-}"
|
|
|
|
_load_env_api_url() {
|
|
local file=$1
|
|
[ -f "$file" ] || return 0
|
|
local line
|
|
line="$(grep -E '^API_BASE_URL=' "$file" 2>/dev/null | tail -1 || true)"
|
|
[ -n "$line" ] || return 0
|
|
line="${line#API_BASE_URL=}"
|
|
line="${line%\"}"
|
|
line="${line#\"}"
|
|
printf '%s' "$line"
|
|
}
|
|
|
|
API_BASE_URL="https://cyberhybridhub.com"
|
|
|
|
_server_api="$(_load_env_api_url "$ROOT/server/.env")"
|
|
if [ -n "$_server_api" ]; then
|
|
API_BASE_URL="$_server_api"
|
|
fi
|
|
|
|
if [ -f "$ROOT/hosting/hosting.env" ]; then
|
|
# shellcheck source=/dev/null
|
|
source "$ROOT/hosting/hosting.env"
|
|
API_BASE_URL="${API_PUBLIC_URL:-$API_BASE_URL}"
|
|
fi
|
|
|
|
if [ -n "$_CLI_OVERRIDE" ]; then
|
|
API_BASE_URL="$_CLI_OVERRIDE"
|
|
fi
|
|
|
|
echo "Building release web with API_BASE_URL=$API_BASE_URL"
|
|
flutter build web --release \
|
|
--dart-define=API_BASE_URL="$API_BASE_URL" \
|
|
--dart-define=AUTH_VERBOSE_LOG=true
|
|
|
|
if [ -x "$ROOT/scripts/copy_flutter_js_source_map.sh" ]; then
|
|
"$ROOT/scripts/copy_flutter_js_source_map.sh" "$ROOT/build/web" || true
|
|
fi
|
|
|
|
echo "Done: $ROOT/build/web"
|