Files
planet/scripts/bootstrap-dev.sh
rayd1o c4ea918fac fix: refine earth hud structure and bun startup flow
- refactor the /earth HUD into class-first CSS layers with dedicated base, hud, and toolbar responsibilities
- clean up Earth markup and runtime DOM hooks so shared panel, toolbar, tooltip, and status classes stay consistent after dynamic updates
- keep HUD scaling configurable through extracted constants and remove leftover legacy panel/toolbar styling paths
- make planet.sh self-bootstrap Bun and uv by prepending local runtime bins to PATH and auto-installing missing tools in fresh environments
- document Bun as the frontend package manager of record and sync repository version metadata to 0.24.1
2026-04-09 02:12:22 +08:00

128 lines
3.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
BLUE='\033[0;34m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
have_cmd() {
command -v "$1" >/dev/null 2>&1
}
ensure_local_bin_on_path() {
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.bun/bin:$PATH"
}
install_uv_if_needed() {
if have_cmd uv; then
echo -e "${GREEN}uv 已存在: $(command -v uv)${NC}"
return
fi
echo -e "${BLUE}安装 uv...${NC}"
curl -LsSf https://astral.sh/uv/install.sh | sh
ensure_local_bin_on_path
if ! have_cmd uv; then
echo -e "${RED}uv 安装失败,请手动检查 ~/.local/bin 是否加入 PATH${NC}"
exit 1
fi
}
install_bun_if_needed() {
if have_cmd bun; then
echo -e "${GREEN}bun 已存在: $(command -v bun)${NC}"
return
fi
echo -e "${BLUE}安装 bun...${NC}"
curl -fsSL https://bun.sh/install | bash
ensure_local_bin_on_path
if ! have_cmd bun; then
echo -e "${RED}bun 安装失败,请手动检查 ~/.bun/bin 是否加入 PATH${NC}"
exit 1
fi
}
ensure_python_alias() {
mkdir -p "$HOME/.local/bin"
if [ ! -e "$HOME/.local/bin/python" ]; then
ln -sf /usr/bin/python3 "$HOME/.local/bin/python"
fi
ensure_local_bin_on_path
}
sync_python_env() {
echo -e "${BLUE}同步 Python 依赖...${NC}"
cd "$ROOT_DIR"
uv python install 3.14
uv sync --group dev
}
sync_frontend_env() {
echo -e "${BLUE}同步前端依赖...${NC}"
cd "$ROOT_DIR/frontend"
bun install
}
ensure_env_files() {
echo -e "${BLUE}检查环境变量模板...${NC}"
if [ ! -f "$ROOT_DIR/backend/.env" ] && [ -f "$ROOT_DIR/backend/.env.example" ]; then
cp "$ROOT_DIR/backend/.env.example" "$ROOT_DIR/backend/.env"
echo -e "${YELLOW}已创建 backend/.env请按需修改 SECRET_KEY / 数据库 / AI 服务配置${NC}"
fi
if [ ! -f "$ROOT_DIR/aiprovider/.env" ] && [ -f "$ROOT_DIR/aiprovider/.env.example" ]; then
cp "$ROOT_DIR/aiprovider/.env.example" "$ROOT_DIR/aiprovider/.env"
echo -e "${YELLOW}已创建 aiprovider/.env请按需修改 provider/model/api key${NC}"
fi
if [ ! -f "$ROOT_DIR/frontend/.env.local" ] && [ -f "$ROOT_DIR/frontend/.env.example" ]; then
cp "$ROOT_DIR/frontend/.env.example" "$ROOT_DIR/frontend/.env.local"
echo -e "${YELLOW}已创建 frontend/.env.local可按需覆盖 VITE_API_URL / VITE_WS_URL${NC}"
fi
}
report_optional_tools() {
if have_cmd docker; then
echo -e "${GREEN}docker 已存在: $(command -v docker)${NC}"
else
echo -e "${YELLOW}未检测到 docker。如需容器方式启动 backend/aiprovider请安装 Docker。${NC}"
fi
}
print_next_steps() {
echo ""
echo -e "${GREEN}开发环境引导完成${NC}"
echo "下一步建议:"
echo " 1. cd \"$ROOT_DIR\""
echo " 2. uv run pytest backend/tests/test_api.py -q -s"
echo " 3. cd \"$ROOT_DIR/frontend\" && bun run build"
echo " 4. cd \"$ROOT_DIR\" && ./planet.sh start"
echo ""
echo "前端统一使用 Bun不使用 npm/pnpm/yarn。"
}
main() {
ensure_local_bin_on_path
install_uv_if_needed
install_bun_if_needed
ensure_python_alias
sync_python_env
sync_frontend_env
ensure_env_files
report_optional_tools
print_next_steps
}
main "$@"