Skip to content

Commit d785e6c

Browse files
committed
feat(scripts): 默认单终端启动并保留多窗口选项
将 start.ps1 默认改为单终端模式,后端后台启动并在前端退出后自动回收,降低本地启动时多窗口干扰;同时提供 -MultiWindow 参数兼容原双窗口习惯,并在更新日志中记录行为变更与回归关注点。 Made-with: Cursor
1 parent 15adb69 commit d785e6c

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
所有重要变更记录在此文件中。
44

5+
## [0.0.6] - 2026-04-18
6+
7+
### 变更
8+
- 启动脚本 `start.ps1` 调整为默认单终端模式:后端改为后台进程启动、前端在当前终端前台运行;结束前端后会自动回收后端进程。
9+
- 增加 `-MultiWindow` 参数用于按需恢复双窗口启动(后端窗口 + 前端窗口),兼容多终端日志分离场景。
10+
- 单终端模式新增运行日志落盘:后端标准输出/错误分别写入 `.run/backend.out.log``.run/backend.err.log`,便于排查启动异常。
11+
12+
### 影响范围与回归关注点
13+
- 本地启动默认行为发生变化:执行 `.\start.ps1` 不再弹出两个 PowerShell 窗口;如需旧行为请使用 `.\start.ps1 -MultiWindow`
14+
- 建议回归验证:`Ctrl+C` 结束前端后,确认后端进程被自动停止;后端启动失败时确认日志文件可用于定位问题。
15+
516
## [0.0.5] - 2026-04-18
617

718
### 变更

start.ps1

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
param(
22
[switch]$SkipInstall,
3-
[switch]$VerboseCheck
3+
[switch]$VerboseCheck,
4+
[switch]$MultiWindow
45
)
56

67
$ErrorActionPreference = "Stop"
@@ -82,15 +83,59 @@ function Stop-BackendProcessOnPort([int]$Port) {
8283

8384
Stop-BackendProcessOnPort -Port 5000
8485

85-
Write-Host "Starting backend window..." -ForegroundColor Green
86-
Write-Check "backend command: dotnet run --project $backendProject"
87-
Start-Process -FilePath "powershell.exe" -WorkingDirectory $repoRoot -ArgumentList "-NoExit", "-Command", "dotnet run --project '$backendProject'" | Out-Null
86+
if (-not $MultiWindow) {
87+
Write-Host "Starting backend in current terminal mode..." -ForegroundColor Green
88+
Write-Check "backend command: dotnet run --project $backendProject"
8889

89-
Write-Host "Starting frontend window..." -ForegroundColor Green
90-
Write-Check "frontend command: npm run -w platform-admin dev"
91-
Start-Process -FilePath "powershell.exe" -WorkingDirectory $frontendDir -ArgumentList "-NoExit", "-Command", "npm run -w platform-admin dev" | Out-Null
90+
$runDir = Join-Path $repoRoot ".run"
91+
if (-not (Test-Path -LiteralPath $runDir)) {
92+
New-Item -ItemType Directory -Path $runDir | Out-Null
93+
}
94+
95+
$backendStdOut = Join-Path $runDir "backend.out.log"
96+
$backendStdErr = Join-Path $runDir "backend.err.log"
97+
98+
$backendProc = Start-Process -FilePath "dotnet" `
99+
-WorkingDirectory $repoRoot `
100+
-ArgumentList @("run", "--project", $backendProject) `
101+
-RedirectStandardOutput $backendStdOut `
102+
-RedirectStandardError $backendStdErr `
103+
-PassThru
104+
105+
Start-Sleep -Seconds 2
106+
if ($backendProc.HasExited) {
107+
throw "Backend failed to start. Check logs: $backendStdOut / $backendStdErr"
108+
}
109+
110+
Write-Host "Backend started (PID: $($backendProc.Id)). Logs: $backendStdOut" -ForegroundColor DarkGray
111+
Write-Host "Starting frontend in current terminal..." -ForegroundColor Green
112+
Write-Check "frontend command: npm run -w platform-admin dev"
113+
114+
try {
115+
Set-Location -LiteralPath $frontendDir
116+
npm run -w platform-admin dev
117+
}
118+
finally {
119+
Set-Location -LiteralPath $repoRoot
120+
if (-not $backendProc.HasExited) {
121+
Write-Host "Stopping backend process (PID: $($backendProc.Id))..." -ForegroundColor Yellow
122+
Stop-Process -Id $backendProc.Id -Force
123+
}
124+
}
125+
}
126+
else {
127+
Write-Host "Starting backend window..." -ForegroundColor Green
128+
Write-Check "backend command: dotnet run --project $backendProject"
129+
Start-Process -FilePath "powershell.exe" -WorkingDirectory $repoRoot -ArgumentList "-NoExit", "-Command", "dotnet run --project '$backendProject'" | Out-Null
130+
131+
Write-Host "Starting frontend window..." -ForegroundColor Green
132+
Write-Check "frontend command: npm run -w platform-admin dev"
133+
Start-Process -FilePath "powershell.exe" -WorkingDirectory $frontendDir -ArgumentList "-NoExit", "-Command", "npm run -w platform-admin dev" | Out-Null
134+
135+
Write-Host "Started backend + frontend." -ForegroundColor Green
136+
}
92137

93-
Write-Host "Started backend + frontend." -ForegroundColor Green
94138
Write-Host "Fast mode: & .\start.ps1 -SkipInstall" -ForegroundColor DarkGray
139+
Write-Host "Multi-window mode: & .\start.ps1 -MultiWindow" -ForegroundColor DarkGray
95140
Write-Host "Frontend dev (no module sync): cd frontend; npm run dev:fast" -ForegroundColor DarkGray
96141
Write-Host "Debug mode: & .\start.ps1 -VerboseCheck" -ForegroundColor DarkGray

0 commit comments

Comments
 (0)