初始化

This commit is contained in:
2026-03-05 21:27:11 +08:00
commit 130de0fd5d
140 changed files with 21972 additions and 0 deletions

179
scripts/setup.sh Normal file
View File

@@ -0,0 +1,179 @@
#!/usr/bin/env bash
# =============================================================================
# Vibe Cursor Pro — 一键初始化脚本 (PHP Hyperf + Vue 3 双栈)
# =============================================================================
# 用法: bash scripts/setup.sh
# =============================================================================
set -euo pipefail
BLUE='\033[0;34m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo ""
echo -e "${BLUE}🚀 Vibe Cursor Pro — Setup (Dual Stack)${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# 1. 创建日志目录
echo -e "${BLUE}📁 Creating directories...${NC}"
mkdir -p .ai-logs/{decisions,costs,sessions,errors,guard}
echo " ✅ .ai-logs/"
# 2. 确保脚本可执行
chmod +x scripts/*.sh 2>/dev/null || true
# 3. 设置 Git Hooks
if [ -d ".git" ]; then
echo -e "${BLUE}🔗 Setting up Git hooks...${NC}"
mkdir -p .husky
git config core.hooksPath .husky
# Pre-commit hook
cat > .husky/pre-commit << 'EOF'
#!/usr/bin/env bash
bash scripts/ai-guard.sh --pre
EOF
chmod +x .husky/pre-commit
# Commit-msg hook (Conventional Commits)
cat > .husky/commit-msg << 'EOF'
#!/usr/bin/env bash
commit_regex='^(feat|fix|refactor|test|docs|chore|style|perf|ci|build|revert)(\(.+\))?: .{1,100}'
if ! grep -qE "$commit_regex" "$1"; then
echo "❌ Invalid commit message format!"
echo " Expected: type(scope): description"
echo " Example: feat(auth): add OAuth login"
exit 1
fi
EOF
chmod +x .husky/commit-msg
echo " ✅ Git hooks installed (.husky, core.hooksPath set)"
else
echo -e "${YELLOW}⚠️ Not a git repository, skipping hooks${NC}"
fi
# 4. 验证 Skills
echo -e "${BLUE}🧠 Validating Agent Skills...${NC}"
if [ -d ".cursor/skills" ]; then
SKILL_COUNT=0
for skill_dir in .cursor/skills/*/; do
[ -d "$skill_dir" ] && [ -f "$skill_dir/SKILL.md" ] && ((SKILL_COUNT++))
done
echo "$SKILL_COUNT skills found"
find .cursor/skills -name "*.sh" -exec chmod +x {} \; 2>/dev/null || true
else
echo -e "${YELLOW} ⚠️ No skills directory — creating .cursor/skills/${NC}"
mkdir -p .cursor/skills
fi
# 5. 检测前端环境
echo -e "${BLUE}🌐 Checking frontend environment...${NC}"
if command -v node &> /dev/null; then
NODE_VER=$(node --version)
echo -e "${GREEN} ✅ Node.js ${NODE_VER} detected${NC}"
else
echo -e "${YELLOW} ⚠️ Node.js not found — frontend needs Node.js 20+${NC}"
fi
if command -v npm &> /dev/null; then
NPM_VER=$(npm --version)
echo -e "${GREEN} ✅ npm ${NPM_VER} detected${NC}"
else
echo -e "${YELLOW} ⚠️ npm not found${NC}"
fi
# 6. 检测后端环境
echo -e "${BLUE}🐘 Checking backend environment...${NC}"
if command -v php &> /dev/null; then
PHP_VER=$(php -r 'echo PHP_VERSION;')
echo -e "${GREEN} ✅ PHP ${PHP_VER} detected${NC}"
# Check minimum version
PHP_MAJOR=$(echo "$PHP_VER" | cut -d. -f1)
PHP_MINOR=$(echo "$PHP_VER" | cut -d. -f2)
if [ "$PHP_MAJOR" -lt 8 ] || ([ "$PHP_MAJOR" -eq 8 ] && [ "$PHP_MINOR" -lt 1 ]); then
echo -e "${RED} ❌ PHP >= 8.1 required, found ${PHP_VER}${NC}"
fi
else
echo -e "${YELLOW} ⚠️ PHP not found — backend needs PHP >= 8.1${NC}"
fi
if command -v composer &> /dev/null; then
COMPOSER_VER=$(composer --version 2>/dev/null | head -1)
echo -e "${GREEN}${COMPOSER_VER}${NC}"
else
echo -e "${YELLOW} ⚠️ Composer not found — install from https://getcomposer.org${NC}"
fi
# Check Swoole extension
if php -m 2>/dev/null | grep -qi swoole; then
SWOOLE_VER=$(php -r 'echo swoole_version();' 2>/dev/null || echo 'unknown')
echo -e "${GREEN} ✅ Swoole ${SWOOLE_VER} detected${NC}"
else
echo -e "${YELLOW} ⚠️ Swoole extension not found — install via: pecl install swoole${NC}"
fi
# 7. 检测 Docker 环境
echo -e "${BLUE}🐳 Checking Docker environment...${NC}"
if command -v docker &> /dev/null; then
DOCKER_VER=$(docker --version 2>/dev/null | head -1)
echo -e "${GREEN}${DOCKER_VER}${NC}"
else
echo -e "${YELLOW} ⚠️ Docker not found (optional for local dev)${NC}"
fi
if docker compose version &> /dev/null; then
COMPOSE_VER=$(docker compose version 2>/dev/null | head -1)
echo -e "${GREEN}${COMPOSE_VER}${NC}"
else
echo -e "${YELLOW} ⚠️ Docker Compose not found (optional)${NC}"
fi
# 8. 安装依赖(如果目录存在)
for dir in Case-Database-Frontend-user Case-Database-Frontend-admin; do
if [ -f "$dir/package.json" ]; then
echo -e "${BLUE}📦 Installing $dir dependencies...${NC}"
(cd "$dir" && npm install) && echo "$dir dependencies installed" || echo -e "${RED}$dir install failed${NC}"
fi
done
if [ -f "Case-Database-Backend/composer.json" ]; then
echo -e "${BLUE}📦 Installing backend dependencies...${NC}"
(cd Case-Database-Backend && composer install --no-interaction) && echo " ✅ Backend dependencies installed" || echo -e "${RED} ❌ Backend install failed${NC}"
fi
# 9. 添加到 .gitignore
if [ -f ".gitignore" ]; then
for pattern in ".ai-logs/" ".env*" "!.env.example"; do
if ! grep -qF "$pattern" .gitignore; then
echo "$pattern" >> .gitignore
fi
done
echo " ✅ .gitignore updated"
fi
echo ""
echo -e "${GREEN}🎉 Setup complete!${NC}"
echo ""
echo "Next steps:"
echo " 1. Edit .cursor/mcp.json — fill in your API tokens"
echo " 2. Edit docs/vision/PRD.md — describe your project"
echo " 3. Open the project in Cursor"
echo " 4. Tell Cursor: 读取 docs/vision/PRD.md制定开发计划"
echo ""
echo "Development:"
echo " • Frontend: cd Case-Database-Frontend-user (or Case-Database-Frontend-admin) && npm run dev"
echo " • Backend: cd Case-Database-Backend && php bin/hyperf.php start"
echo " • Docker: docker compose up -d"
echo ""
echo "Skills system:"
echo " • Skills in .cursor/skills/"
echo " • Run 'bash scripts/skill-manager.sh validate' to validate skills"
echo " • Create new skills: ask Cursor \"创建新技能\""
echo ""