???param( [Parameter(Mandatory=$true)][string]$Base, # ex: write_devlock_debugkit_rule [Parameter(ValueFromRemainingArguments=$true)][string[]]$PassThruArgs ) try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding } catch {} $scriptPath = $MyInvocation.MyCommand.Definition $scriptDir = Split-Path -Parent $scriptPath $registry = Split-Path -Parent $scriptDir $dirScripts = Join-Path $registry 'scripts' $encGuard = Join-Path $dirScripts 'text_encoding_guard_latest.cmd' $psLint = Join-Path $dirScripts 'ps_script_linter_v1.0.ps1' function gv([string]$n){ $m=[regex]::Match($n,'_v([0-9]+(?:\.[0-9]+)*)$'); if($m.Success){ try { return [version]$m.Groups[1].Value } catch { return [version]'0.0' } } return [version]'0.0' } $pattern = $Base + '_v*.ps1' $files = Get-ChildItem -LiteralPath $dirScripts -Filter $pattern -File -ErrorAction SilentlyContinue if(-not $files){ Write-Host "[ERR] Aucun writer ne correspond a $pattern"; exit 1 } $best = $files | Sort-Object @{Expression={ gv $_.BaseName };Descending=$true}, @{Expression={$_.LastWriteTime};Descending=$true} | Select-Object -First 1 # 1) Execute writer & 'powershell.exe' -NoProfile -ExecutionPolicy Bypass -File $best.FullName @PassThruArgs 2>&1 | Write-Host $exit = $LASTEXITCODE # 2) Post-hook (Write only): encodage + lint $doWrite = ($PassThruArgs -contains '-Write') if($doWrite){ if(Test-Path $encGuard){ Write-Host "POST-HOOK: encoding guard (All -Write, manifest recalc off)." & $encGuard -Scope All -Write | Out-Null Write-Host "POST-HOOK: encoding report (All -Preview)." & $encGuard -Scope All -Preview | Out-Null } else { Write-Host "[WARN] encoding guard introuvable." } if(Test-Path $psLint){ Write-Host "POST-HOOK: PS script linter." & 'powershell.exe' -NoProfile -ExecutionPolicy Bypass -File $psLint -SummaryOnly $lintExit=$LASTEXITCODE if($lintExit -ne 0){ Write-Host "[BLOCK] Lint a detecte des anomalies dans scripts\*.ps1 (voir log). Commit refuse." exit 2 } } else { Write-Host "[WARN] ps_script_linter_v1.0.ps1 introuvable." } } exit $exit