feat: Refactor service management scripts to use a unified dev script
- Added package.json to manage development scripts. - Updated restart-services.ps1 to call the new dev script for starting services. - Refactored start-admin.ps1, start-backend.ps1, start-frontend.ps1, and start-mcp.ps1 to utilize the dev script for starting respective services. - Enhanced stop-services.ps1 to improve process termination logic by matching command patterns.
This commit is contained in:
@@ -16,23 +16,24 @@ if (@($FrontendOnly, $BackendOnly, $AdminOnly, $McpOnly).Where({ $_ }).Count -gt
|
||||
|
||||
function Stop-RepoShells {
|
||||
param(
|
||||
[string]$ScriptName
|
||||
[string[]]$CommandPatterns
|
||||
)
|
||||
|
||||
$shells = Get-CimInstance Win32_Process | Where-Object {
|
||||
$commandLine = $_.CommandLine
|
||||
($_.Name -in @("powershell.exe", "pwsh.exe")) -and
|
||||
$_.CommandLine -and
|
||||
$_.CommandLine.Contains($repoRoot) -and
|
||||
$_.CommandLine.Contains($ScriptName)
|
||||
$commandLine.Contains($repoRoot) -and
|
||||
($CommandPatterns | Where-Object { $commandLine.Contains($_) }).Count -gt 0
|
||||
}
|
||||
|
||||
foreach ($shell in $shells) {
|
||||
try {
|
||||
Stop-Process -Id $shell.ProcessId -Force -ErrorAction Stop
|
||||
Write-Host "[stop] Closed shell for $ScriptName (PID $($shell.ProcessId))." -ForegroundColor Yellow
|
||||
Write-Host "[stop] Closed matching shell (PID $($shell.ProcessId))." -ForegroundColor Yellow
|
||||
}
|
||||
catch {
|
||||
Write-Warning "[stop] Failed to close shell for $ScriptName (PID $($shell.ProcessId)): $($_.Exception.Message)"
|
||||
Write-Warning "[stop] Failed to close matching shell (PID $($shell.ProcessId)): $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,22 +68,22 @@ function Stop-PortOwner {
|
||||
}
|
||||
|
||||
function Stop-Frontend {
|
||||
Stop-RepoShells -ScriptName "start-frontend.ps1"
|
||||
Stop-RepoShells -CommandPatterns @("start-frontend.ps1", "dev.ps1", "-Only frontend")
|
||||
Stop-PortOwner -Port 4321 -Label "frontend"
|
||||
}
|
||||
|
||||
function Stop-Backend {
|
||||
Stop-RepoShells -ScriptName "start-backend.ps1"
|
||||
Stop-RepoShells -CommandPatterns @("start-backend.ps1", "dev.ps1", "-Only backend")
|
||||
Stop-PortOwner -Port 5150 -Label "backend"
|
||||
}
|
||||
|
||||
function Stop-Admin {
|
||||
Stop-RepoShells -ScriptName "start-admin.ps1"
|
||||
Stop-RepoShells -CommandPatterns @("start-admin.ps1", "dev.ps1", "-Only admin")
|
||||
Stop-PortOwner -Port 4322 -Label "admin"
|
||||
}
|
||||
|
||||
function Stop-Mcp {
|
||||
Stop-RepoShells -ScriptName "start-mcp.ps1"
|
||||
Stop-RepoShells -CommandPatterns @("start-mcp.ps1", "dev.ps1", "-Only mcp")
|
||||
Stop-PortOwner -Port 5151 -Label "MCP"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user