|
|
# 修复后的启动脚本 - 解决资源加载问题 |
|
|
param( |
|
|
[switch]$Debug, |
|
|
[switch]$Watch |
|
|
) |
|
|
|
|
|
# 设置控制台编码为 UTF-8 |
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 |
|
|
[Console]::InputEncoding = [System.Text.Encoding]::UTF8 |
|
|
$OutputEncoding = [System.Text.Encoding]::UTF8 |
|
|
|
|
|
Write-Host "🚀 启动 GoFaster (修复版)..." -ForegroundColor Cyan |
|
|
Write-Host "" |
|
|
|
|
|
# 检查依赖 |
|
|
Write-Host "📦 检查依赖..." -ForegroundColor Yellow |
|
|
if (-not (Test-Path "node_modules")) { |
|
|
Write-Host "⚠️ 依赖未安装,正在安装..." -ForegroundColor Yellow |
|
|
npm install |
|
|
if ($LASTEXITCODE -ne 0) { |
|
|
Write-Host "❌ 依赖安装失败" -ForegroundColor Red |
|
|
exit 1 |
|
|
} |
|
|
} |
|
|
|
|
|
# 检查构建文件 |
|
|
Write-Host "📁 检查构建文件..." -ForegroundColor Yellow |
|
|
$indexHtml = "dist/renderer/index.html" |
|
|
$indexJs = "dist/renderer/js/index.js" |
|
|
$vendorsJs = "dist/renderer/js/vendors.js" |
|
|
|
|
|
$needBuild = $false |
|
|
if (-not (Test-Path $indexHtml)) { |
|
|
Write-Host "❌ index.html 不存在" -ForegroundColor Red |
|
|
$needBuild = $true |
|
|
} |
|
|
if (-not (Test-Path $indexJs)) { |
|
|
Write-Host "❌ index.js 不存在" -ForegroundColor Red |
|
|
$needBuild = $true |
|
|
} |
|
|
if (-not (Test-Path $vendorsJs)) { |
|
|
Write-Host "❌ vendors.js 不存在" -ForegroundColor Red |
|
|
$needBuild = $true |
|
|
} |
|
|
|
|
|
if ($needBuild) { |
|
|
Write-Host "🔨 需要重新构建..." -ForegroundColor Yellow |
|
|
npm run fix:build |
|
|
if ($LASTEXITCODE -ne 0) { |
|
|
Write-Host "❌ 构建失败" -ForegroundColor Red |
|
|
exit 1 |
|
|
} |
|
|
} else { |
|
|
Write-Host "✅ 构建文件已存在" -ForegroundColor Green |
|
|
} |
|
|
|
|
|
Write-Host "" |
|
|
Write-Host "🎯 启动应用..." -ForegroundColor Cyan |
|
|
|
|
|
# 选择运行模式 |
|
|
if ($Debug) { |
|
|
Write-Host "🐛 调试模式启动..." -ForegroundColor Magenta |
|
|
$env:DEBUG = "*" |
|
|
$script = "npm run dev:debug" |
|
|
} elseif ($Watch) { |
|
|
Write-Host "👀 监听模式启动..." -ForegroundColor Blue |
|
|
$script = "npm run dev:watch" |
|
|
} else { |
|
|
Write-Host "🚀 标准模式启动..." -ForegroundColor Green |
|
|
$script = "npm run dev" |
|
|
} |
|
|
|
|
|
Write-Host "" |
|
|
Write-Host "💡 提示:" -ForegroundColor Cyan |
|
|
Write-Host " - 使用 -Debug 参数启用详细调试信息" -ForegroundColor White |
|
|
Write-Host " - 使用 -Watch 参数启用文件监听" -ForegroundColor White |
|
|
Write-Host " - 按 Ctrl+C 停止服务" -ForegroundColor White |
|
|
Write-Host "" |
|
|
|
|
|
# 启动服务 |
|
|
Write-Host "▶️ 执行命令: $script" -ForegroundColor Yellow |
|
|
Write-Host "" |
|
|
|
|
|
try { |
|
|
Invoke-Expression $script |
|
|
} catch { |
|
|
Write-Host "❌ 启动失败: $($_.Exception.Message)" -ForegroundColor Red |
|
|
Write-Host "" |
|
|
Write-Host "🔧 故障排除:" -ForegroundColor Yellow |
|
|
Write-Host " 1. 运行: npm run fix:rebuild" -ForegroundColor White |
|
|
Write-Host " 2. 检查 Node.js 版本 (推荐 v16+)" -ForegroundColor White |
|
|
Write-Host " 3. 清除 node_modules 并重新安装" -ForegroundColor White |
|
|
Write-Host " 4. 检查端口占用情况" -ForegroundColor White |
|
|
exit 1 |
|
|
}
|
|
|
|