# 诊断脚本 - 检查项目状态和问题 param( [switch]$Fix ) # 设置控制台编码为 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 "========================" -ForegroundColor Cyan Write-Host "" # 1. 检查 Node.js 和 npm Write-Host "1️⃣ 检查 Node.js 环境..." -ForegroundColor Yellow try { $nodeVersion = node --version 2>$null $npmVersion = npm --version 2>$null if ($nodeVersion) { Write-Host " ✅ Node.js: $nodeVersion" -ForegroundColor Green } else { Write-Host " ❌ Node.js 未安装或不在 PATH 中" -ForegroundColor Red } if ($npmVersion) { Write-Host " ✅ npm: $npmVersion" -ForegroundColor Green } else { Write-Host " ❌ npm 未安装或不在 PATH 中" -ForegroundColor Red } } catch { Write-Host " ❌ 检查 Node.js 环境失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # 2. 检查项目结构 Write-Host "2️⃣ 检查项目结构..." -ForegroundColor Yellow $requiredFiles = @( "package.json", "vue.config.js", "src/main/index.js", "src/renderer/main.js", "public/index.html" ) foreach ($file in $requiredFiles) { if (Test-Path $file) { Write-Host " ✅ $file" -ForegroundColor Green } else { Write-Host " ❌ $file (缺失)" -ForegroundColor Red } } Write-Host "" # 3. 检查依赖 Write-Host "3️⃣ 检查依赖..." -ForegroundColor Yellow if (Test-Path "node_modules") { Write-Host " ✅ node_modules 存在" -ForegroundColor Green # 检查关键依赖 $keyDependencies = @("vue", "electron", "@vue/cli-service") foreach ($dep in $keyDependencies) { $depPath = "node_modules/$dep" if (Test-Path $depPath) { Write-Host " ✅ $dep" -ForegroundColor Green } else { Write-Host " ❌ $dep (缺失)" -ForegroundColor Red } } } else { Write-Host " ❌ node_modules 不存在" -ForegroundColor Red } Write-Host "" # 4. 检查构建文件 Write-Host "4️⃣ 检查构建文件..." -ForegroundColor Yellow $buildFiles = @( "dist/renderer/index.html", "dist/renderer/js/index.js", "dist/renderer/js/vendors.js" ) $buildFilesExist = $true foreach ($file in $buildFiles) { if (Test-Path $file) { $size = (Get-Item $file).Length $sizeKB = [math]::Round($size / 1KB, 2) Write-Host " ✅ $file ($sizeKB KB)" -ForegroundColor Green } else { Write-Host " ❌ $file (缺失)" -ForegroundColor Red $buildFilesExist = $false } } Write-Host "" # 5. 检查构建文件内容 if ($buildFilesExist) { Write-Host "5️⃣ 检查构建文件内容..." -ForegroundColor Yellow $indexHtml = Get-Content "dist/renderer/index.html" -Raw if ($indexHtml -match "vendors\.js") { Write-Host " ✅ index.html 包含 vendors.js 引用" -ForegroundColor Green } else { Write-Host " ❌ index.html 缺少 vendors.js 引用" -ForegroundColor Red } if ($indexHtml -match "index\.js") { Write-Host " ✅ index.html 包含 index.js 引用" -ForegroundColor Green } else { Write-Host " ❌ index.html 缺少 index.js 引用" -ForegroundColor Red } } Write-Host "" # 6. 检查配置文件 Write-Host "6️⃣ 检查配置文件..." -ForegroundColor Yellow $vueConfig = Get-Content "vue.config.js" -Raw if ($vueConfig -match "publicPath.*['\""]\.\/['\""]") { Write-Host " ⚠️ vue.config.js 中的 publicPath 可能导致资源加载问题" -ForegroundColor Yellow } else { Write-Host " ✅ vue.config.js 配置正常" -ForegroundColor Green } Write-Host "" # 7. 总结和建议 Write-Host "📋 诊断总结" -ForegroundColor Cyan Write-Host "=============" -ForegroundColor Cyan $issues = @() if (-not (Test-Path "node_modules")) { $issues += "依赖未安装" } if (-not $buildFilesExist) { $issues += "构建文件缺失" } if ($issues.Count -eq 0) { Write-Host "✅ 项目状态良好,没有发现明显问题" -ForegroundColor Green } else { Write-Host "⚠️ 发现以下问题:" -ForegroundColor Yellow foreach ($issue in $issues) { Write-Host " • $issue" -ForegroundColor Red } } Write-Host "" # 8. 修复建议 Write-Host "🔧 修复建议" -ForegroundColor Cyan Write-Host "=============" -ForegroundColor Cyan Write-Host "1. 如果依赖缺失,运行: npm install" -ForegroundColor White Write-Host "2. 如果构建文件缺失,运行: npm run fix:build" -ForegroundColor White Write-Host "3. 如果问题持续,运行: npm run fix:rebuild" -ForegroundColor White Write-Host "4. 使用修复版启动脚本: npm run start:fixed" -ForegroundColor White if ($Fix) { Write-Host "" Write-Host "🔨 自动修复..." -ForegroundColor Yellow if (-not (Test-Path "node_modules")) { Write-Host " 安装依赖..." -ForegroundColor Yellow npm install } if (-not $buildFilesExist) { Write-Host " 重新构建..." -ForegroundColor Yellow npm run fix:build } Write-Host "✅ 修复完成!" -ForegroundColor Green }