Skip to content

Commit

Permalink
Expand PowerShell Aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Oct 13, 2018
1 parent 59fb82a commit b3c1f23
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions automatic/bower/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function global:au_GetLatest {

#v1.7.9.zip
$re = "(.*).zip"
$url = $download_page.links | ? href -match $re | select -First 1 -expand href
$file = $url -split 'v' | select -last 1
$url = $download_page.links | Where-Object href -match $re | Select-Object -First 1 -expand href
$file = $url -split 'v' | Select-Object -last 1

$version = [IO.Path]::GetFileNameWithoutExtension($file)

Expand Down
4 changes: 2 additions & 2 deletions automatic/gulp-cli/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function global:au_GetLatest {

#v1.2.2.zip
$re = "(.*).zip"
$url = $download_page.links | ? href -match $re | select -First 1 -expand href
$file = $url -split 'v' | select -last 1
$url = $download_page.links | Where-Object href -match $re | Select-Object -First 1 -expand href
$file = $url -split 'v' | Select-Object -last 1

$version = [IO.Path]::GetFileNameWithoutExtension($file)

Expand Down
12 changes: 6 additions & 6 deletions scripts/EventLogs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Clear all event logs
#>
function Clear-EventLogs {
Get-EventLog * | % { Clear-EventLog $_.Log }
Get-EventLog * | ForEach-Object { Clear-EventLog $_.Log }

#Clear this one again as it accumulates clearing events from previous step
Clear-EventLog System
Expand All @@ -30,16 +30,16 @@ function Get-EventLogs{
$r = @()

if ($EntryType -eq '*') { $EntryType = 'Error', 'Information', 'Warning' }
Get-EventLog * | % Log | % {
Get-EventLog * | ForEach-Object Log | ForEach-Object {
$log = $_
try {
$r += Get-EventLog -Log $log -Newest $Newest -EntryType $EntryType -ea 0
}
catch { Write-Warning "$log - $_" }
}
$r = $r | sort TimeWritten -Descending
if ($Raw) {$r} else { $r | select Source, TimeWritten, Message }
$r = $r | Sort-Object TimeWritten -Descending
if ($Raw) {$r} else { $r | Select-Object Source, TimeWritten, Message }
}

sal logs Get-EventLogs
sal clearlogs Clear-EventLogs
Set-Alias logs Get-EventLogs
Set-Alias clearlogs Clear-EventLogs
6 changes: 3 additions & 3 deletions scripts/Set-DescriptionFromReadme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ function Set-DescriptionFromReadme([int]$SkipFirst=0, [int]$SkipLast=0) {
if (!(Test-Path README.md)) { throw 'Set-DescriptionFromReadme: README.md not found' }

Write-Host 'Setting README.md to Nuspec description tag'
$description = gc README.md -Encoding UTF8
$description = Get-Content README.md -Encoding UTF8
$endIdx = $description.Length - $SkipLast
$description = $description | select -Index ($SkipFirst..$endIdx) | Out-String
$description = $description | Select-Object -Index ($SkipFirst..$endIdx) | Out-String

$nuspecFileName = Resolve-Path "*.nuspec"
# We force gc to read as UTF8, otherwise nuspec files will be treated as ANSI
# causing bogus/invalid characters to appear when non-ANSI characters are used.
$nu = gc $nuspecFileName -Encoding UTF8 -Raw
$nu = Get-Content $nuspecFileName -Encoding UTF8 -Raw
$nu = $nu -replace "(?smi)(\<description\>).*?(\</description\>)", "`${1}$($description)`$2"

$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False)
Expand Down
94 changes: 47 additions & 47 deletions scripts/Test-RepoPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ param(
function CheckPackageSizes() {
$nupkgFiles = Get-ChildItem "$PSScriptRoot\.." -Filter "*.nupkg" -Recurse

$nupkgFiles | % {
$nupkgFiles | ForEach-Object {
$size = $_.Length
$maxSize = 300MB
$packageName = $_.Directory.Name
Expand All @@ -87,10 +87,10 @@ function CreateSnapshotArchive() {
if (!(Get-Command 7z.exe -ea 0)) { WriteOutput -type Warning "7zip was not found in path, skipping creation of 7zip archive."; return }

if (!(Test-Path $artifactsDirectory)) { mkdir $artifactsDirectory }
$directories = $packages | ? {
$directories = $packages | Where-Object {
Test-path "$env:ChocolateyInstall\.chocolatey\$($_.Name)*"
} | % {
$directory = Resolve-Path "$env:ChocolateyInstall\.chocolatey\$($_.Name)*" | select -last 1
} | ForEach-Object {
$directory = Resolve-Path "$env:ChocolateyInstall\.chocolatey\$($_.Name)*" | Select-Object -last 1
"`"$directory`""
}

Expand Down Expand Up @@ -174,10 +174,10 @@ function CleanFiles() {
"$PSScriptRoot\..\Update-Force-Test*.md"
)
if ($TakeScreenshots) { $pathsToClean += @("$screenShotDir\*") }
$pathsToClean += Get-ChildItem -Recurse "$PSScriptRoot\.." -Filter "*.nupkg" | select -Expand FullName
$pathsToClean += Get-ChildItem -Recurse "$PSScriptRoot\.." -Filter "*.nupkg" | Select-Object -Expand FullName

$pathsToClean | % {
if (Test-Path $_) { rm $_ -Recurse }
$pathsToClean | ForEach-Object {
if (Test-Path $_) { Remove-Item $_ -Recurse }
}
}

Expand All @@ -190,11 +190,11 @@ function GetDependentPackage() {
[Parameter(Mandatory = $true)]
[string]$packageDirectory
)
$packageName = $PackageDirectory -split '[\/\\]' | select -last 1
$packageName = $PackageDirectory -split '[\/\\]' | Select-Object -last 1
$nuspecPath = Get-Item "$PackageDirectory\*.nuspec"
$content = Get-Content -Encoding UTF8 $nuspecPath
$Matches = $null
$content | ? { $_ -match "\<dependency.*id=`"(${packageName}.(install|portable|app|commandline))" } | select -First 1 | WriteOutput
$content | Where-Object { $_ -match "\<dependency.*id=`"(${packageName}.(install|portable|app|commandline))" } | Select-Object -First 1 | WriteOutput
$result = if ($Matches) { $Matches[1].ToLowerInvariant() } else { $null }
return $result
}
Expand All @@ -208,7 +208,7 @@ function GetPackagePath() {
if ($packageName -eq $null -or $packageName -eq '') {
return $null
}
$sourcePath = gci "$PSScriptRoot\.." -Recurse -Filter "$packageName.nuspec" | select -First 1 -Expand Directory
$sourcePath = Get-ChildItem "$PSScriptRoot\.." -Recurse -Filter "$packageName.nuspec" | Select-Object -First 1 -Expand Directory
if (!$sourcePath) {
WriteOutput "No path was found for the package: $packageName" -type Warning
}
Expand All @@ -222,7 +222,7 @@ function GetPackageSelectQuery() {
)
begin { $queries = @() }
process {
$queries += $InputObject | select `
$queries += $InputObject | Select-Object `
@{Name = 'NuspecPath'; Expression = {Resolve-Path "$_\*.nuspec"}},
@{Name = 'Directory'; Expression = {Resolve-Path $_}},
@{Name = 'Name'; Expression = {[System.IO.Path]::GetFileName($_).ToLowerInvariant()}},
Expand All @@ -247,7 +247,7 @@ function GetPackagesFromDiff() {
[ValidateNotNull()]
[string]$diffAgainst
)
$paths = git diff "${diffAgainst}..." --name-only | % {
$paths = git diff "${diffAgainst}..." --name-only | ForEach-Object {
if ($_.StartsWith('..')) {
$path = Split-Path -Parent $_
} else {
Expand All @@ -258,7 +258,7 @@ function GetPackagesFromDiff() {
$path = Split-Path -Parent $path
}
if ($path) { $path }
} | select -Unique
} | Select-Object -Unique

return $paths | GetPackageSelectQuery
}
Expand All @@ -269,7 +269,7 @@ function GetPackagesFromName() {
[ValidateNotNullOrEmpty()]
[string]$packageName
)
return Get-ChildItem "$PSScriptRoot\..\" -Recurse -Filter "$packageName.nuspec" | select -Unique -expand Directory | GetPackageSelectQuery
return Get-ChildItem "$PSScriptRoot\..\" -Recurse -Filter "$packageName.nuspec" | Select-Object -Unique -expand Directory | GetPackageSelectQuery
}

function MoveLogFile() {
Expand All @@ -286,7 +286,7 @@ function MoveLogFile() {
)

if (Test-Path "$env:ChocolateyInstall\logs\chocolatey.log") {
mv "$env:ChocolateyInstall\logs\chocolatey.log" "$env:ChocolateyInstall\logs\${commandType}_${packageName}.log" | WriteOutput
Move-Item "$env:ChocolateyInstall\logs\chocolatey.log" "$env:ChocolateyInstall\logs\${commandType}_${packageName}.log" | WriteOutput
}
}

Expand All @@ -295,9 +295,9 @@ function RemoveDependentPackages() {
[object]$packages
)

[array]$dependentPackages = $packages | ? { $_.DependentPackage -ne $null -and $_.DependentPackage -ne '' } | select -expand DependentPackage
[array]$dependentPackages = $packages | Where-Object { $_.DependentPackage -ne $null -and $_.DependentPackage -ne '' } | Select-Object -expand DependentPackage
if ($dependentPackages -ne $null -and $dependentPackages.Count -gt 0) {
$packages = $packages | ? { !$dependentPackages.Contains($_.Name) }
$packages = $packages | Where-Object { !$dependentPackages.Contains($_.Name) }
}
return $packages
}
Expand All @@ -308,12 +308,12 @@ function RunChocoPackProcess() {
Function responsible for running choco pack when a nupkg file have not already been created.
#>
param([string]$path)
if ($path -ne $null -and $path -ne '') { pushd $path }
if ($path -ne $null -and $path -ne '') { Push-Location $path }
if (!(Test-Path "*.nupkg")) {
. choco pack | WriteChocoOutput
if ($LastExitCode -ne 0) { popd; throw "Choco pack failed with code: $LastExitCode"; return }
if ($LastExitCode -ne 0) { Pop-Location; throw "Choco pack failed with code: $LastExitCode"; return }
}
if ($path -ne $null -and $path -ne '') { popd}
if ($path -ne $null -and $path -ne '') { Pop-Location}
}

function SetAppveyorExitCode() {
Expand Down Expand Up @@ -370,12 +370,12 @@ function RunChocoProcess() {
$errorFilePath = "$screenShotDir\$($arguments[0])Error_$($arguments[1]).jpg"
if (!(Test-Path "$screenShotDir")) { mkdir "$screenShotDir" -Force | Out-Null }

$packageName = $arguments[1] -split ' ' | select -first 1
$pkgDir = Get-ChildItem -Path "$PSScriptRoot\.." -Filter "$packageName" -Recurse -Directory | select -first 1
$nupkgFile = Get-ChildItem -Path $pkgDir.FullName -Filter "*.nupkg" | select -first 1
$pkgNameVersion = Split-Path -Leaf $nupkgFile | % { ($_ -replace '((\.\d+)+(-[^-\.]+)?).nupkg', ':$1').Replace(':.', ':') -split ':' }
$packageName = $pkgNameVersion | select -first 1
$version = $pkgNameVersion | select -last 1
$packageName = $arguments[1] -split ' ' | Select-Object -first 1
$pkgDir = Get-ChildItem -Path "$PSScriptRoot\.." -Filter "$packageName" -Recurse -Directory | Select-Object -first 1
$nupkgFile = Get-ChildItem -Path $pkgDir.FullName -Filter "*.nupkg" | Select-Object -first 1
$pkgNameVersion = Split-Path -Leaf $nupkgFile | ForEach-Object { ($_ -replace '((\.\d+)+(-[^-\.]+)?).nupkg', ':$1').Replace(':.', ':') -split ':' }
$packageName = $pkgNameVersion | Select-Object -first 1
$version = $pkgNameVersion | Select-Object -last 1
if ($packageName -ne $arguments[1]) { $args[1] = $packageName }

try {
Expand All @@ -391,7 +391,7 @@ function RunChocoProcess() {
$failureOccurred = $false
$previousPercentage = -1;
$progressRegex = 'Progress\:.*\s+([\d]+)\%'
. choco $args | % {
. choco $args | ForEach-Object {
$matches = $null
if ($failureOccurred) { WriteOutput "$_" -type ChocoError }
# We are only showing progress per 10th value
Expand All @@ -410,11 +410,11 @@ function RunChocoProcess() {
$failureOccurred = $true
$res = $false
# Allow everything to complete before we continue
sleep -Seconds 5
Start-Sleep -Seconds 5
if ($takeScreenshot) {
Take-ScreenShot -file $errorFilePath -imagetype jpeg
# Wait for a second so the screenshot can be taken before we continue
sleep -Seconds 1
Start-Sleep -Seconds 1
}
if ($arguments[0] -eq 'uninstall') {
Stop-Process -ProcessName "unins*" -ErrorAction Ignore
Expand All @@ -429,7 +429,7 @@ function RunChocoProcess() {
$res = $false
}
if ($takeScreenshot -and !$packFailed) {
if ($timeoutBeforeScreenshot -gt 0) { sleep -Seconds $timeoutBeforeScreenshot }
if ($timeoutBeforeScreenshot -gt 0) { Start-Sleep -Seconds $timeoutBeforeScreenshot }
WriteOutput "Taking screenshot after $($arguments[0])"
# We take a screenshot when install/uninstall have finished to see if a program have started that isn't monitored by choco
$filePath = "$screenShotDir\$($arguments[0])_$($arguments[1]).jpg"
Expand Down Expand Up @@ -496,47 +496,47 @@ function TestAuUpdatePackages() {
param(
$packages
)
[array]$packageNames = $packages | ? IsAutomatic | select -expand Name
$packageNames += $packages | ? { $_.DependentPackage -ne $null -and $_.DependentPackage -ne '' } | select -expand DependentPackage
[array]$packageNames = $packages | Where-Object IsAutomatic | Select-Object -expand Name
$packageNames += $packages | Where-Object { $_.DependentPackage -ne $null -and $_.DependentPackage -ne '' } | Select-Object -expand DependentPackage
if (!$packageNames) {
WriteOutput "No Automatic packages was found. Skipping AU update test."
return
}

try {
pushd "$PSScriptRoot\.."
Push-Location "$PSScriptRoot\.."
.\test_all.ps1 -Name $packageNames -ThrowOnErrors
} catch {
SetAppveyorExitCode $LastExitCode
throw "An exception ocurred during AU update. Cancelling all other checks."
} finally {
MoveLogFile -packageName 'au' -commandType 'update'
popd
Pop-Location
}
}

function RunUpdateScripts {
param(
$packages
)
[array]$manualPackages = $packages | ? { !$_.IsAutomatic -and (Test-Path "$($_.Directory)\update.ps1") }
[array]$manualPackages = $packages | Where-Object { !$_.IsAutomatic -and (Test-Path "$($_.Directory)\update.ps1") }
# Currently we do not support dependent packages
if (!$manualPackages) {
WriteOutput "No manual packages that contain an update script"
return
}

$manualPackages | % {
$manualPackages | ForEach-Object {
$name = $_.Name
WriteOutput "Running update.ps1 for $name"
try {
pushd $_.Directory
Push-Location $_.Directory
.\update.ps1
} catch {
SetAppveyorExitCode 1
throw "An exception ocurred during the manual update of $name. Cancelling all other checks."
} finally {
popd
Pop-Location
}
}
}
Expand All @@ -561,8 +561,8 @@ function TestInstallAllPackages() {
[object[]]$ignoredValues
)

$packages | % {
pushd $_.Directory
$packages | ForEach-Object {
Push-Location $_.Directory
if ($runChocoWithAu) { Test-Package -Install | WriteChocoOutput }
else {
InstallPackage `
Expand All @@ -573,8 +573,8 @@ function TestInstallAllPackages() {
-screenShotDir $screenShotDir
MoveLogFile -packageName $_.Name -commandType 'install'
}
popd
} | ? { $_ -ne $null -and $_ -ne '' }
Pop-Location
} | Where-Object { $_ -ne $null -and $_ -ne '' }
}

function UninstallPackage() {
Expand Down Expand Up @@ -647,14 +647,14 @@ function TestUninstallAllPackages() {
[object[]]$ignoredValues
)

$packages | % {
$packages | ForEach-Object {
$name = $_.Name
$packageFailed = $failedInstalls | ? { $_ -eq $name }
$packageFailed = $failedInstalls | Where-Object { $_ -eq $name }
if ($packageFailed) {
WriteOutput "$name failed to install, skipping uninstall test..." -type Warning
return ""
} else {
pushd $_.Directory
Push-Location $_.Directory
if ($runChocoWithAu) { Test-Package -Uninstall | WriteChocoOutput }
else {
UninstallPackage `
Expand All @@ -665,9 +665,9 @@ function TestUninstallAllPackages() {
-screenShotDir $screenShotDir
MoveLogFile -packageName $name -commandType 'uninstall'
}
popd
Pop-Location
}
} | ? { $_ -ne $null -and $_ -ne '' }
} | Where-Object { $_ -ne $null -and $_ -ne '' }
}

if ($packageName) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/Update-ChangelogVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Update-ChangelogVersion([string]$version, [string]$format = '## Version
Write-Host "Updating changelog version."

$path = (Resolve-Path "Changelog.md")
[string[]]$changelog = gc $path -Encoding UTF8 | % {
[string[]]$changelog = Get-Content $path -Encoding UTF8 | ForEach-Object {
if ($_.StartsWith('## Upcoming')) {
$line = ($format -replace '\{VERSION\}',$version -replace '\{DATE\}',(Get-Date -Format 'yyyy-MM-dd'))
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/au_extensions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $funcs = @(
'Update-OnETagChanged'
)

$funcs | % {
$funcs | ForEach-Object {
if (Test-Path "$PSScriptRoot\$_.ps1") {
. "$PSScriptRoot\$_.ps1"
if (Get-Command $_ -ea 0) {
Expand Down
2 changes: 1 addition & 1 deletion setup/au_setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ if ($refreshenv -ne $null -and $refreshenv.CommandType -ne 'Application') {
Install-PackageProvider -Name NuGet -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module au -Scope AllUsers
Get-Module au -ListAvailable | select Name, Version
Get-Module au -ListAvailable | Select-Object Name, Version
Loading

0 comments on commit b3c1f23

Please sign in to comment.