# install_latest_aliases_v1.1.ps1 - cr?e uniquement des .cmd "latest" (et supprime les .ps1 qui posaient EP) param([switch]$Install) function Ensure-Dir([string]$p){ if($p -and !(Test-Path $p)){ New-Item -ItemType Directory -Force -Path $p | Out-Null } } $registry = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Definition) $bin = Join-Path $registry 'bin' $scripts = Join-Path $registry 'scripts' Ensure-Dir $bin # Nettoyage des anciens alias .ps1 Get-ChildItem -LiteralPath $bin -Filter '*_latest.ps1' -File -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue function New-LatestCmd([string]$aliasBase,[string]$pattern){ $cmdBin = Join-Path $bin ($aliasBase+'_latest.cmd') $cmdScr = Join-Path $scripts ($aliasBase+'_latest.cmd') # wrapper jumeau dans \scripts pour compatibilit? $template='@echo off setlocal set REG={REG} set SCRIPTS=%REG%\scripts set PATTERN={PAT} for /f "usebackq delims=" %%F in (`powershell -NoProfile -Command "function gv($([char]36)name){$([char]36)m=[regex]::Match($([char]36)name,''_v([0-9]+(?:\.[0-9]+)*)$''); if($([char]36)m.Success){[version]$([char]36)m.Groups[1].Value}else{[version]''0.0''}}; Get-ChildItem -LiteralPath ''%SCRIPTS%'' -Filter ''%PATTERN%'' -File | Sort-Object @{Expression={ gv ($([char]36)_.BaseName) };Descending=$true}, @{Expression={$([char]36)_.LastWriteTime};Descending=$true} | Select-Object -First 1 -Expand FullName"`) do set TARGET=%%F if not defined TARGET ( echo [ERR] Aucun script ne correspond a %PATTERN% dans %SCRIPTS% exit /b 1 ) powershell -NoProfile -ExecutionPolicy Bypass -File "%TARGET%" %* ' $codeBin = $template.Replace('{REG}',$registry).Replace('{PAT}',$pattern) [IO.File]::WriteAllText($cmdBin,$codeBin,[Text.ASCIIEncoding]::new()) [IO.File]::WriteAllText($cmdScr,$codeBin,[Text.ASCIIEncoding]::new()) "Alias CMD -> " + (Split-Path $cmdBin -Leaf) + " (pattern: "+$pattern+")" } $map = @( @{Alias='gov_profile_launcher'; Pattern='gov_profile_launcher_v*.ps1'} @{Alias='gov_dev_coach'; Pattern='gov_dev_coach_v*.ps1'} @{Alias='apply_kb_guard_asserts'; Pattern='apply_kb_guard_asserts_v*.ps1'} @{Alias='kb_guard_validator'; Pattern='kb_guard_validator_v*.ps1'} @{Alias='export_ingest_pack'; Pattern='export_ingest_pack_v*.ps1'} @{Alias='fix_manifest_sha'; Pattern='fix_manifest_sha_v*.ps1'} @{Alias='rebuild_bootpack_full_hub'; Pattern='rebuild_bootpack_full_hub_v*.ps1'} @{Alias='rebuild_bootpack_full_seedbox'; Pattern='rebuild_bootpack_full_seedbox_v*.ps1'} ) foreach($m in $map){ New-LatestCmd -aliasBase $m.Alias -pattern $m.Pattern | Write-Host } "OK - alias .cmd installes dans: $bin ET wrappers dans: $scripts"