param([switch]$Full) function WriteUtf8NoBom([string]$p,[string]$t){ $enc = New-Object System.Text.UTF8Encoding($false) [IO.File]::WriteAllText($p,$t,$enc) } function Get-Version([string]$name){ $m=[regex]::Match($name,'_v([0-9]+(?:\.[0-9]+)*)\.ps1$') if($m.Success){ try { return [version]$m.Groups[1].Value } catch { return [version]"0.0" } } return [version]"0.0" } try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding } catch {} $here = $PSScriptRoot; if(-not $here){ $here = Split-Path -Parent $MyInvocation.MyCommand.Path } $registry = Split-Path -Parent $here $dirScripts = Join-Path $registry "scripts" $dirBin = Join-Path $registry "bin" $dirReports = Join-Path $registry "reports" if(!(Test-Path $dirReports)){ New-Item -ItemType Directory -Force -Path $dirReports | Out-Null } # Bases critiques align?es avec le dashboard $critical = @( "gov_profile_launcher","rebuild_bootpack_full_hub","rebuild_bootpack_full_seedbox", "writer_posthook_runner","text_encoding_guard","ps_script_linter","safe_write_text", "write_devlock_debugkit_rule","project_profile_echo","encoding_policy_resolver","view_utf8", "run_encoding_maintenance","ps_scripts_sanitize_and_quarantine","gov_pipeline_guard", "kb_guard_validator","kb_emit_bootpack_dual","export_bootpack_txt","fix_manifest_sha","kb_quicklog_and_sync" ) # Optionnel: inclure toutes les bases trouv?es si -Full $allBases = New-Object System.Collections.Generic.HashSet[string] foreach($b in $critical){ [void]$allBases.Add($b) } if($Full){ $all = Get-ChildItem -LiteralPath $dirScripts -Filter "*_v*.ps1" -File -EA SilentlyContinue | ForEach-Object { $_.BaseName -replace "_v[0-9.]+$","" } | Sort-Object -Unique foreach($b in $all){ [void]$allBases.Add($b) } } $madeShims=0; $madeAliases=0 foreach($base in $allBases){ $pattern = $base + "_v*.ps1" $cands = Get-ChildItem -LiteralPath $dirScripts -Filter $pattern -File -EA SilentlyContinue if(-not $cands){ $unv = Join-Path $dirScripts ($base + ".ps1") if(Test-Path $unv){ $shimName = $base + "_v1.0.ps1" $shimPath = Join-Path $dirScripts $shimName if(-not (Test-Path $shimPath)){ $shim = "@`n`# shim -> calls unversioned "+$base+".ps1`n" + "$here = Split-Path -Parent `$MyInvocation.MyCommand.Path`n" + "$root = Split-Path -Parent $here`n" + "$target = Join-Path (Join-Path $root 'scripts') '"+$base+".ps1'`n" + "powershell -NoProfile -ExecutionPolicy Bypass -File `"$target`" @args`n" WriteUtf8NoBom $shimPath $shim $madeShims++ } $cands = Get-ChildItem -LiteralPath $dirScripts -Filter $pattern -File -EA SilentlyContinue } } if($cands){ $best = ($cands | Sort-Object @{Expression={ Get-Version $_.Name };Descending=$true}, @{Expression={$_.LastWriteTime};Descending=$true} | Select-Object -First 1) if($best){ $aliasPath = Join-Path $dirBin ($base+"_latest.cmd") $cmd = '@echo off'+"`r`n"+ 'setlocal'+"`r`n"+ 'set "SELF=%~dp0"'+"`r`n"+ 'for %%I in ("%SELF%..") do set "ROOT=%%~fI"'+"`r`n"+ 'powershell -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\'+$best.Name+'" %*'+"`r`n" [IO.File]::WriteAllText($aliasPath,$cmd,[Text.ASCIIEncoding]::new()) $madeAliases++ } } } Write-Host ("Shims created: "+$madeShims) Write-Host ("Aliases created/updated: "+$madeAliases) # Post: normalisation d'encodage (scripts) si l'alias existe $encGuard = Join-Path $dirBin "text_encoding_guard_latest.cmd" if(Test-Path $encGuard){ & $encGuard -Scope Scripts -Write | Out-Null } # Post: relancer dashboard $dash = Join-Path $dirBin "scripts_baseline_dashboard_latest.cmd" if(Test-Path $dash){ & $dash }