Browse Source

环境对比

master
hejl 1 week ago
parent
commit
0831e0f3e0
  1. 149
      gofaster/check-environment.ps1

149
gofaster/check-environment.ps1

@ -0,0 +1,149 @@ @@ -0,0 +1,149 @@
# GoFaster 环境兼容性检查脚本
# 检查当前环境是否满足运行要求
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster 环境兼容性检查" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查 Node.js 版本
Write-Host "检查 Node.js 版本..." -ForegroundColor Yellow
try {
$nodeVersion = node --version
Write-Host "Node.js 版本: $nodeVersion" -ForegroundColor Green
# 检查版本兼容性
if ($nodeVersion -match "v(\d+)") {
$majorVersion = [int]$matches[1]
if ($majorVersion -lt 16) {
Write-Host " 警告: Node.js 版本过低,推荐使用 v16 或更高版本" -ForegroundColor Yellow
} elseif ($majorVersion -gt 20) {
Write-Host " 警告: Node.js 版本过高,可能存在兼容性问题" -ForegroundColor Yellow
} else {
Write-Host "✅ Node.js 版本兼容" -ForegroundColor Green
}
}
} catch {
Write-Host "❌ Node.js 未安装或不可用" -ForegroundColor Red
}
Write-Host ""
# 检查 npm 版本
Write-Host "检查 npm 版本..." -ForegroundColor Yellow
try {
$npmVersion = npm --version
Write-Host "npm 版本: $npmVersion" -ForegroundColor Green
# 检查版本兼容性
if ($npmVersion -match "(\d+)") {
$majorVersion = [int]$matches[1]
if ($majorVersion -lt 8) {
Write-Host " 警告: npm 版本过低,推荐使用 v8 或更高版本" -ForegroundColor Yellow
} elseif ($majorVersion -gt 10) {
Write-Host " 警告: npm 版本过高,可能存在兼容性问题" -ForegroundColor Yellow
} else {
Write-Host "✅ npm 版本兼容" -ForegroundColor Green
}
}
} catch {
Write-Host "❌ npm 未安装或不可用" -ForegroundColor Red
}
Write-Host ""
# 检查 Go 版本
Write-Host "检查 Go 版本..." -ForegroundColor Yellow
try {
$goVersion = go version
Write-Host "Go 版本: $goVersion" -ForegroundColor Green
# 检查版本兼容性
if ($goVersion -match "go(\d+\.\d+)") {
$version = [version]$matches[1]
if ($version -lt [version]"1.20") {
Write-Host " 警告: Go 版本过低,推荐使用 v1.20 或更高版本" -ForegroundColor Yellow
} elseif ($version -gt [version]"1.25") {
Write-Host " 警告: Go 版本过高,可能存在兼容性问题" -ForegroundColor Yellow
} else {
Write-Host "✅ Go 版本兼容" -ForegroundColor Green
}
}
} catch {
Write-Host "❌ Go 未安装或不可用" -ForegroundColor Red
}
Write-Host ""
# 检查项目结构
Write-Host "检查项目结构..." -ForegroundColor Yellow
$requiredDirs = @("app", "backend")
$missingDirs = @()
foreach ($dir in $requiredDirs) {
if (Test-Path $dir) {
Write-Host "✅ 目录存在: $dir" -ForegroundColor Green
} else {
Write-Host "❌ 目录缺失: $dir" -ForegroundColor Red
$missingDirs += $dir
}
}
Write-Host ""
# 检查前端依赖
Write-Host "检查前端依赖..." -ForegroundColor Yellow
if (Test-Path "app/package.json") {
Write-Host "✅ 前端 package.json 存在" -ForegroundColor Green
if (Test-Path "app/node_modules") {
Write-Host "✅ 前端依赖已安装" -ForegroundColor Green
} else {
Write-Host " 前端依赖未安装,需要运行: cd app && npm install" -ForegroundColor Yellow
}
} else {
Write-Host "❌ 前端 package.json 不存在" -ForegroundColor Red
}
Write-Host ""
# 检查后端依赖
Write-Host "检查后端依赖..." -ForegroundColor Yellow
if (Test-Path "backend/go.mod") {
Write-Host "✅ 后端 go.mod 存在" -ForegroundColor Green
} else {
Write-Host "❌ 后端 go.mod 不存在" -ForegroundColor Red
}
Write-Host ""
# 检查端口占用
Write-Host "检查端口占用..." -ForegroundColor Yellow
$ports = @(8080, 3000)
foreach ($port in $ports) {
$processes = netstat -ano 2>$null | Select-String ":$port\s"
if ($processes) {
Write-Host " 端口 $port 被占用" -ForegroundColor Yellow
} else {
Write-Host "✅ 端口 $port 可用" -ForegroundColor Green
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "检查完成!" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
# 提供修复建议
if ($missingDirs.Count -gt 0) {
Write-Host ""
Write-Host "🔧 修复建议:" -ForegroundColor Yellow
Write-Host " 1. 确保项目结构完整" -ForegroundColor White
Write-Host " 2. 重新克隆或下载项目" -ForegroundColor White
}
Write-Host ""
Write-Host "💡 启动建议:" -ForegroundColor Cyan
Write-Host " 1. 使用 .\start-enhanced.ps1 启动完整环境" -ForegroundColor White
Write-Host " 2. 使用 .\start-enhanced.ps1 -BackendOnly 仅启动后端" -ForegroundColor White
Write-Host " 3. 使用 .\start-enhanced.ps1 -FrontendOnly 仅启动前端" -ForegroundColor White
Write-Host " 4. 使用 .\start-enhanced.ps1 -ForceClean 强制清理后启动" -ForegroundColor White
Loading…
Cancel
Save