From fc44def0ad47af6ad297f5f243c44d6cc67a4051 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sun, 6 Nov 2022 11:32:22 +0330 Subject: [PATCH] make powershell scripts consistent --- scripts/build.ps1 | 4 ++-- scripts/update.ps1 | 34 +++++++++++++++---------------- scripts/utils.ps1 | 6 +++--- vendor/bin/cmder_diag.ps1 | 2 +- vendor/psmodules/PsGet/PsGet.psm1 | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 4d3c96b..cab8849 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -88,7 +88,7 @@ if ($Compile) { Pop-Location } -if (-Not $noVendor) { +if (-not $noVendor) { # Check for requirements Ensure-Exists $sourcesPath Ensure-Executable "7z" @@ -162,7 +162,7 @@ if (-Not $noVendor) { Pop-Location } -if (-Not $Compile -Or $noVendor) { +if (-not $Compile -or $noVendor) { Write-Warning "You are not building the full project, Use -Compile without -noVendor" Write-Warning "This cannot be a release. Test build only!" return diff --git a/scripts/update.ps1 b/scripts/update.ps1 index b7ac73c..9eea219 100644 --- a/scripts/update.ps1 +++ b/scripts/update.ps1 @@ -55,7 +55,7 @@ function Match-Filenames { $position = 0 - if ([String]::IsNullOrEmpty($filename) -Or [String]::IsNullOrEmpty($filenameDownload)) { + if ([String]::IsNullOrEmpty($filename) -or [String]::IsNullOrEmpty($filenameDownload)) { throw "Either one or both filenames are empty!" } @@ -88,15 +88,15 @@ function Fetch-DownloadUrl { $url = [uri] $urlStr - if ((-Not $url) -Or ($null -eq $url) -Or ($url -eq '')) { + if ((-not $url) -or ($null -eq $url) -or ($url -eq '')) { throw "Failed to parse url: $urlStr" } - if (-Not ("http", "https" -Contains $url.Scheme)) { + if (-not ("http", "https" -contains $url.Scheme)) { throw "unknown source scheme: $($url.Scheme)" } - if (-Not ($url.Host -ilike "*github.com")) { + if (-not ($url.Host -ilike "*github.com")) { throw "unknown source domain: $($url.Host)" } @@ -116,12 +116,12 @@ function Fetch-DownloadUrl { $charCount = 0 - if (-Not ($info -Is [array])) { + if (-not ($info -is [array])) { throw "The response received from API server is invalid" } :loop foreach ($i in $info) { - if (-Not ($i.assets -Is [array])) { + if (-not ($i.assets -is [array])) { continue } @@ -157,12 +157,12 @@ function Fetch-DownloadUrl { } # Special case for archive downloads of repository - if (($null -eq $downloadLinks) -Or (-Not $downloadLinks)) { - if ((($p | % { $_.Trim('/') }) -Contains "archive") -And $info[0].tag_name) { + if (($null -eq $downloadLinks) -or (-not $downloadLinks)) { + if ((($p | ForEach-Object { $_.Trim('/') }) -contains "archive") -and $info[0].tag_name) { for ($i = 0; $i -lt $p.Length; $i++) { if ($p[$i].Trim('/') -eq "archive") { $p[$i + 1] = $info[0].tag_name + ".zip" - $downloadLinks = $url.Scheme + "://" + $url.Host + ($p -Join '') + $downloadLinks = $url.Scheme + "://" + $url.Host + ($p -join '') return $downloadLinks } } @@ -188,11 +188,11 @@ function Fetch-DownloadUrl { $downloadLinks = $temp | Where-Object { (Match-Filenames $url $_ true) -eq $charCount } - if (($null -eq $downloadLinks) -Or (-Not $downloadLinks)) { + if (($null -eq $downloadLinks) -or (-not $downloadLinks)) { throw "No suitable download links matched for the url!" } - if (-Not($downloadLinks -is [String])) { + if (-not($downloadLinks -is [String])) { throw "Found multiple matches for the same url:`n" + $downloadLinks } @@ -211,7 +211,7 @@ foreach ($s in $sources) { $downloadUrl = Fetch-DownloadUrl $s.url - if (($null -eq $downloadUrl) -Or ($downloadUrl -eq '')) { + if (($null -eq $downloadUrl) -or ($downloadUrl -eq '')) { Write-Verbose "No new links were found" continue } @@ -222,15 +222,15 @@ foreach ($s in $sources) { $version = '' - if ( ($url.Segments[-3] -eq "download/") -And ($url.Segments[-2].StartsWith("v")) ) { + if (($url.Segments[-3] -eq "download/") -and ($url.Segments[-2].StartsWith("v"))) { $version = $url.Segments[-2].TrimStart('v').TrimEnd('/') } - if ( ($url.Segments[-2] -eq "archive/") ) { + if (($url.Segments[-2] -eq "archive/")) { $version = [System.IO.Path]::GetFileNameWithoutExtension($url.Segments[-1].TrimStart('v').TrimEnd('/')) } - if ( $version -eq '' ) { + if ($version -eq '') { throw "Unable to extract version from url string" } @@ -255,11 +255,11 @@ if ($count -eq 0) { return } -if ( $Env:APPVEYOR -eq 'True' ) { +if ($Env:APPVEYOR -eq 'True') { Add-AppveyorMessage -Message "Successfully updated $count dependencies." -Category Information } -if ( $Env:GITHUB_ACTIONS -eq 'true' ) { +if ($Env:GITHUB_ACTIONS -eq 'true') { Write-Output "::notice title=Task Complete::Successfully updated $count dependencies." } diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index f294393..e1db5af 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -226,12 +226,12 @@ function Download-File { $useBitTransfer = $null -ne (Get-Module -Name BitsTransfer -ListAvailable) -and ($PSVersionTable.PSVersion.Major -le 5) - $File = $File -Replace "/", "\" + $File = $File -replace "/", "\" try { if ($useBitTransfer) { - Start-BitsTransfer -Source $Url -Destination $File -DisplayName "Downloading $Url to $File" - Return + Start-BitsTransfer -Source $Url -Destination $File -DisplayName "Downloading '$Url' to $File" + return } } catch { diff --git a/vendor/bin/cmder_diag.ps1 b/vendor/bin/cmder_diag.ps1 index e4ddb16..8b5202e 100644 --- a/vendor/bin/cmder_diag.ps1 +++ b/vendor/bin/cmder_diag.ps1 @@ -1,4 +1,4 @@ -if (test-path $env:temp\cmder_diag_ps.log) { +if (Test-Path $env:temp\cmder_diag_ps.log) { remove-item $env:temp\cmder_diag_ps.log } diff --git a/vendor/psmodules/PsGet/PsGet.psm1 b/vendor/psmodules/PsGet/PsGet.psm1 index b0094b9..4774dca 100644 --- a/vendor/psmodules/PsGet/PsGet.psm1 +++ b/vendor/psmodules/PsGet/PsGet.psm1 @@ -1818,7 +1818,7 @@ function Expand-ZipModule { # Check if powershell v3+ and .net v4.5 is available $netFailed = $true - if ( $PSVersionTable.PSVersion.Major -ge 3 -and (Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' -Recurse | Get-ItemProperty -Name Version | Where-Object { $_.Version -like '4.5*' -Or $_.Version -ge '4.5' }) ) { + if ( $PSVersionTable.PSVersion.Major -ge 3 -and (Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' -Recurse | Get-ItemProperty -Name Version | Where-Object { $_.Version -like '4.5*' -or $_.Version -ge '4.5' }) ) { Write-Debug 'Attempting unzip using the .NET Framework...' try {