Refactor parameter handling in build and sign scripts for PowerShell 5.1 compatibility

This commit is contained in:
2026-02-25 08:34:44 +11:00
parent 3fb8e98eed
commit 5c5a8b3b4c
3 changed files with 47 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
[CmdletBinding()]
param(
[string]$SourceScript = (Join-Path $PSScriptRoot 'caffeine.ps1'),
[string]$OutputDir = (Join-Path $PSScriptRoot 'dist'),
[string]$BuildDir = (Join-Path $PSScriptRoot 'build'),
[string]$SourceScript,
[string]$OutputDir,
[string]$BuildDir,
[string]$ExeName = 'PortableCaffeine.exe',
[switch]$ConsoleTarget,
[switch]$KeepExtractedSource
@@ -11,6 +11,26 @@ param(
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# In Windows PowerShell 5.1, $PSScriptRoot may be empty during param default evaluation.
# Resolve script-relative defaults after the param block for compatibility.
$scriptRoot = if (-not [string]::IsNullOrWhiteSpace($PSScriptRoot)) {
$PSScriptRoot
} elseif ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} else {
(Get-Location).Path
}
if ([string]::IsNullOrWhiteSpace($SourceScript)) {
$SourceScript = Join-Path $scriptRoot 'caffeine.ps1'
}
if ([string]::IsNullOrWhiteSpace($OutputDir)) {
$OutputDir = Join-Path $scriptRoot 'dist'
}
if ([string]::IsNullOrWhiteSpace($BuildDir)) {
$BuildDir = Join-Path $scriptRoot 'build'
}
function Get-CSharpFromCaffeineScript {
param(
[Parameter(Mandatory = $true)]