docs: add setup guides and error notification component
- Add OpenFang Kernel configuration guide (docs/setup/OPENFANG-SETUP.md) - Add Chinese models configuration guide (docs/setup/chinese-models.md) - Add quick start guide (docs/quick-start.md) - Add quick start scripts for Windows and Linux/macOS - Add ErrorNotification component for centralized error display These additions help users: - Quickly set up development environment - Configure OpenFang backend correctly - Configure Chinese LLM providers (GLM, Qwen, Kimi, MiniMax) - See error notifications in a consistent UI Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
225
scripts/quick-start-dev.ps1
Normal file
225
scripts/quick-start-dev.ps1
Normal file
@@ -0,0 +1,225 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
ZCLAW 开发环境快速启动脚本
|
||||
|
||||
.DESCRIPTION
|
||||
检查依赖、启动后端服务、启动桌面端开发环境
|
||||
|
||||
.PARAMETER SkipBackend
|
||||
跳过后端启动(假设后端已运行)
|
||||
|
||||
.PARAMETER DesktopOnly
|
||||
仅启动桌面端
|
||||
|
||||
.PARAMETER Stop
|
||||
停止所有服务
|
||||
|
||||
.EXAMPLE
|
||||
.\scripts\quick-start-dev.ps1
|
||||
.\scripts\quick-start-dev.ps1 -SkipBackend
|
||||
.\scripts\quick-start-dev.ps1 -Stop
|
||||
#>
|
||||
|
||||
param(
|
||||
[switch]$SkipBackend,
|
||||
[switch]$DesktopOnly,
|
||||
[switch]$Stop
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ProjectRoot = $PSScriptRoot | Split-Path -Parent
|
||||
|
||||
# 颜色输出函数
|
||||
function Write-Step {
|
||||
param([string]$Message)
|
||||
Write-Host "`n[STEP] $Message" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
function Write-Success {
|
||||
param([string]$Message)
|
||||
Write-Host "[OK] $Message" -ForegroundColor Green
|
||||
}
|
||||
|
||||
function Write-Warning {
|
||||
param([string]$Message)
|
||||
Write-Host "[WARN] $Message" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
function Write-Error {
|
||||
param([string]$Message)
|
||||
Write-Host "[ERROR] $Message" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# 停止服务
|
||||
if ($Stop) {
|
||||
Write-Step "停止所有服务..."
|
||||
|
||||
# 停止 OpenFang
|
||||
$openfang = Get-Process -Name "openfang" -ErrorAction SilentlyContinue
|
||||
if ($openfang) {
|
||||
Stop-Process -Name "openfang" -Force -ErrorAction SilentlyContinue
|
||||
Write-Success "OpenFang 已停止"
|
||||
}
|
||||
|
||||
# 停止 Vite
|
||||
$vite = Get-Process -Name "node" -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowTitle -like "*vite*" -or $_.CommandLine -like "*vite*" }
|
||||
if ($vite) {
|
||||
$vite | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Write-Success "Vite 进程已停止"
|
||||
}
|
||||
|
||||
# 调用项目的停止脚本
|
||||
$stopScript = Join-Path $ProjectRoot "start-all.ps1"
|
||||
if (Test-Path $stopScript) {
|
||||
& $stopScript -Stop
|
||||
}
|
||||
|
||||
Write-Success "所有服务已停止"
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host " ZCLAW Development Quick Start" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
|
||||
# 1. 检查 Node.js
|
||||
Write-Step "检查 Node.js..."
|
||||
try {
|
||||
$nodeVersion = node -v
|
||||
if ($nodeVersion -match "v(\d+)") {
|
||||
$majorVersion = [int]$Matches[1]
|
||||
if ($majorVersion -lt 18) {
|
||||
Write-Error "Node.js 版本过低: $nodeVersion (需要 18+)"
|
||||
Write-Host "请从 https://nodejs.org 安装最新版本"
|
||||
exit 1
|
||||
}
|
||||
Write-Success "Node.js $nodeVersion"
|
||||
}
|
||||
} catch {
|
||||
Write-Error "未找到 Node.js,请从 https://nodejs.org 安装"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 2. 检查 pnpm
|
||||
Write-Step "检查 pnpm..."
|
||||
try {
|
||||
$pnpmVersion = pnpm -v
|
||||
Write-Success "pnpm $pnpmVersion"
|
||||
} catch {
|
||||
Write-Warning "未找到 pnpm,正在安装..."
|
||||
npm install -g pnpm
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "pnpm 安装失败"
|
||||
exit 1
|
||||
}
|
||||
Write-Success "pnpm 安装完成"
|
||||
}
|
||||
|
||||
# 3. 检查依赖安装
|
||||
Write-Step "检查依赖..."
|
||||
$nodeModules = Join-Path $ProjectRoot "node_modules"
|
||||
$desktopModules = Join-Path $ProjectRoot "desktop\node_modules"
|
||||
|
||||
if (-not (Test-Path $nodeModules)) {
|
||||
Write-Host "安装根目录依赖..."
|
||||
Push-Location $ProjectRoot
|
||||
pnpm install
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
if (-not (Test-Path $desktopModules)) {
|
||||
Write-Host "安装桌面端依赖..."
|
||||
Push-Location (Join-Path $ProjectRoot "desktop")
|
||||
pnpm install
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Write-Success "依赖已就绪"
|
||||
|
||||
# 4. 检查/启动后端
|
||||
if (-not $SkipBackend -and -not $DesktopOnly) {
|
||||
Write-Step "检查后端服务..."
|
||||
|
||||
$backendRunning = $false
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri "http://127.0.0.1:50051/api/health" -TimeoutSec 2 -UseBasicParsing -ErrorAction SilentlyContinue
|
||||
if ($response.StatusCode -eq 200) {
|
||||
$backendRunning = $true
|
||||
Write-Success "后端服务已运行"
|
||||
}
|
||||
} catch {
|
||||
# 后端未运行
|
||||
}
|
||||
|
||||
if (-not $backendRunning) {
|
||||
Write-Host "启动 OpenFang 后端..."
|
||||
|
||||
# 尝试多种方式启动
|
||||
$started = $false
|
||||
|
||||
# 方式 1: 使用 openfang CLI
|
||||
try {
|
||||
$openfangCmd = Get-Command "openfang" -ErrorAction SilentlyContinue
|
||||
if ($openfangCmd) {
|
||||
Start-Process -FilePath "openfang" -ArgumentList "start" -NoNewWindow
|
||||
$started = $true
|
||||
}
|
||||
} catch {}
|
||||
|
||||
# 方式 2: 使用 pnpm 脚本
|
||||
if (-not $started) {
|
||||
$startScript = Join-Path $ProjectRoot "start-all.ps1"
|
||||
if (Test-Path $startScript) {
|
||||
Start-Process -FilePath "powershell" -ArgumentList "-ExecutionPolicy", "Bypass", "-File", $startScript -NoNewWindow
|
||||
$started = $true
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $started) {
|
||||
Write-Error "无法启动后端服务"
|
||||
Write-Host "请手动启动 OpenFang:"
|
||||
Write-Host " openfang start"
|
||||
Write-Host " 或运行 start-all.ps1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 等待后端启动
|
||||
Write-Host "等待后端启动..."
|
||||
$retries = 0
|
||||
$maxRetries = 15
|
||||
while ($retries -lt $maxRetries) {
|
||||
Start-Sleep -Seconds 1
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri "http://127.0.0.1:50051/api/health" -TimeoutSec 2 -UseBasicParsing -ErrorAction SilentlyContinue
|
||||
if ($response.StatusCode -eq 200) {
|
||||
Write-Success "后端服务启动成功"
|
||||
break
|
||||
}
|
||||
} catch {}
|
||||
$retries++
|
||||
Write-Host "." -NoNewline
|
||||
}
|
||||
|
||||
if ($retries -ge $maxRetries) {
|
||||
Write-Error "后端启动超时"
|
||||
Write-Host "请检查 OpenFang 是否正确安装"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 5. 启动开发环境
|
||||
Write-Step "启动开发环境..."
|
||||
|
||||
Push-Location $ProjectRoot
|
||||
|
||||
if ($DesktopOnly) {
|
||||
Write-Host "仅启动桌面端..."
|
||||
pnpm desktop
|
||||
} else {
|
||||
Write-Host "启动完整开发环境..."
|
||||
pnpm start:dev
|
||||
}
|
||||
|
||||
Pop-Location
|
||||
Reference in New Issue
Block a user