#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" PYTHON_BIN="$ROOT_DIR/.venv/bin/python" LAUNCHER="$ROOT_DIR/backend_embedded_launcher.py" APP_NAME="ManeshTraderBackend" BUILD_ROOT="$ROOT_DIR/dist-backend-build" DIST_PATH="$BUILD_ROOT/dist" WORK_PATH="$BUILD_ROOT/build" SPEC_PATH="$BUILD_ROOT/spec" TARGET_DIR="$ROOT_DIR/ManeshTraderMac/ManeshTraderMac/EmbeddedBackend" if [[ ! -x "$PYTHON_BIN" ]]; then echo "Missing virtual environment. Run ./run.sh --setup-only first." >&2 exit 1 fi if [[ ! -f "$LAUNCHER" ]]; then echo "Missing launcher file: $LAUNCHER" >&2 exit 1 fi mkdir -p "$DIST_PATH" "$WORK_PATH" "$SPEC_PATH" "$TARGET_DIR" "$PYTHON_BIN" -m pip install -q pyinstaller "$PYTHON_BIN" -m PyInstaller \ --noconfirm \ --clean \ --onefile \ --name "$APP_NAME" \ --distpath "$DIST_PATH" \ --workpath "$WORK_PATH" \ --specpath "$SPEC_PATH" \ --add-data "$ROOT_DIR/app.py:." \ --add-data "$ROOT_DIR/manesh_trader:manesh_trader" \ --add-data "$ROOT_DIR/ONBOARDING.md:." \ --collect-all streamlit \ --collect-all streamlit_autorefresh \ --hidden-import yfinance \ --hidden-import pandas \ --collect-all plotly \ --collect-all kaleido \ "$LAUNCHER" cp "$DIST_PATH/$APP_NAME" "$TARGET_DIR/$APP_NAME" chmod +x "$TARGET_DIR/$APP_NAME" echo "Embedded backend updated: $TARGET_DIR/$APP_NAME"