|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [Parameter(Mandatory=$true)][ValidateSet('install','update','verify','remove','status')][string]$Action, |
| 4 | + [string]$Module = 'all' |
| 5 | +) |
| 6 | + |
| 7 | +Set-StrictMode -Version Latest |
| 8 | +$ErrorActionPreference = 'Stop' |
| 9 | +$Root = Split-Path -Parent $PSScriptRoot |
| 10 | +$Modules = Join-Path $Root 'modules' |
| 11 | + |
| 12 | +function Invoke-Script([string]$Path) { |
| 13 | + if (Test-Path $Path) { & bash $Path; if ($LASTEXITCODE -ne 0) { throw "Hook failed: $Path" } } |
| 14 | +} |
| 15 | + |
| 16 | +$dirs = if ($Module -eq 'all') { |
| 17 | + Get-ChildItem -Path $Modules -Directory -Recurse -Depth 1 |
| 18 | +} else { |
| 19 | + $p = Join-Path $Modules $Module |
| 20 | + if (-not (Test-Path $p)) { throw "Unknown module: $Module" } |
| 21 | + @(Get-Item $p) |
| 22 | +} |
| 23 | + |
| 24 | +foreach ($m in $dirs) { |
| 25 | + $install = Join-Path $m.FullName 'install.sh' |
| 26 | + $update = Join-Path $m.FullName 'update.sh' |
| 27 | + $verify = Join-Path $m.FullName 'verify.sh' |
| 28 | + $uninstall = Join-Path $m.FullName 'uninstall.sh' |
| 29 | + $stopBackend = Join-Path $m.FullName 'shutdown-backend.sh' |
| 30 | + $stopFrontend = Join-Path $m.FullName 'shutdown-frontend.sh' |
| 31 | + |
| 32 | + Write-Host "==> $Action $($m.Name)" |
| 33 | + switch ($Action) { |
| 34 | + 'install' { |
| 35 | + if (Test-Path $install) { Invoke-Script $install } |
| 36 | + elseif (Test-Path (Join-Path $m.FullName 'source/Makefile')) { make -C (Join-Path $m.FullName 'source') } |
| 37 | + elseif (Test-Path (Join-Path $m.FullName 'Makefile')) { make -C $m.FullName } |
| 38 | + elseif (Test-Path (Join-Path $m.FullName 'pom.xml')) { mvn -f (Join-Path $m.FullName 'pom.xml') package } |
| 39 | + else { Write-Host 'No install/build hook; source preserved.' } |
| 40 | + } |
| 41 | + 'update' { |
| 42 | + if (Test-Path $update) { Invoke-Script $update } else { & $PSCommandPath -Action install -Module $m.Name } |
| 43 | + } |
| 44 | + 'verify' { if (Test-Path $verify) { Invoke-Script $verify } else { Write-Host 'Lifecycle hooks:'; Write-Host " install=$([bool](Test-Path $install)) update=$([bool](Test-Path $update)) remove=$([bool](Test-Path $uninstall)) verify=$([bool](Test-Path $verify))" } } |
| 45 | + 'status' { & $PSCommandPath -Action verify -Module $m.Name } |
| 46 | + 'remove' { |
| 47 | + if (Test-Path $stopBackend) { Invoke-Script $stopBackend } |
| 48 | + if (Test-Path $stopFrontend) { Invoke-Script $stopFrontend } |
| 49 | + if (Test-Path $uninstall) { Invoke-Script $uninstall } |
| 50 | + foreach ($name in @('out','build','target')) { $p = Join-Path $m.FullName $name; if (Test-Path $p) { Remove-Item -Recurse -Force $p } } |
| 51 | + Get-ChildItem $m.FullName -Recurse -File -Include *.class,*.jar -ErrorAction SilentlyContinue | Remove-Item -Force |
| 52 | + Write-Host 'Source preserved; generated artifacts removed where recognized.' |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments