|
|
|
# GoFaster Full Stack Development Environment
|
|
|
|
param(
|
|
|
|
[switch]$Debug,
|
|
|
|
[switch]$Watch,
|
|
|
|
[switch]$BackendOnly,
|
|
|
|
[switch]$FrontendOnly
|
|
|
|
)
|
|
|
|
|
|
|
|
# Set console encoding
|
|
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
|
|
|
|
# Set environment variables
|
|
|
|
$env:VUE_CLI_BABEL_TRANSPILE_MODULES = "false"
|
|
|
|
$env:VUE_CLI_MODERN_BUILD = "false"
|
|
|
|
$env:VUE_CLI_LOG_LEVEL = "info"
|
|
|
|
$env:VUE_CLI_DEBUG = "true"
|
|
|
|
$env:LANG = "zh_CN.UTF-8"
|
|
|
|
$env:LC_ALL = "zh_CN.UTF-8"
|
|
|
|
$env:NODE_OPTIONS = "--max-old-space-size=4096"
|
|
|
|
|
|
|
|
# Display startup information
|
|
|
|
Write-Host "Starting GoFaster Full Stack Development Environment..." -ForegroundColor Cyan
|
|
|
|
Write-Host "Encoding: UTF-8" -ForegroundColor Green
|
|
|
|
Write-Host "Log Level: INFO" -ForegroundColor Green
|
|
|
|
Write-Host "Hot Reload: Enabled" -ForegroundColor Green
|
|
|
|
Write-Host ""
|
|
|
|
Write-Host "Frontend: Electron + Vue.js with Enhanced Hot Reload" -ForegroundColor Green
|
|
|
|
Write-Host "Backend: Go + Gin with Air Hot Reload" -ForegroundColor Green
|
|
|
|
Write-Host ""
|
|
|
|
|
|
|
|
# Check run mode
|
|
|
|
if ($Debug) {
|
|
|
|
Write-Host "Debug mode starting..." -ForegroundColor Magenta
|
|
|
|
$env:DEBUG = "*"
|
|
|
|
} elseif ($Watch) {
|
|
|
|
Write-Host "Watch mode starting..." -ForegroundColor Blue
|
|
|
|
} else {
|
|
|
|
Write-Host "Standard mode starting..." -ForegroundColor Green
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host ""
|
|
|
|
|
|
|
|
# Check dependencies
|
|
|
|
Write-Host "Checking frontend dependencies..." -ForegroundColor Yellow
|
|
|
|
if (-not (Test-Path "app/node_modules")) {
|
|
|
|
Write-Host "Frontend dependencies not installed, installing..." -ForegroundColor Yellow
|
|
|
|
Set-Location "app"
|
|
|
|
npm install
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
Write-Host "Frontend dependency installation failed" -ForegroundColor Red
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
Set-Location ".."
|
|
|
|
}
|
|
|
|
|
|
|
|
# Install cross-env if not exists
|
|
|
|
$crossEnvInstalled = npm list cross-env 2>$null -Path "app"
|
|
|
|
if (-not $crossEnvInstalled) {
|
|
|
|
Write-Host "Installing cross-env..." -ForegroundColor Yellow
|
|
|
|
Set-Location "app"
|
|
|
|
npm install --save-dev cross-env
|
|
|
|
Set-Location ".."
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Frontend dependency check completed" -ForegroundColor Green
|
|
|
|
Write-Host ""
|
|
|
|
|
|
|
|
# Check backend dependencies
|
|
|
|
Write-Host "Checking backend dependencies..." -ForegroundColor Yellow
|
|
|
|
if (-not (Test-Path "backend/go.mod")) {
|
|
|
|
Write-Host "Backend Go module not found" -ForegroundColor Red
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if air is installed
|
|
|
|
try {
|
|
|
|
$airVersion = air -v 2>$null
|
|
|
|
if (-not $airVersion) {
|
|
|
|
Write-Host "Air not installed, installing..." -ForegroundColor Yellow
|
|
|
|
go install github.com/air-verse/air@latest
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
Write-Host "Air not installed, installing..." -ForegroundColor Yellow
|
|
|
|
go install github.com/air-verse/air@latest
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Backend dependency check completed" -ForegroundColor Green
|
|
|
|
Write-Host ""
|
|
|
|
|
|
|
|
# Select startup mode - 修复:默认使用watch模式确保热重载
|
|
|
|
$frontendScript = if ($Debug) { "npm run dev:debug" } elseif ($Watch) { "npm run dev:watch" } else { "npm run dev:watch" }
|
|
|
|
$backendScript = "air"
|
|
|
|
|
|
|
|
# Start services
|
|
|
|
if (-not $FrontendOnly) {
|
|
|
|
Write-Host "Starting backend hot reload..." -ForegroundColor Green
|
|
|
|
$backendProcess = Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; $backendScript" -WindowStyle Normal -PassThru
|
|
|
|
Write-Host "Backend started (PID: $($backendProcess.Id))" -ForegroundColor Green
|
|
|
|
|
|
|
|
# Wait for backend to start
|
|
|
|
Write-Host "Waiting for backend to start..." -ForegroundColor Yellow
|
|
|
|
Start-Sleep -Seconds 3
|
|
|
|
|
|
|
|
# Check if backend started successfully
|
|
|
|
try {
|
|
|
|
$response = Invoke-WebRequest -Uri "http://localhost:8080/health" -Method GET -TimeoutSec 5 -ErrorAction Stop
|
|
|
|
if ($response.StatusCode -eq 200) {
|
|
|
|
Write-Host "Backend started successfully" -ForegroundColor Green
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
Write-Host "Backend might still be starting, continuing with frontend..." -ForegroundColor Yellow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-not $BackendOnly) {
|
|
|
|
Write-Host "Starting frontend hot reload..." -ForegroundColor Green
|
|
|
|
Write-Host "Using script: $frontendScript" -ForegroundColor Cyan
|
|
|
|
$frontendProcess = Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd app; $frontendScript" -WindowStyle Normal -PassThru
|
|
|
|
Write-Host "Frontend started (PID: $($frontendProcess.Id))" -ForegroundColor Green
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host ""
|
|
|
|
Write-Host "Service startup completed!" -ForegroundColor Green
|
|
|
|
|
|
|
|
if (-not $BackendOnly) {
|
|
|
|
Write-Host "Backend: http://localhost:8080" -ForegroundColor Cyan
|
|
|
|
Write-Host "Swagger: http://localhost:8080/swagger/index.html" -ForegroundColor Cyan
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-not $FrontendOnly) {
|
|
|
|
Write-Host "Frontend: Electron app (auto-reload enabled)" -ForegroundColor Cyan
|
|
|
|
Write-Host "Note: Frontend now uses watch mode by default for better hot reload" -ForegroundColor Yellow
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host ""
|
|
|
|
Write-Host "Usage:" -ForegroundColor Yellow
|
|
|
|
Write-Host " - Use -Debug parameter to enable detailed debug info" -ForegroundColor White
|
|
|
|
Write-Host " - Use -Watch parameter to explicitly enable file watching" -ForegroundColor White
|
|
|
|
Write-Host " - Use -BackendOnly to start only backend" -ForegroundColor White
|
|
|
|
Write-Host " - Use -FrontendOnly to start only frontend" -ForegroundColor White
|
|
|
|
Write-Host " - Press Ctrl+C to stop services" -ForegroundColor White
|
|
|
|
Write-Host ""
|
|
|
|
|
|
|
|
# Display process information
|
|
|
|
if (-not $BackendOnly -and -not $FrontendOnly) {
|
|
|
|
Write-Host "Process Information:" -ForegroundColor Yellow
|
|
|
|
Write-Host " Backend PID: $($backendProcess.Id)" -ForegroundColor White
|
|
|
|
Write-Host " Frontend PID: $($frontendProcess.Id)" -ForegroundColor White
|
|
|
|
Write-Host ""
|
|
|
|
Write-Host "Management Commands:" -ForegroundColor Yellow
|
|
|
|
Write-Host " Stop Backend: Stop-Process -Id $($backendProcess.Id)" -ForegroundColor White
|
|
|
|
Write-Host " Stop Frontend: Stop-Process -Id $($frontendProcess.Id)" -ForegroundColor White
|
|
|
|
Write-Host " Stop All: Get-Process | Where-Object {$_.ProcessName -eq 'powershell'} | Stop-Process" -ForegroundColor White
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Code changes will automatically trigger rebuilds and reloads!" -ForegroundColor Yellow
|
|
|
|
Write-Host "Frontend now uses watch mode by default for better hot reload experience" -ForegroundColor Green
|
|
|
|
Write-Host "Press any key to exit..."
|
|
|
|
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|