You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

133 lines
4.8 KiB

# GoFaster 增强版全栈启动脚本
param(
[switch]$ForceClean,
[switch]$Debug,
[switch]$Watch
)
# 设置控制台编码为 UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
# 设置环境变量
$env:LANG = "zh_CN.UTF-8"
$env:LC_ALL = "zh_CN.UTF-8"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster Enhanced Startup" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 强制清理模式
if ($ForceClean) {
Write-Host "🧹 强制清理模式..." -ForegroundColor Magenta
Write-Host "清理 node_modules..." -ForegroundColor Yellow
if (Test-Path "app/node_modules") {
Remove-Item -Recurse -Force "app/node_modules"
}
if (Test-Path "app/dist") {
Remove-Item -Recurse -Force "app/dist"
}
Write-Host "✅ 清理完成" -ForegroundColor Green
Write-Host ""
}
# 检查并安装前端依赖
Write-Host "📦 检查前端依赖..." -ForegroundColor Yellow
if (-not (Test-Path "app/node_modules")) {
Write-Host " 前端依赖未安装,正在安装..." -ForegroundColor Yellow
Set-Location "app"
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ 前端依赖安装失败" -ForegroundColor Red
exit 1
}
Set-Location ".."
}
# 生成路由映射文件
Write-Host "🔧 生成路由映射文件..." -ForegroundColor Yellow
Set-Location "app"
try {
node scripts/generate-route-mappings.js
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ 路由映射生成失败" -ForegroundColor Red
exit 1
}
Write-Host "✅ 路由映射生成成功" -ForegroundColor Green
} catch {
Write-Host "❌ 路由映射生成失败: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Set-Location ".."
# 检查后端依赖
Write-Host "📦 检查后端依赖..." -ForegroundColor Yellow
if (-not (Test-Path "backend/go.mod")) {
Write-Host "❌ 后端 Go 模块未找到" -ForegroundColor Red
exit 1
}
# 检查 Air 是否安装
try {
$airVersion = air -v 2>$null
if (-not $airVersion) {
Write-Host "📦 安装 Air..." -ForegroundColor Yellow
go install github.com/air-verse/air@latest
}
} catch {
Write-Host "📦 安装 Air..." -ForegroundColor Yellow
go install github.com/air-verse/air@latest
}
Write-Host "✅ 依赖检查完成" -ForegroundColor Green
Write-Host ""
# 选择启动模式
$frontendScript = if ($Debug) { "npm run dev:debug" } elseif ($Watch) { "npm run dev:watch" } else { "npm run dev:watch" }
Write-Host "🚀 启动服务..." -ForegroundColor Green
Write-Host "前端脚本: $frontendScript" -ForegroundColor Cyan
Write-Host ""
# 启动后端
Write-Host " 启动后端热重载..." -ForegroundColor Green
$backendProcess = Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; air" -WindowStyle Normal -PassThru
Write-Host "后端已启动 (PID: $($backendProcess.Id))" -ForegroundColor Green
# 等待后端启动
Write-Host "⏳ 等待后端启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 3
# 检查后端是否启动成功
try {
$response = Invoke-WebRequest -Uri "http://localhost:8080/health" -Method GET -TimeoutSec 5 -ErrorAction Stop
if ($response.StatusCode -eq 200) {
Write-Host "✅ 后端启动成功" -ForegroundColor Green
}
} catch {
Write-Host " 后端可能仍在启动中,继续启动前端..." -ForegroundColor Yellow
}
# 启动前端
Write-Host " 启动前端热重载..." -ForegroundColor Green
$frontendProcess = Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd app; $frontendScript" -WindowStyle Normal -PassThru
Write-Host "前端已启动 (PID: $($frontendProcess.Id))" -ForegroundColor Green
Write-Host ""
Write-Host "🎉 服务启动完成!" -ForegroundColor Green
Write-Host ""
Write-Host "📍 服务地址:" -ForegroundColor Yellow
Write-Host " 后端: http://localhost:8080" -ForegroundColor Cyan
Write-Host " Swagger: http://localhost:8080/swagger/index.html" -ForegroundColor Cyan
Write-Host " 前端: Electron 应用 (自动重载已启用)" -ForegroundColor Cyan
Write-Host ""
Write-Host "🔧 管理命令:" -ForegroundColor Yellow
Write-Host " 停止后端: Stop-Process -Id $($backendProcess.Id)" -ForegroundColor White
Write-Host " 停止前端: Stop-Process -Id $($frontendProcess.Id)" -ForegroundColor White
Write-Host " 停止所有: Get-Process | Where-Object {$_.ProcessName -eq 'powershell'} | Stop-Process" -ForegroundColor White
Write-Host ""
Write-Host "💡 提示: 代码更改将自动触发重建和重载!" -ForegroundColor Yellow
Write-Host "按任意键退出..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")