Files
zclaw_openfang/scripts/quick-start-dev.ps1
iven 0d4fa96b82
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
refactor: 统一项目名称从OpenFang到ZCLAW
重构所有代码和文档中的项目名称,将OpenFang统一更新为ZCLAW。包括:
- 配置文件中的项目名称
- 代码注释和文档引用
- 环境变量和路径
- 类型定义和接口名称
- 测试用例和模拟数据

同时优化部分代码结构,移除未使用的模块,并更新相关依赖项。
2026-03-27 07:36:03 +08:00

226 lines
5.9 KiB
PowerShell
Raw 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.

#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 "停止所有服务..."
# 停止 ZCLAW
$zclaw = Get-Process -Name "zclaw" -ErrorAction SilentlyContinue
if ($zclaw) {
Stop-Process -Name "zclaw" -Force -ErrorAction SilentlyContinue
Write-Success "ZCLAW 已停止"
}
# 停止 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 "启动 ZCLAW 后端..."
# 尝试多种方式启动
$started = $false
# 方式 1: 使用 zclaw CLI
try {
$zclawCmd = Get-Command "zclaw" -ErrorAction SilentlyContinue
if ($zclawCmd) {
Start-Process -FilePath "zclaw" -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 "请手动启动 ZCLAW:"
Write-Host " zclaw 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 "请检查 ZCLAW 是否正确安装"
exit 1
}
}
}
# 5. 启动开发环境
Write-Step "启动开发环境..."
Push-Location $ProjectRoot
if ($DesktopOnly) {
Write-Host "仅启动桌面端..."
pnpm desktop
} else {
Write-Host "启动完整开发环境..."
pnpm start:dev
}
Pop-Location