[CmdletBinding()] param() $ErrorActionPreference = 'Stop' $projectPath = Split-Path -Parent $MyInvocation.MyCommand.Path $runtimePath = Join-Path $projectPath 'storage\framework\demo-runtime' $statePath = Join-Path $runtimePath 'state.json' $mysqlStop = 'C:\xampp\mysql_stop.bat' $windowsPath = $env:Path Remove-Item Env:PATH -ErrorAction SilentlyContinue $env:Path = $windowsPath function Stop-ProcessTree { param([Nullable[int]]$ProcessId) if (-not $ProcessId) { return } $children = Get-CimInstance Win32_Process -Filter "ParentProcessId = $ProcessId" -ErrorAction SilentlyContinue foreach ($child in $children) { Stop-ProcessTree -ProcessId $child.ProcessId } Stop-Process -Id $ProcessId -Force -ErrorAction SilentlyContinue } if (-not (Test-Path -LiteralPath $statePath)) { Write-Host 'Não existe uma demonstração iniciada pelos scripts.' -ForegroundColor Yellow exit 0 } $state = Get-Content -LiteralPath $statePath -Raw | ConvertFrom-Json Write-Host 'A encerrar a demonstração MAKOMBE...' -ForegroundColor Cyan Stop-ProcessTree -ProcessId $state.cloudflaredPid Stop-ProcessTree -ProcessId $state.laravelPid if ($state.mysqlStartedByDemo -and (Test-Path -LiteralPath $mysqlStop)) { Write-Host 'A parar o MySQL iniciado pela demonstração...' Start-Process -FilePath $mysqlStop -WindowStyle Hidden -Wait | Out-Null } else { Write-Host 'O MySQL já estava ativo e será mantido ligado.' -ForegroundColor DarkGray } Remove-Item -LiteralPath $statePath -Force Write-Host 'Demonstração encerrada.' -ForegroundColor Green