From 73d9b969988ce2a067c359998e9fab94e9a51b18 Mon Sep 17 00:00:00 2001 From: zerosaturation Date: Mon, 13 Apr 2026 12:41:23 +0800 Subject: [PATCH] feat: add dev.sh main framework header Co-Authored-By: Claude Opus 4.6 --- backend/dev.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 backend/dev.sh diff --git a/backend/dev.sh b/backend/dev.sh new file mode 100755 index 0000000..950096e --- /dev/null +++ b/backend/dev.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Hot-Reload Dev Script for TopFans Backend +# Usage: ./dev.sh +# +# Requires: fswatch (Mac: brew install fswatch) or inotifywait (Linux) + +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +NC='\033[0m' + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +# Detect platform +if [[ "$(uname)" == "Darwin" ]]; then + WATCHER_TOOL="fswatch" + WATCHER_CMD="fswatch -r" +elif [[ "$(uname)" == "Linux" ]]; then + WATCHER_TOOL="inotifywait" + WATCHER_CMD="inotifywait -r -m -e modify,create,write" +else + echo -e "${RED}不支持的平台${NC}" + exit 1 +fi + +if ! command -v "$WATCHER_TOOL" &> /dev/null; then + echo -e "${RED}缺少工具: $WATCHER_TOOL${NC}" + if [[ "$(uname)" == "Darwin" ]]; then + echo "安装方法: brew install fswatch" + else + echo "安装方法: sudo apt install inotify-tools (Debian/Ubuntu)" + echo " sudo yum install inotify-tools (CentOS/RHEL)" + fi + exit 1 +fi + +ENV_FILE="$SCRIPT_DIR/.env" +if [ -f "$ENV_FILE" ]; then + echo -e "${GREEN}📄 加载 .env 文件...${NC}" + set -a + source "$ENV_FILE" + set +a +fi + +DB_HOST="${DB_HOST:-localhost}" +DB_PORT="${DB_PORT:-5432}" +DB_USER="${DB_USER:-haihuizhu}" +DB_PASSWORD="${DB_PASSWORD:-admin}" +DB_NAME="${DB_NAME:-top-fans}" +DB_ARGS=(-db-host="$DB_HOST" -db-port="$DB_PORT" -db-user="$DB_USER" -db-password="$DB_PASSWORD" -db-name="$DB_NAME") \ No newline at end of file