Refactor parameter handling in build and sign scripts for PowerShell 5.1 compatibility
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user