From e5b5e4313a6154ca5bad61f6c42836c89809261c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 20:29:22 +0100 Subject: [PATCH 01/25] Fix escape single quoted text in manifest --- .../helpers/Build/Build-PSModuleManifest.ps1 | 1 + .../helpers/Build/Escape-HashtableString.ps1 | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 scripts/helpers/Build/Escape-HashtableString.ps1 diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 6f3d8471..3bee380c 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -431,6 +431,7 @@ function Build-PSModuleManifest { Write-Verbose 'Creating new manifest file in outputs folder' $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Verbose "OutputManifestPath - [$outputManifestPath]" + $manifest | Invoke-RecurseEscapeFix New-ModuleManifest -Path $outputManifestPath @manifest } diff --git a/scripts/helpers/Build/Escape-HashtableString.ps1 b/scripts/helpers/Build/Escape-HashtableString.ps1 new file mode 100644 index 00000000..1c19a809 --- /dev/null +++ b/scripts/helpers/Build/Escape-HashtableString.ps1 @@ -0,0 +1,71 @@ +function Invoke-RecurseEscapeFix { + <# + .SYNOPSIS + Recurse through a hashtable and escape single quotes in strings. + #> + param( + [Parameter(Mandatory)] + [object] $Value + ) + + if ($Value -is [string]) { + # Escape single quotes in strings + return $Value -replace "'", "''" + } elseif ($Value -is [hashtable]) { + # Recursively process nested hashtables + $keys = @($Value.Keys) # Make a copy of the keys + foreach ($key in $keys) { + $Value[$key] = Invoke-RecurseEscapeFix -Value $Value[$key] + } + } elseif ($Value -is [array]) { + # Recursively process arrays + for ($i = 0; $i -lt $Value.Count; $i++) { + $Value[$i] = Invoke-RecurseEscapeFix -Value $Value[$i] + } + } + + return $Value +} + +filter ConvertTo-EscapedHashtableString { + <# + .SYNOPSIS + Converts a hashtable to a string with escaped single quotes. + + .DESCRIPTION + Converts a hashtable to a string with escaped single quotes. + + .EXAMPLE + $myHashtable = @{ + Name = "O'Brien" + Nested = @{ + Description = "It's a 'nested' value" + Array = @("String with 'quotes'", 123, @{'Another' = "Nested 'string'" }) + } + } + Escape-HashtableStrings -Hashtable $myHashtable + $myHashtable | Format-List -Force + + Name : Nested + Value : {[Description, It''s a ''nested'' value], [Array, System.Object[]]} + + Name : Name + Value : O''Brien + #> + param ( + # The hashtable to convert to a string with escaped single quotes. + [Parameter( + Mandatory, + ValueFromPipeline + )] + [hashtable] $Hashtable + ) + + # Loop through the hashtable and process each value + $keys = @($Hashtable.Keys) # Make a copy of the keys + foreach ($key in $keys) { + $Hashtable[$key] = Invoke-RecurseEscapeFix -Value $Hashtable[$key] + } + + return $Hashtable +} From da18c11fd6d0e77daea5303743cbfdcdd166a1f2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 20:37:28 +0100 Subject: [PATCH 02/25] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Replace=20In?= =?UTF-8?q?voke-RecurseEscapeFix=20with=20ConvertTo-EscapedHashtableString?= =?UTF-8?q?=20for=20escaping=20single=20quotes=20in=20hashtables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helpers/Build/Build-PSModuleManifest.ps1 | 2 +- ...1 => ConvertTo-EscapedHashtableString.ps1} | 30 +------------------ .../helpers/Build/Invoke-RecurseEscapeFix.ps1 | 28 +++++++++++++++++ 3 files changed, 30 insertions(+), 30 deletions(-) rename scripts/helpers/Build/{Escape-HashtableString.ps1 => ConvertTo-EscapedHashtableString.ps1} (59%) create mode 100644 scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 3bee380c..ae2ac908 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -431,7 +431,7 @@ function Build-PSModuleManifest { Write-Verbose 'Creating new manifest file in outputs folder' $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Verbose "OutputManifestPath - [$outputManifestPath]" - $manifest | Invoke-RecurseEscapeFix + ConvertTo-EscapedHashtableString -Hashtable $manifest New-ModuleManifest -Path $outputManifestPath @manifest } diff --git a/scripts/helpers/Build/Escape-HashtableString.ps1 b/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 similarity index 59% rename from scripts/helpers/Build/Escape-HashtableString.ps1 rename to scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 index 1c19a809..9e7e4528 100644 --- a/scripts/helpers/Build/Escape-HashtableString.ps1 +++ b/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 @@ -1,32 +1,4 @@ -function Invoke-RecurseEscapeFix { - <# - .SYNOPSIS - Recurse through a hashtable and escape single quotes in strings. - #> - param( - [Parameter(Mandatory)] - [object] $Value - ) - - if ($Value -is [string]) { - # Escape single quotes in strings - return $Value -replace "'", "''" - } elseif ($Value -is [hashtable]) { - # Recursively process nested hashtables - $keys = @($Value.Keys) # Make a copy of the keys - foreach ($key in $keys) { - $Value[$key] = Invoke-RecurseEscapeFix -Value $Value[$key] - } - } elseif ($Value -is [array]) { - # Recursively process arrays - for ($i = 0; $i -lt $Value.Count; $i++) { - $Value[$i] = Invoke-RecurseEscapeFix -Value $Value[$i] - } - } - - return $Value -} - + filter ConvertTo-EscapedHashtableString { <# .SYNOPSIS diff --git a/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 b/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 new file mode 100644 index 00000000..dbd3968d --- /dev/null +++ b/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 @@ -0,0 +1,28 @@ +function Invoke-RecurseEscapeFix { + <# + .SYNOPSIS + Recurse through a hashtable and escape single quotes in strings. + #> + param( + [Parameter(Mandatory)] + [object] $Value + ) + + if ($Value -is [string]) { + # Escape single quotes in strings + return $Value -replace "'", "''" + } elseif ($Value -is [hashtable]) { + # Recursively process nested hashtables + $keys = @($Value.Keys) # Make a copy of the keys + foreach ($key in $keys) { + $Value[$key] = Invoke-RecurseEscapeFix -Value $Value[$key] + } + } elseif ($Value -is [array]) { + # Recursively process arrays + for ($i = 0; $i -lt $Value.Count; $i++) { + $Value[$i] = Invoke-RecurseEscapeFix -Value $Value[$i] + } + } + + return $Value +} From 1dfe9a481139b7cc955a7f720aa8c4cc759c8b1b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 20:40:52 +0100 Subject: [PATCH 03/25] =?UTF-8?q?=F0=9F=A9=B9=20[Enhancement]:=20Add=20ver?= =?UTF-8?q?bose=20logging=20to=20ConvertTo-EscapedHashtableString=20for=20?= =?UTF-8?q?better=20debugging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 b/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 index 9e7e4528..14c605da 100644 --- a/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 +++ b/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 @@ -35,8 +35,12 @@ filter ConvertTo-EscapedHashtableString { # Loop through the hashtable and process each value $keys = @($Hashtable.Keys) # Make a copy of the keys + Write-Verbose "Processing hashtable keys: $keys" foreach ($key in $keys) { + Write-Verbose "Processing key: $key" + Write-Verbose "Value: [$($Hashtable[$key])]" $Hashtable[$key] = Invoke-RecurseEscapeFix -Value $Hashtable[$key] + Write-Verbose "Escaped value: [$($Hashtable[$key])]" } return $Hashtable From f1ffce3c2a7da2e699b84bef300cdb0688daaa00 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 20:41:55 +0100 Subject: [PATCH 04/25] =?UTF-8?q?=F0=9F=A9=B9=20[Enhancement]:=20Add=20ver?= =?UTF-8?q?bose=20flag=20to=20ConvertTo-EscapedHashtableString=20for=20imp?= =?UTF-8?q?roved=20logging=20in=20manifest=20generation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index ae2ac908..ccd15cce 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -431,7 +431,7 @@ function Build-PSModuleManifest { Write-Verbose 'Creating new manifest file in outputs folder' $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Verbose "OutputManifestPath - [$outputManifestPath]" - ConvertTo-EscapedHashtableString -Hashtable $manifest + ConvertTo-EscapedHashtableString -Hashtable $manifest -Verbose New-ModuleManifest -Path $outputManifestPath @manifest } From d8c8674646863d00e8b3d80ab430fef31e2948c4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 20:53:09 +0100 Subject: [PATCH 05/25] =?UTF-8?q?=F0=9F=A9=B9=20[Enhancement]:=20Add=20nul?= =?UTF-8?q?l=20and=20empty=20string=20handling=20to=20Invoke-RecurseEscape?= =?UTF-8?q?Fix=20for=20improved=20robustness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 b/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 index dbd3968d..7866ee3f 100644 --- a/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 +++ b/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 @@ -5,9 +5,15 @@ #> param( [Parameter(Mandatory)] + [AllowEmptyString()] + [AllowNull()] [object] $Value ) + if (-not $Value) { + return $Value + } + if ($Value -is [string]) { # Escape single quotes in strings return $Value -replace "'", "''" From edf629d1ac5534add4cfd0001ec4d2acc13e4cc2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 20:56:22 +0100 Subject: [PATCH 06/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Correctly=20assig?= =?UTF-8?q?n=20output=20of=20ConvertTo-EscapedHashtableString=20to=20manif?= =?UTF-8?q?est=20in=20Build-PSModuleManifest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index ccd15cce..be018954 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -431,7 +431,7 @@ function Build-PSModuleManifest { Write-Verbose 'Creating new manifest file in outputs folder' $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Verbose "OutputManifestPath - [$outputManifestPath]" - ConvertTo-EscapedHashtableString -Hashtable $manifest -Verbose + $manifest = ConvertTo-EscapedHashtableString -Hashtable $manifest -Verbose New-ModuleManifest -Path $outputManifestPath @manifest } From 3e58fb0c69245dc4c919c106353ee8db25c6373e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:00:48 +0100 Subject: [PATCH 07/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Escape=20single?= =?UTF-8?q?=20quotes=20in=20module=20manifest=20description=20to=20prevent?= =?UTF-8?q?=20formatting=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index be018954..7a032f6d 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -70,6 +70,7 @@ function Build-PSModuleManifest { $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription + $manifest.Description = $manifest.Description -replace "'", "''" Write-Verbose "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null @@ -431,7 +432,6 @@ function Build-PSModuleManifest { Write-Verbose 'Creating new manifest file in outputs folder' $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Verbose "OutputManifestPath - [$outputManifestPath]" - $manifest = ConvertTo-EscapedHashtableString -Hashtable $manifest -Verbose New-ModuleManifest -Path $outputManifestPath @manifest } From 257e5afe0c2ab44f1c3e8a93a3e3a0354c120e7c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:02:19 +0100 Subject: [PATCH 08/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Remove=20redundan?= =?UTF-8?q?t=20single=20quote=20escaping=20in=20module=20manifest=20descri?= =?UTF-8?q?ption=20assignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 7a032f6d..6f3d8471 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -70,7 +70,6 @@ function Build-PSModuleManifest { $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription - $manifest.Description = $manifest.Description -replace "'", "''" Write-Verbose "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null From 0500cf1a6f8cc098e14e591fafd21d6dd12cb6f1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:10:04 +0100 Subject: [PATCH 09/25] =?UTF-8?q?=F0=9F=A9=B9=20[Enhancement]:=20Add=20ver?= =?UTF-8?q?bose=20flag=20to=20Set-ModuleManifest=20for=20improved=20loggin?= =?UTF-8?q?g=20during=20manifest=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 6f3d8471..34801a5e 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -439,7 +439,7 @@ function Build-PSModuleManifest { } LogGroup 'Build manifest file - Format' { - Set-ModuleManifest -Path $outputManifestPath + Set-ModuleManifest -Path $outputManifestPath -Verbose } LogGroup 'Build manifest file - Result - After format' { From d98cbb90c42897001f258ada1adffe4e503a0978 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:27:09 +0100 Subject: [PATCH 10/25] =?UTF-8?q?=F0=9F=A9=B9=20[Feature]:=20Add=20multipl?= =?UTF-8?q?e=20PowerShell=20utility=20functions=20for=20module=20managemen?= =?UTF-8?q?t=20and=20hashtable=20operations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hashtable/Convert-HashtableToString.ps1 | 103 ++++++ .../public/Hashtable/ConvertTo-HashTable.ps1 | 70 ++++ .../public/Hashtable/Merge-Hashtable.ps1 | 56 +++ .../Module/Add-ModuleManifestData.ps1 | 164 +++++++++ .../PowerShell/Module/Add-PSModulePath.ps1 | 29 ++ .../Module/Export-PowerShellDataFile.ps1 | 30 ++ .../Module/Format-ModuleManifest.ps1 | 32 ++ .../PowerShell/Module/Get-ModuleManifest.ps1 | 121 +++++++ .../PowerShell/Module/Invoke-PruneModule.ps1 | 58 ++++ .../Module/Invoke-ReinstallModule.ps1 | 61 ++++ .../PowerShell/Module/Set-ModuleManifest.ps1 | 325 ++++++++++++++++++ .../PowerShell/Module/Uninstall-Pester.ps1 | 54 +++ 12 files changed, 1103 insertions(+) create mode 100644 scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 create mode 100644 scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 create mode 100644 scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 create mode 100644 scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 new file mode 100644 index 00000000..932f409d --- /dev/null +++ b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 @@ -0,0 +1,103 @@ +function Convert-HashtableToString { + <# + .SYNOPSIS + Converts a hashtable to its code representation. + + .DESCRIPTION + Recursively converts a hashtable to its code representation. + This function is useful for exporting hashtables to .psd1 files. + + .EXAMPLE + $hashtable = @{ + Key1 = 'Value1' + Key2 = @{ + NestedKey1 = 'NestedValue1' + NestedKey2 = 'NestedValue2' + } + Key3 = @(1, 2, 3) + Key4 = $true + } + Convert-HashtableToString -Hashtable $hashtable + + This will return the following string: + @{ + Key1 = 'Value1' + Key2 = @{ + NestedKey1 = 'NestedValue1' + NestedKey2 = 'NestedValue2' + } + Key3 = @(1, 2, 3) + Key4 = $true + } + + .NOTES + General notes + #> + [CmdletBinding()] + param ( + # The hashtable to convert to a string. + [Parameter(Mandatory)] + [object]$Hashtable, + + # The indentation level. + [Parameter()] + [int]$IndentLevel = 0 + ) + + $lines = @() + $lines += '@{' + $indent = ' ' * $IndentLevel + + foreach ($key in $Hashtable.Keys) { + Write-Verbose "Processing key: $key" + $value = $Hashtable[$key] + Write-Verbose "Processing value: $value" + if ($null -eq $value) { + Write-Verbose "Value type: `$null" + continue + } + Write-Verbose "Value type: $($value.GetType().Name)" + if (($value -is [System.Collections.Hashtable]) -or ($value -is [System.Collections.Specialized.OrderedDictionary])) { + $nestedString = Convert-HashtableToString -Hashtable $value -IndentLevel ($IndentLevel + 1) + $lines += "$indent $key = $nestedString" + } elseif ($value -is [System.Management.Automation.PSCustomObject]) { + $nestedString = Convert-HashtableToString -Hashtable $value -IndentLevel ($IndentLevel + 1) + $lines += "$indent $key = $nestedString" + } elseif ($value -is [System.Management.Automation.PSObject]) { + $nestedString = Convert-HashtableToString -Hashtable $value -IndentLevel ($IndentLevel + 1) + $lines += "$indent $key = $nestedString" + } elseif ($value -is [bool]) { + $lines += "$indent $key = `$$($value.ToString().ToLower())" + } elseif ($value -is [int]) { + $lines += "$indent $key = $value" + } elseif ($value -is [array]) { + if ($value.Count -eq 0) { + $lines += "$indent $key = @()" + } else { + $lines += "$indent $key = @(" + $value | ForEach-Object { + $nestedValue = $_ + Write-Verbose "Processing array element: $_" + Write-Verbose "Element type: $($_.GetType().Name)" + if (($nestedValue -is [System.Collections.Hashtable]) -or ($nestedValue -is [System.Collections.Specialized.OrderedDictionary])) { + $nestedString = Convert-HashtableToString -Hashtable $nestedValue -IndentLevel ($IndentLevel + 1) + $lines += "$indent $nestedString" + } elseif ($nestedValue -is [bool]) { + $lines += "$indent `$$($nestedValue.ToString().ToLower())" + } elseif ($nestedValue -is [int]) { + $lines += "$indent $nestedValue" + } else { + $lines += "$indent '$nestedValue'" + } + } + $lines += "$indent )" + } + } else { + $value = $value -replace "'", "''" + $lines += "$indent $key = '$value'" + } + } + + $lines += "$indent}" + return $lines -join "`n" +} diff --git a/scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 b/scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 new file mode 100644 index 00000000..b9a381f5 --- /dev/null +++ b/scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 @@ -0,0 +1,70 @@ +filter ConvertTo-Hashtable { + <# + .SYNOPSIS + Converts an object to a hashtable. + + .DESCRIPTION + Recursively converts an object to a hashtable. This function is useful for converting complex objects + to hashtables for serialization or other purposes. + + .EXAMPLE + $object = [PSCustomObject]@{ + Name = 'John Doe' + Age = 30 + Address = [PSCustomObject]@{ + Street = '123 Main St' + City = 'Somewhere' + ZipCode = '12345' + } + Occupations = @( + [PSCustomObject]@{ + Title = 'Developer' + Company = 'TechCorp' + }, + [PSCustomObject]@{ + Title = 'Consultant' + Company = 'ConsultCorp' + } + ) + } + $hashtable = ConvertTo-Hashtable -InputObject $object + + This will return a hashtable representation of the object. + #> + param ( + # The object to convert to a hashtable. + [Parameter( + Mandatory, + ValueFromPipeline + )] + [PSObject] $InputObject + ) + + $hashtable = @{} + + # Iterate over each property of the object + $InputObject.PSObject.Properties | ForEach-Object { + $propertyName = $_.Name + $propertyValue = $_.Value + + if ($propertyValue -is [PSObject]) { + if ($propertyValue -is [Array] -or $propertyValue -is [System.Collections.IEnumerable]) { + # Handle arrays and enumerables + $hashtable[$propertyName] = @() + foreach ($item in $propertyValue) { + $hashtable[$propertyName] += ConvertTo-HashTable -InputObject $item + } + } elseif ($propertyValue.PSObject.Properties.Count -gt 0) { + # Handle nested objects + $hashtable[$propertyName] = ConvertTo-Hashtable -InputObject $propertyValue + } else { + # Handle simple properties + $hashtable[$propertyName] = $propertyValue + } + } else { + $hashtable[$propertyName] = $propertyValue + } + } + + return $hashtable +} diff --git a/scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 b/scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 new file mode 100644 index 00000000..8f698f30 --- /dev/null +++ b/scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 @@ -0,0 +1,56 @@ +function Merge-Hashtable { + <# + .SYNOPSIS + Merge two hashtables, with the second hashtable overriding the first + + .DESCRIPTION + Merge two hashtables, with the second hashtable overriding the first + + .EXAMPLE + $Main = [ordered]@{ + Action = '' + Location = 'Main' + Name = 'Main' + Mode = 'Main' + } + $Override1 = [ordered]@{ + Action = '' + Location = '' + Name = 'Override1' + Mode = 'Override1' + } + $Override2 = [ordered]@{ + Action = '' + Location = '' + Name = 'Override1' + Mode = 'Override2' + } + Merge-Hashtables -Main $Main -Overrides $Override1, $Override2 + #> + [OutputType([Hashtable])] + [Alias('Merge-Hashtables')] + [CmdletBinding()] + param ( + # Main hashtable + [Parameter(Mandatory)] + [object] $Main, + + # Hashtable with overrides. + # Providing a list of overrides will apply them in order. + # Last write wins. + [Parameter(Mandatory)] + [object[]] $Overrides + ) + $Output = $Main.Clone() + foreach ($Override in $Overrides) { + foreach ($Key in $Override.Keys) { + if (($Output.Keys) -notcontains $Key) { + $Output.$Key = $Override.$Key + } + if ($Override.item($Key) | IsNotNullOrEmpty) { + $Output.$Key = $Override.$Key + } + } + } + return $Output +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 new file mode 100644 index 00000000..00ba9e14 --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 @@ -0,0 +1,164 @@ +function Add-ModuleManifestData { + <# + .SYNOPSIS + Add data to a module manifest file property + + .DESCRIPTION + This function adds data to a module manifest file property. + If the property doesn't exist, it will be created. + If it does exist, the new data will be appended to the existing data. + + .EXAMPLE + Add-ModuleManifestData -Path 'MyModule.psd1' -RequiredModules 'pester', 'platyPS' + + Adds the modules 'pester' and 'platyPS' to the RequiredModules property of the module manifest file 'MyModule.psd1'. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [ValidateScript({ Test-Path -Path $_ -PathType Leaf })] + [string]$Path, + + # Modules that must be imported into the global environment prior to importing this module. + [Parameter()] + [Object[]] $RequiredModules, + + # Compatible editions of PowerShell. + [Parameter()] + [string[]] $CompatiblePSEditions, + + # Assemblies that must be loaded prior to importing this module. + [Parameter()] + [string[]] $RequiredAssemblies, + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + [Parameter()] + [string[]] $ScriptsToProcess, + + # Type files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [string[]] $TypesToProcess, + + # Format files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [string[]] $FormatsToProcess, + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. + [Parameter()] + [Object[]] $NestedModules, + + # Functions to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no functions to export. + [Parameter()] + [string[]] $FunctionsToExport, + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no cmdlets to export. + [Parameter()] + [string[]] $CmdletsToExport, + + # Variables to export from this module. + [Parameter()] + [string[]] $VariablesToExport, + + # Aliases to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no aliases to export. + [Parameter()] + [string[]] $AliasesToExport, + + # DSC resources to export from this module. + [Parameter()] + [string[]] $DscResourcesToExport, + + # List of all modules packaged with this module. + [Parameter()] + [Object[]] $ModuleList, + + # List of all files packaged with this module. + [Parameter()] + [string[]] $FileList, + + # Tags applied to this module. These help with module discovery in online galleries. + [Parameter()] + [string[]] $Tags, + + # External dependent modules of this module. + [Parameter()] + [string[]] $ExternalModuleDependencies + ) + + $moduleManifest = Get-ModuleManifest -Path $Path + $changes = @{} + + if ($RequiredModules) { + $RequiredModules += $moduleManifest.RequiredModules + $changes.RequiredModules = $RequiredModules + } + if ($RequiredAssemblies) { + $RequiredAssemblies += $moduleManifest.RequiredAssemblies + $changes.RequiredAssemblies = $RequiredAssemblies + } + if ($CompatiblePSEditions) { + $CompatiblePSEditions += $moduleManifest.CompatiblePSEditions + $changes.CompatiblePSEditions = $CompatiblePSEditions + } + if ($ScriptsToProcess) { + $ScriptsToProcess += $moduleManifest.ScriptsToProcess + $changes.ScriptsToProcess = $ScriptsToProcess + } + if ($TypesToProcess) { + $TypesToProcess += $moduleManifest.TypesToProcess + $changes.TypesToProcess = $TypesToProcess + } + if ($FormatsToProcess) { + $FormatsToProcess += $moduleManifest.FormatsToProcess + $changes.FormatsToProcess = $FormatsToProcess + } + if ($NestedModules) { + $NestedModules += $moduleManifest.NestedModules + $changes.NestedModules = $NestedModules + } + if ($FunctionsToExport) { + $FunctionsToExport += $moduleManifest.FunctionsToExport + $changes.FunctionsToExport = $FunctionsToExport + } + if ($CmdletsToExport) { + $CmdletsToExport += $moduleManifest.CmdletsToExport + $changes.CmdletsToExport = $CmdletsToExport + } + if ($VariablesToExport) { + $VariablesToExport += $moduleManifest.VariablesToExport + $changes.VariablesToExport = $VariablesToExport + } + if ($AliasesToExport) { + $AliasesToExport += $moduleManifest.AliasesToExport + $changes.AliasesToExport = $AliasesToExport + } + if ($DscResourcesToExport) { + $DscResourcesToExport += $moduleManifest.DscResourcesToExport + $changes.DscResourcesToExport = $DscResourcesToExport + } + if ($ModuleList) { + $ModuleList += $moduleManifest.ModuleList + $changes.ModuleList = $ModuleList + } + if ($FileList) { + $FileList += $moduleManifest.FileList + $changes.FileList = $FileList + } + if ($Tags) { + $Tags += $moduleManifest.PrivateData.PSData.Tags + $changes.Tags = $Tags + } + if ($ExternalModuleDependencies) { + $ExternalModuleDependencies += $moduleManifest.PrivateData.PSData.ExternalModuleDependencies + $changes.ExternalModuleDependencies = $ExternalModuleDependencies + } + + foreach ($key in $changes.GetEnumerator().Name) { + $changes[$key] = $changes[$key] | Sort-Object -Unique | Where-Object { $_ | IsNotNullOrEmpty } + } + + Set-ModuleManifest -Path $Path @changes + +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 new file mode 100644 index 00000000..f5abf042 --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 @@ -0,0 +1,29 @@ +function Add-PSModulePath { + <# + .SYNOPSIS + Adds a path to the PSModulePath environment variable. + + .DESCRIPTION + Adds a path to the PSModulePath environment variable. + For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. + + .EXAMPLE + Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' + + Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. + #> + [CmdletBinding()] + param( + # Path to the folder where the module source code is located. + [Parameter(Mandatory)] + [string] $Path + ) + $PSModulePathSeparator = [System.IO.Path]::PathSeparator + + $env:PSModulePath += "$PSModulePathSeparator$Path" + + Write-Verbose 'PSModulePath:' + $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { + Write-Verbose " - [$_]" + } +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 new file mode 100644 index 00000000..f903cb99 --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 @@ -0,0 +1,30 @@ +function Export-PowerShellDataFile { + <# + .SYNOPSIS + Export a hashtable to a .psd1 file. + + .DESCRIPTION + This function exports a hashtable to a .psd1 file. It also formats the .psd1 file using the Format-ModuleManifest cmdlet. + + .EXAMPLE + Export-PowerShellDataFile -Hashtable @{ Name = 'MyModule'; ModuleVersion = '1.0.0' } -Path 'MyModule.psd1' + #> + [CmdletBinding()] + param ( + # The hashtable to export to a .psd1 file. + [Parameter(Mandatory)] + [object] $Hashtable, + + # The path of the .psd1 file to export. + [Parameter(Mandatory)] + [string] $Path, + + # Force the export, even if the file already exists. + [Parameter()] + [switch] $Force + ) + + $content = Convert-HashtableToString -Hashtable $Hashtable + $content | Out-File -FilePath $Path -Force:$Force + Format-ModuleManifest -Path $Path +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 new file mode 100644 index 00000000..d5b1267a --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 @@ -0,0 +1,32 @@ +function Format-ModuleManifest { + <# + .SYNOPSIS + Formats a module manifest file. + + .DESCRIPTION + This function formats a module manifest file, by removing comments and empty lines, + and then formatting the file using the `Invoke-Formatter` function. + + .EXAMPLE + Format-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' + #> + [CmdletBinding()] + param( + # Path to the module manifest file. + [Parameter(Mandatory)] + [string] $Path + ) + + $Utf8BomEncoding = New-Object System.Text.UTF8Encoding $true + + $manifestContent = Get-Content -Path $Path + $manifestContent = $manifestContent | ForEach-Object { $_ -replace '#.*' } + $manifestContent = $manifestContent | ForEach-Object { $_.TrimEnd() } + $manifestContent = $manifestContent | Where-Object { $_ | IsNotNullOrEmpty } + [System.IO.File]::WriteAllLines($Path, $manifestContent, $Utf8BomEncoding) + $manifestContent = Get-Content -Path $Path -Raw + + $content = Invoke-Formatter -ScriptDefinition $manifestContent + [System.IO.File]::WriteAllLines($Path, $content, $Utf8BomEncoding) + +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 new file mode 100644 index 00000000..a3afd35b --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 @@ -0,0 +1,121 @@ +function Get-ModuleManifest { + <# + .SYNOPSIS + Get the module manifest. + + .DESCRIPTION + Get the module manifest as a path, file info, content, or hashtable. + + .EXAMPLE + Get-PSModuleManifest -Path 'src/PSModule/PSModule.psd1' -As Hashtable + #> + [OutputType([string], [System.IO.FileInfo], [System.Collections.Hashtable], [System.Collections.Specialized.OrderedDictionary])] + [CmdletBinding()] + param( + # Path to the module manifest file. + [Parameter(Mandatory)] + [string] $Path, + + # The format of the output. + [Parameter()] + [ValidateSet('FileInfo', 'Content', 'Hashtable')] + [string] $As = 'Hashtable' + ) + + if (-not (Test-Path -Path $Path)) { + Write-Warning 'No manifest file found.' + return $null + } + Write-Verbose "Found manifest file [$Path]" + + switch ($As) { + 'FileInfo' { + return Get-Item -Path $Path + } + 'Content' { + return Get-Content -Path $Path + } + 'Hashtable' { + $manifest = [System.Collections.Specialized.OrderedDictionary]@{} + $psData = [System.Collections.Specialized.OrderedDictionary]@{} + $privateData = [System.Collections.Specialized.OrderedDictionary]@{} + $tempManifest = Import-PowerShellDataFile -Path $Path + if ($tempManifest.ContainsKey('PrivateData')) { + $tempPrivateData = $tempManifest.PrivateData + if ($tempPrivateData.ContainsKey('PSData')) { + $tempPSData = $tempPrivateData.PSData + $tempPrivateData.Remove('PSData') + } + } + + $psdataOrder = @( + 'Tags' + 'LicenseUri' + 'ProjectUri' + 'IconUri' + 'ReleaseNotes' + 'Prerelease' + 'RequireLicenseAcceptance' + 'ExternalModuleDependencies' + ) + foreach ($key in $psdataOrder) { + if (($null -ne $tempPSData) -and ($tempPSData.ContainsKey($key))) { + $psData.$key = $tempPSData.$key + } + } + if ($psData.Count -gt 0) { + $privateData.PSData = $psData + } else { + $privateData.Remove('PSData') + } + foreach ($key in $tempPrivateData.Keys) { + $privateData.$key = $tempPrivateData.$key + } + + $manifestOrder = @( + 'RootModule' + 'ModuleVersion' + 'CompatiblePSEditions' + 'GUID' + 'Author' + 'CompanyName' + 'Copyright' + 'Description' + 'PowerShellVersion' + 'PowerShellHostName' + 'PowerShellHostVersion' + 'DotNetFrameworkVersion' + 'ClrVersion' + 'ProcessorArchitecture' + 'RequiredModules' + 'RequiredAssemblies' + 'ScriptsToProcess' + 'TypesToProcess' + 'FormatsToProcess' + 'NestedModules' + 'FunctionsToExport' + 'CmdletsToExport' + 'VariablesToExport' + 'AliasesToExport' + 'DscResourcesToExport' + 'ModuleList' + 'FileList' + 'HelpInfoURI' + 'DefaultCommandPrefix' + 'PrivateData' + ) + foreach ($key in $manifestOrder) { + if ($tempManifest.ContainsKey($key)) { + $manifest.$key = $tempManifest.$key + } + } + if ($privateData.Count -gt 0) { + $manifest.PrivateData = $privateData + } else { + $manifest.Remove('PrivateData') + } + + return $manifest + } + } +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 new file mode 100644 index 00000000..1b21131a --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 @@ -0,0 +1,58 @@ +function Invoke-PruneModule { + <# + .SYNOPSIS + Remove all but the newest version of a module + + .DESCRIPTION + Remove all but the newest version of a module + + .EXAMPLE + Invoke-PruneModule -Name 'Az.*' -Scope CurrentUser + #> + [OutputType([void])] + [CmdletBinding()] + [Alias('Prune-Module')] + param ( + # Name of the module(s) to prune + [Parameter()] + [string[]] $Name = '*', + + # Scope of the module(s) to prune + [Parameter()] + [ValidateSet('CurrentUser', 'AllUsers')] + [string[]] $Scope = 'CurrentUser' + ) + + if ($Scope -eq 'AllUsers' -and -not (IsAdmin)) { + $message = 'Administrator rights are required to uninstall modules for all users. Please run the command again with' + + " elevated rights (Run as Administrator) or provide '-Scope CurrentUser' to your command." + + throw $message + } + + $UpdateableModules = Get-InstalledModule | Where-Object Name -Like "$Name" + $UpdateableModuleNames = $UpdateableModules.Name | Sort-Object -Unique + foreach ($UpdateableModuleName in $UpdateableModuleNames) { + $UpdateableModule = $UpdateableModules | Where-Object Name -EQ $UpdateableModuleName | Sort-Object -Property Version -Descending + Write-Verbose "[$($UpdateableModuleName)] - Found [$($UpdateableModule.Count)]" + + $NewestModule = $UpdateableModule | Select-Object -First 1 + Write-Verbose "[$($UpdateableModuleName)] - Newest [$($NewestModule.Version -join ', ')]" + + $OutdatedModules = $UpdateableModule | Select-Object -Skip 1 + Write-Verbose "[$($UpdateableModuleName)] - Outdated [$($OutdatedModules.Version -join ', ')]" + + foreach ($OutdatedModule in $OutdatedModules) { + Write-Verbose "[$($UpdateableModuleName)] - [$($OutdatedModule.Version)] - Removing" + $OutdatedModule | Remove-Module -Force + Write-Verbose "[$($UpdateableModuleName)] - [$($OutdatedModule.Version)] - Uninstalling" + Uninstall-Module -Name $OutdatedModule.Name -RequiredVersion -Force + try { + $OutdatedModule.ModuleBase | Remove-Item -Force -Recurse -ErrorAction Stop + } catch { + Write-Warning "[$($UpdateableModuleName)] - [$($OutdatedModule.Version)] - Failed to remove [$($OutdatedModule.ModuleBase)]" + continue + } + } + } +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 new file mode 100644 index 00000000..448deb1e --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 @@ -0,0 +1,61 @@ +function Invoke-ReinstallModule { + <# + .SYNOPSIS + Reinstalls module into a given scope. + + .DESCRIPTION + Reinstalls module into a given scope. This is useful when you want to reinstall or clean up your module versions. + With this command you always get the newest available version of the module and all the previous version wiped out. + + .PARAMETER Name + The name of the module to be reinstalled. Wildcards are supported. + + .PARAMETER Scope + The scope of the module to will be reinstalled to. + + .EXAMPLE + Reinstall-Module -Name Pester -Scope CurrentUser + + Reinstall Pester module for the current user. + + .EXAMPLE + Reinstall-Module -Scope CurrentUser + + Reinstall all reinstallable modules into the current user. + #> + [CmdletBinding()] + [Alias('Reinstall-Module')] + param ( + # Name of the module(s) to reinstall + [Parameter()] + [SupportsWildcards()] + [string[]] $Name = '*', + + # Scope of the module(s) to reinstall + [Parameter()] + [ValidateSet('CurrentUser', 'AllUsers')] + [string[]] $Scope = 'CurrentUser' + ) + + if ($Scope -eq 'AllUsers' -and -not (IsAdmin)) { + $message = 'Administrator rights are required to uninstall modules for all users. Please run the command again with' + + " elevated rights (Run as Administrator) or provide '-Scope CurrentUser' to your command." + + throw $message + } + + $modules = Get-InstalledModule | Where-Object Name -Like "$Name" + Write-Verbose "Found [$($modules.Count)] modules" + + $modules | ForEach-Object { + if ($_.name -eq 'Pester') { + Uninstall-Pester -All + continue + } + Uninstall-Module -Name $_ -AllVersions -Force -ErrorAction SilentlyContinue + } + + $modules.Name | ForEach-Object { + Install-Module -Name $_ -Scope $Scope -Force + } +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 new file mode 100644 index 00000000..558857af --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 @@ -0,0 +1,325 @@ +filter Set-ModuleManifest { + <# + .SYNOPSIS + Sets the values of a module manifest file. + + .DESCRIPTION + This function sets the values of a module manifest file. + Very much like the Update-ModuleManifest function, but allows values to be missing. + + .EXAMPLE + Set-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' -ModuleVersion '1.0.0' + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', '', + Justification = 'Function does not change state.' + )] + [CmdletBinding()] + param( + # Path to the module manifest file. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [string] $Path, + + #Script module or binary module file associated with this manifest. + [Parameter()] + [AllowNull()] + [string] $RootModule, + + #Version number of this module. + [Parameter()] + [AllowNull()] + [Version] $ModuleVersion, + + # Supported PSEditions. + [Parameter()] + [AllowNull()] + [string[]] $CompatiblePSEditions, + + # ID used to uniquely identify this module. + [Parameter()] + [AllowNull()] + [guid] $GUID, + + # Author of this module. + [Parameter()] + [AllowNull()] + [string] $Author, + + # Company or vendor of this module. + [Parameter()] + [AllowNull()] + [string] $CompanyName, + + # Copyright statement for this module. + [Parameter()] + [AllowNull()] + [string] $Copyright, + + # Description of the functionality provided by this module. + [Parameter()] + [AllowNull()] + [string] $Description, + + # Minimum version of the PowerShell engine required by this module. + [Parameter()] + [AllowNull()] + [Version] $PowerShellVersion, + + # Name of the PowerShell host required by this module. + [Parameter()] + [AllowNull()] + [string] $PowerShellHostName, + + # Minimum version of the PowerShell host required by this module. + [Parameter()] + [AllowNull()] + [version] $PowerShellHostVersion, + + # Minimum version of Microsoft .NET Framework required by this module. + # This prerequisite is valid for the PowerShell Desktop edition only. + [Parameter()] + [AllowNull()] + [Version] $DotNetFrameworkVersion, + + # Minimum version of the common language runtime (CLR) required by this module. + # This prerequisite is valid for the PowerShell Desktop edition only. + [Parameter()] + [AllowNull()] + [Version] $ClrVersion, + + # Processor architecture (None,X86, Amd64) required by this module + [Parameter()] + [AllowNull()] + [System.Reflection.ProcessorArchitecture] $ProcessorArchitecture, + + # Modules that must be imported into the global environment prior to importing this module. + [Parameter()] + [AllowNull()] + [Object[]] $RequiredModules, + + # Assemblies that must be loaded prior to importing this module. + [Parameter()] + [AllowNull()] + [string[]] $RequiredAssemblies, + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + [Parameter()] + [AllowNull()] + [string[]] $ScriptsToProcess, + + # Type files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [AllowNull()] + [string[]] $TypesToProcess, + + # Format files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [AllowNull()] + [string[]] $FormatsToProcess, + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. + [Parameter()] + [AllowNull()] + [Object[]] $NestedModules, + + # Functions to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no functions to export. + [Parameter()] + [AllowNull()] + [string[]] $FunctionsToExport, + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no cmdlets to export. + [Parameter()] + [AllowNull()] + [string[]] $CmdletsToExport, + + # Variables to export from this module. + [Parameter()] + [AllowNull()] + [string[]] $VariablesToExport, + + # Aliases to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no aliases to export. + [Parameter()] + [AllowNull()] + [string[]] $AliasesToExport, + + # DSC resources to export from this module. + [Parameter()] + [AllowNull()] + [string[]] $DscResourcesToExport, + + # List of all modules packaged with this module. + [Parameter()] + [AllowNull()] + [Object[]] $ModuleList, + + # List of all files packaged with this module. + [Parameter()] + [AllowNull()] + [string[]] $FileList, + + # Tags applied to this module. These help with module discovery in online galleries. + [Parameter()] + [AllowNull()] + [string[]] $Tags, + + # A URL to the license for this module. + [Parameter()] + [AllowNull()] + [uri] $LicenseUri, + + # A URL to the main site for this project. + [Parameter()] + [AllowNull()] + [uri] $ProjectUri, + + # A URL to an icon representing this module. + [Parameter()] + [AllowNull()] + [uri] $IconUri, + + # ReleaseNotes of this module. + [Parameter()] + [AllowNull()] + [string] $ReleaseNotes, + + # Prerelease string of this module. + [Parameter()] + [AllowNull()] + [string] $Prerelease, + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save. + [Parameter()] + [AllowNull()] + [bool] $RequireLicenseAcceptance, + + # External dependent modules of this module. + [Parameter()] + [AllowNull()] + [string[]] $ExternalModuleDependencies, + + # HelpInfo URI of this module. + [Parameter()] + [AllowNull()] + [String] $HelpInfoURI, + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + [Parameter()] + [AllowNull()] + [string] $DefaultCommandPrefix, + + # Private data to pass to the module specified in RootModule/ModuleToProcess. + # This may also contain a PSData hashtable with additional module metadata used by PowerShell. + [Parameter()] + [AllowNull()] + [object] $PrivateData + ) + + $outManifest = [ordered]@{} + $outPSData = [ordered]@{} + $outPrivateData = [ordered]@{} + + $tempManifest = Get-ModuleManifest -Path $Path + if ($tempManifest.Keys.Contains('PrivateData')) { + $tempPrivateData = $tempManifest.PrivateData + if ($tempPrivateData.Keys.Contains('PSData')) { + $tempPSData = $tempPrivateData.PSData + $tempPrivateData.Remove('PSData') + } + } + + $psdataOrder = @( + 'Tags' + 'LicenseUri' + 'ProjectUri' + 'IconUri' + 'ReleaseNotes' + 'Prerelease' + 'RequireLicenseAcceptance' + 'ExternalModuleDependencies' + ) + foreach ($key in $psdataOrder) { + if (($null -ne $tempPSData) -and $tempPSData.Keys.Contains($key)) { + $outPSData[$key] = $tempPSData[$key] + } + if ($PSBoundParameters.Keys.Contains($key)) { + if ($null -eq $PSBoundParameters[$key]) { + $outPSData.Remove($key) + } else { + $outPSData[$key] = $PSBoundParameters[$key] + } + } + } + + if ($outPSData.Count -gt 0) { + $outPrivateData.PSData = $outPSData + } else { + $outPrivateData.Remove('PSData') + } + foreach ($key in $tempPrivateData.Keys) { + $outPrivateData[$key] = $tempPrivateData[$key] + } + foreach ($key in $PrivateData.Keys) { + $outPrivateData[$key] = $PrivateData[$key] + } + + $manifestOrder = @( + 'RootModule' + 'ModuleVersion' + 'CompatiblePSEditions' + 'GUID' + 'Author' + 'CompanyName' + 'Copyright' + 'Description' + 'PowerShellVersion' + 'PowerShellHostName' + 'PowerShellHostVersion' + 'DotNetFrameworkVersion' + 'ClrVersion' + 'ProcessorArchitecture' + 'RequiredModules' + 'RequiredAssemblies' + 'ScriptsToProcess' + 'TypesToProcess' + 'FormatsToProcess' + 'NestedModules' + 'FunctionsToExport' + 'CmdletsToExport' + 'VariablesToExport' + 'AliasesToExport' + 'DscResourcesToExport' + 'ModuleList' + 'FileList' + 'HelpInfoURI' + 'DefaultCommandPrefix' + 'PrivateData' + ) + foreach ($key in $manifestOrder) { + if ($tempManifest.Keys.Contains($key)) { + $outManifest[$key] = $tempManifest[$key] + } + if ($PSBoundParameters.Keys.Contains($key)) { + if ($null -eq $PSBoundParameters[$key]) { + $outManifest.Remove($key) + } else { + $outManifest[$key] = $PSBoundParameters[$key] + } + } + } + if ($outPrivateData.Count -gt 0) { + $outManifest['PrivateData'] = $outPrivateData + } else { + $outManifest.Remove('PrivateData') + } + + Remove-Item -Path $Path -Force + Export-PowerShellDataFile -Hashtable $outManifest -Path $Path + +} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 new file mode 100644 index 00000000..2b69a265 --- /dev/null +++ b/scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 @@ -0,0 +1,54 @@ +function Uninstall-Pester { + <# + .SYNOPSIS + Uninstall Pester 3 from Program Files and Program Files (x86) + + .DESCRIPTION + Uninstall Pester 3 from Program Files and Program Files (x86). This is useful + when you want to install Pester 4 and you have Pester 3 installed. + + .PARAMETER All + + .EXAMPLE + Uninstall-Pester + + Uninstall Pester 3 from Program Files and Program Files (x86). + + .EXAMPLE + Uninstall-Pester -All + + Completely remove all built-in Pester 3 installations. + #> + [OutputType([String])] + [CmdletBinding()] + param ( + # Completely remove all built-in Pester 3 installations + [Parameter()] + [switch] $All + ) + + $pesterPaths = foreach ($programFiles in ($env:ProgramFiles, ${env:ProgramFiles(x86)})) { + $path = "$programFiles\WindowsPowerShell\Modules\Pester" + if ($null -ne $programFiles -and (Test-Path $path)) { + if ($All) { + Get-Item $path + } else { + Get-ChildItem "$path\3.*" + } + } + } + + if (-not $pesterPaths) { + "There are no Pester$(if (-not $all) {' 3'}) installations in Program Files and Program Files (x86) doing nothing." + return + } + + foreach ($pesterPath in $pesterPaths) { + takeown /F $pesterPath /A /R + icacls $pesterPath /reset + # grant permissions to Administrators group, but use SID to do + # it because it is localized on non-us installations of Windows + icacls $pesterPath /grant '*S-1-5-32-544:F' /inheritance:d /T + Remove-Item -Path $pesterPath -Recurse -Force -Confirm:$false + } +} From b64a89bd56bea3fc41e15c7b6c738046c4c1dbfc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:33:28 +0100 Subject: [PATCH 11/25] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Replace=20Wr?= =?UTF-8?q?ite-Verbose=20with=20Write-Host=20for=20improved=20output=20vis?= =?UTF-8?q?ibility=20in=20module=20build=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build-PSModule.ps1 | 8 +- scripts/helpers/Build/Build-PSModuleBase.ps1 | 2 +- .../helpers/Build/Build-PSModuleManifest.ps1 | 160 +++++++++--------- scripts/main.ps1 | 10 +- 4 files changed, 90 insertions(+), 90 deletions(-) diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index 4dbb4244..8188491b 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -32,19 +32,19 @@ function Build-PSModule { ) LogGroup "Building module [$ModuleName]" { - Write-Verbose "Source path: [$ModuleSourceFolderPath]" + Write-Host "Source path: [$ModuleSourceFolderPath]" if (-not (Test-Path -Path $ModuleSourceFolderPath)) { Write-Error "Source folder not found at [$ModuleSourceFolderPath]" exit 1 } $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath - Write-Verbose "Module source folder: [$moduleSourceFolder]" + Write-Host "Module source folder: [$moduleSourceFolder]" $moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force - Write-Verbose "Module output folder: [$moduleOutputFolder]" + Write-Host "Module output folder: [$moduleOutputFolder]" $docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force - Write-Verbose "Docs output folder: [$docsOutputFolder]" + Write-Host "Docs output folder: [$docsOutputFolder]" } Build-PSModuleBase -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder diff --git a/scripts/helpers/Build/Build-PSModuleBase.ps1 b/scripts/helpers/Build/Build-PSModuleBase.ps1 index 3b237313..e00a33fc 100644 --- a/scripts/helpers/Build/Build-PSModuleBase.ps1 +++ b/scripts/helpers/Build/Build-PSModuleBase.ps1 @@ -32,7 +32,7 @@ function Build-PSModuleBase { ) LogGroup 'Build base' { - Write-Verbose "Copying files from [$ModuleSourceFolder] to [$ModuleOutputFolder]" + Write-Host "Copying files from [$ModuleSourceFolder] to [$ModuleOutputFolder]" Copy-Item -Path "$ModuleSourceFolder\*" -Destination $ModuleOutputFolder -Recurse -Force -Verbose -Exclude "$ModuleName.psm1" New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -ItemType File -Force -Verbose } diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 34801a5e..c420b100 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -33,64 +33,64 @@ function Build-PSModuleManifest { LogGroup 'Build manifest file' { $sourceManifestFilePath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" - Write-Verbose "[SourceManifestFilePath] - [$sourceManifestFilePath]" + Write-Host "[SourceManifestFilePath] - [$sourceManifestFilePath]" if (-not (Test-Path -Path $sourceManifestFilePath)) { - Write-Verbose "[SourceManifestFilePath] - [$sourceManifestFilePath] - Not found" + Write-Host "[SourceManifestFilePath] - [$sourceManifestFilePath] - Not found" $sourceManifestFilePath = Join-Path -Path $ModuleOutputFolder -ChildPath 'manifest.psd1' } if (-not (Test-Path -Path $sourceManifestFilePath)) { - Write-Verbose "[SourceManifestFilePath] - [$sourceManifestFilePath] - Not found" + Write-Host "[SourceManifestFilePath] - [$sourceManifestFilePath] - Not found" $manifest = @{} - Write-Verbose '[Manifest] - Loading empty manifest' + Write-Host '[Manifest] - Loading empty manifest' } else { - Write-Verbose "[SourceManifestFilePath] - [$sourceManifestFilePath] - Found" + Write-Host "[SourceManifestFilePath] - [$sourceManifestFilePath] - Found" $manifest = Get-ModuleManifest -Path $sourceManifestFilePath -Verbose:$false - Write-Verbose '[Manifest] - Loading from file' + Write-Host '[Manifest] - Loading from file' Remove-Item -Path $sourceManifestFilePath -Force -Verbose:$false } $rootModule = "$ModuleName.psm1" $manifest.RootModule = $rootModule - Write-Verbose "[RootModule] - [$($manifest.RootModule)]" + Write-Host "[RootModule] - [$($manifest.RootModule)]" $manifest.ModuleVersion = '999.0.0' - Write-Verbose "[ModuleVersion] - [$($manifest.ModuleVersion)]" + Write-Host "[ModuleVersion] - [$($manifest.ModuleVersion)]" $manifest.Author = $manifest.Keys -contains 'Author' ? ($manifest.Author | IsNotNullOrEmpty) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER - Write-Verbose "[Author] - [$($manifest.Author)]" + Write-Host "[Author] - [$($manifest.Author)]" $manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? ($manifest.CompanyName | IsNotNullOrEmpty) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER - Write-Verbose "[CompanyName] - [$($manifest.CompanyName)]" + Write-Host "[CompanyName] - [$($manifest.CompanyName)]" $year = Get-Date -Format 'yyyy' $copyrightOwner = $manifest.CompanyName -eq $manifest.Author ? $manifest.Author : "$($manifest.Author) | $($manifest.CompanyName)" $copyright = "(c) $year $copyrightOwner. All rights reserved." $manifest.Copyright = $manifest.Keys -contains 'Copyright' ? -not [string]::IsNullOrEmpty($manifest.Copyright) ? $manifest.Copyright : $copyright : $copyright - Write-Verbose "[Copyright] - [$($manifest.Copyright)]" + Write-Host "[Copyright] - [$($manifest.Copyright)]" $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription - Write-Verbose "[Description] - [$($manifest.Description)]" + Write-Host "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null - Write-Verbose "[PowerShellHostName] - [$($manifest.PowerShellHostName)]" + Write-Host "[PowerShellHostName] - [$($manifest.PowerShellHostName)]" $manifest.PowerShellHostVersion = $manifest.Keys -contains 'PowerShellHostVersion' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostVersion) ? $manifest.PowerShellHostVersion : $null : $null - Write-Verbose "[PowerShellHostVersion] - [$($manifest.PowerShellHostVersion)]" + Write-Host "[PowerShellHostVersion] - [$($manifest.PowerShellHostVersion)]" $manifest.DotNetFrameworkVersion = $manifest.Keys -contains 'DotNetFrameworkVersion' ? -not [string]::IsNullOrEmpty($manifest.DotNetFrameworkVersion) ? $manifest.DotNetFrameworkVersion : $null : $null - Write-Verbose "[DotNetFrameworkVersion] - [$($manifest.DotNetFrameworkVersion)]" + Write-Host "[DotNetFrameworkVersion] - [$($manifest.DotNetFrameworkVersion)]" $manifest.ClrVersion = $manifest.Keys -contains 'ClrVersion' ? -not [string]::IsNullOrEmpty($manifest.ClrVersion) ? $manifest.ClrVersion : $null : $null - Write-Verbose "[ClrVersion] - [$($manifest.ClrVersion)]" + Write-Host "[ClrVersion] - [$($manifest.ClrVersion)]" $manifest.ProcessorArchitecture = $manifest.Keys -contains 'ProcessorArchitecture' ? -not [string]::IsNullOrEmpty($manifest.ProcessorArchitecture) ? $manifest.ProcessorArchitecture : 'None' : 'None' - Write-Verbose "[ProcessorArchitecture] - [$($manifest.ProcessorArchitecture)]" + Write-Host "[ProcessorArchitecture] - [$($manifest.ProcessorArchitecture)]" # Get the path separator for the current OS $pathSeparator = [System.IO.Path]::DirectorySeparatorChar - Write-Verbose '[FileList]' + Write-Host '[FileList]' $files = [System.Collections.Generic.List[System.IO.FileInfo]]::new() # Get files on module root @@ -105,27 +105,27 @@ function Build-PSModuleManifest { # Get the relative file path and store it in the manifest $files = $files | Select-Object -ExpandProperty FullName | ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) } $manifest.FileList = $files.count -eq 0 ? @() : @($files) - $manifest.FileList | ForEach-Object { Write-Verbose "[FileList] - [$_]" } + $manifest.FileList | ForEach-Object { Write-Host "[FileList] - [$_]" } - Write-Verbose '[RequiredAssemblies]' + Write-Host '[RequiredAssemblies]' $requiredAssembliesFolderPath = Join-Path $ModuleOutputFolder 'assemblies' $requiredAssemblies = Get-ChildItem -Path $RequiredAssembliesFolderPath -Recurse -File -ErrorAction SilentlyContinue -Filter '*.dll' | Select-Object -ExpandProperty FullName | ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) } $manifest.RequiredAssemblies = $requiredAssemblies.count -eq 0 ? @() : @($requiredAssemblies) - $manifest.RequiredAssemblies | ForEach-Object { Write-Verbose "[RequiredAssemblies] - [$_]" } + $manifest.RequiredAssemblies | ForEach-Object { Write-Host "[RequiredAssemblies] - [$_]" } - Write-Verbose '[NestedModules]' + Write-Host '[NestedModules]' $nestedModulesFolderPath = Join-Path $ModuleOutputFolder 'modules' $nestedModules = Get-ChildItem -Path $nestedModulesFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.psm1', '*.ps1' | Select-Object -ExpandProperty FullName | ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) } $manifest.NestedModules = $nestedModules.count -eq 0 ? @() : @($nestedModules) - $manifest.NestedModules | ForEach-Object { Write-Verbose "[NestedModules] - [$_]" } + $manifest.NestedModules | ForEach-Object { Write-Host "[NestedModules] - [$_]" } - Write-Verbose '[ScriptsToProcess]' + Write-Host '[ScriptsToProcess]' $allScriptsToProcess = @('scripts') | ForEach-Object { - Write-Verbose "[ScriptsToProcess] - Processing [$_]" + Write-Host "[ScriptsToProcess] - Processing [$_]" $scriptsFolderPath = Join-Path $ModuleOutputFolder $_ $scriptsToProcess = Get-ChildItem -Path $scriptsFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.ps1' | Select-Object -ExpandProperty FullName | @@ -133,52 +133,52 @@ function Build-PSModuleManifest { $scriptsToProcess } $manifest.ScriptsToProcess = $allScriptsToProcess.count -eq 0 ? @() : @($allScriptsToProcess) - $manifest.ScriptsToProcess | ForEach-Object { Write-Verbose "[ScriptsToProcess] - [$_]" } + $manifest.ScriptsToProcess | ForEach-Object { Write-Host "[ScriptsToProcess] - [$_]" } - Write-Verbose '[TypesToProcess]' + Write-Host '[TypesToProcess]' $typesToProcess = Get-ChildItem -Path $ModuleOutputFolder -Recurse -File -ErrorAction SilentlyContinue -Include '*.Types.ps1xml' | Select-Object -ExpandProperty FullName | ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) } $manifest.TypesToProcess = $typesToProcess.count -eq 0 ? @() : @($typesToProcess) - $manifest.TypesToProcess | ForEach-Object { Write-Verbose "[TypesToProcess] - [$_]" } + $manifest.TypesToProcess | ForEach-Object { Write-Host "[TypesToProcess] - [$_]" } - Write-Verbose '[FormatsToProcess]' + Write-Host '[FormatsToProcess]' $formatsToProcess = Get-ChildItem -Path $ModuleOutputFolder -Recurse -File -ErrorAction SilentlyContinue -Include '*.Format.ps1xml' | Select-Object -ExpandProperty FullName | ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) } $manifest.FormatsToProcess = $formatsToProcess.count -eq 0 ? @() : @($formatsToProcess) - $manifest.FormatsToProcess | ForEach-Object { Write-Verbose "[FormatsToProcess] - [$_]" } + $manifest.FormatsToProcess | ForEach-Object { Write-Host "[FormatsToProcess] - [$_]" } - Write-Verbose '[DscResourcesToExport]' + Write-Host '[DscResourcesToExport]' $dscResourcesToExportFolderPath = Join-Path $ModuleOutputFolder 'resources' $dscResourcesToExport = Get-ChildItem -Path $dscResourcesToExportFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.psm1' | Select-Object -ExpandProperty FullName | ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) } $manifest.DscResourcesToExport = $dscResourcesToExport.count -eq 0 ? @() : @($dscResourcesToExport) - $manifest.DscResourcesToExport | ForEach-Object { Write-Verbose "[DscResourcesToExport] - [$_]" } + $manifest.DscResourcesToExport | ForEach-Object { Write-Host "[DscResourcesToExport] - [$_]" } $manifest.FunctionsToExport = Get-PSModuleFunctionsToExport -SourceFolderPath $ModuleOutputFolder $manifest.CmdletsToExport = Get-PSModuleCmdletsToExport -SourceFolderPath $ModuleOutputFolder $manifest.AliasesToExport = Get-PSModuleAliasesToExport -SourceFolderPath $ModuleOutputFolder $manifest.VariablesToExport = Get-PSModuleVariablesToExport -SourceFolderPath $ModuleOutputFolder - Write-Verbose '[ModuleList]' + Write-Host '[ModuleList]' $moduleList = Get-ChildItem -Path $ModuleOutputFolder -Recurse -File -ErrorAction SilentlyContinue -Include '*.psm1' | Where-Object -Property Name -NE $rootModule | Select-Object -ExpandProperty FullName | ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) } $manifest.ModuleList = $moduleList.count -eq 0 ? @() : @($moduleList) - $manifest.ModuleList | ForEach-Object { Write-Verbose "[ModuleList] - [$_]" } + $manifest.ModuleList | ForEach-Object { Write-Host "[ModuleList] - [$_]" } - Write-Verbose '[Gather]' + Write-Host '[Gather]' $capturedModules = [System.Collections.Generic.List[System.Object]]::new() $capturedVersions = [System.Collections.Generic.List[string]]::new() $capturedPSEdition = [System.Collections.Generic.List[string]]::new() $files = $ModuleOutputFolder | Get-ChildItem -Recurse -File -ErrorAction SilentlyContinue - Write-Verbose "[Gather] - Processing [$($files.Count)] files" + Write-Host "[Gather] - Processing [$($files.Count)] files" foreach ($file in $files) { $relativePath = $file.FullName.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) - Write-Verbose "[Gather] - [$relativePath]" + Write-Host "[Gather] - [$relativePath]" if ($file.extension -in '.psm1', '.ps1') { $fileContent = Get-Content -Path $file @@ -191,21 +191,21 @@ function Build-PSModuleManifest { $capturedMatches | ForEach-Object { $hashtable = '@\{[^}]*\}' if ($_ -match $hashtable) { - Write-Verbose " - [#Requires -Modules] - [$_] - Hashtable" + Write-Host " - [#Requires -Modules] - [$_] - Hashtable" } else { - Write-Verbose " - [#Requires -Modules] - [$_] - String" + Write-Host " - [#Requires -Modules] - [$_] - String" } $capturedModules.Add($_) } } # PowerShellVersion -> REQUIRES -Version [.], $null if not provided '^\s*#Requires -Version (.+)$' { - Write-Verbose " - [#Requires -Version] - [$($matches[1])]" + Write-Host " - [#Requires -Version] - [$($matches[1])]" $capturedVersions.Add($matches[1]) } #CompatiblePSEditions -> REQUIRES -PSEdition , $null if not provided '^\s*#Requires -PSEdition (.+)$' { - Write-Verbose " - [#Requires -PSEdition] - [$($matches[1])]" + Write-Host " - [#Requires -PSEdition] - [$($matches[1])]" $capturedPSEdition.Add($matches[1]) } } @@ -223,7 +223,7 @@ function Build-PSModuleManifest { $required.ToString() #> - Write-Verbose '[RequiredModules] - Gathered' + Write-Host '[RequiredModules] - Gathered' # Group the module specifications by ModuleName $capturedModules = $capturedModules | ForEach-Object { $test = [Microsoft.PowerShell.Commands.ModuleSpecification]::new() @@ -242,13 +242,13 @@ function Build-PSModuleManifest { # Iterate through each group foreach ($group in $groupedModules) { $requiredModuleName = $group.Name - Write-Verbose "Processing required module [$requiredModuleName]" + Write-Host "Processing required module [$requiredModuleName]" $requiredVersion = $group.Group.RequiredVersion | ForEach-Object { [Version]$_ } | Sort-Object -Unique $minimumVersion = $group.Group.Version | ForEach-Object { [Version]$_ } | Sort-Object -Unique | Select-Object -Last 1 $maximumVersion = $group.Group.MaximumVersion | ForEach-Object { [Version]$_ } | Sort-Object -Unique | Select-Object -First 1 - Write-Verbose "RequiredVersion: [$($requiredVersion -join ', ')]" - Write-Verbose "ModuleVersion: [$minimumVersion]" - Write-Verbose "MaximumVersion: [$maximumVersion]" + Write-Host "RequiredVersion: [$($requiredVersion -join ', ')]" + Write-Host "ModuleVersion: [$minimumVersion]" + Write-Host "MaximumVersion: [$maximumVersion]" if ($requiredVersion.Count -gt 1) { throw 'Multiple RequiredVersions specified.' @@ -274,13 +274,13 @@ function Build-PSModuleManifest { } if ($requiredVersion) { - Write-Verbose '[RequiredModules] - RequiredVersion' + Write-Host '[RequiredModules] - RequiredVersion' $uniqueModule = @{ ModuleName = $requiredModuleName RequiredVersion = $requiredVersion } } elseif (($minimumVersion -ne [Version]'0.0.0') -or ($maximumVersion -ne [Version]'9999.9999.9999')) { - Write-Verbose '[RequiredModules] - ModuleVersion/MaximumVersion' + Write-Host '[RequiredModules] - ModuleVersion/MaximumVersion' $uniqueModule = @{ ModuleName = $requiredModuleName } @@ -291,61 +291,61 @@ function Build-PSModuleManifest { $uniqueModule['MaximumVersion'] = $maximumVersion } } else { - Write-Verbose '[RequiredModules] - Simple string' + Write-Host '[RequiredModules] - Simple string' $uniqueModule = $requiredModuleName } $uniqueModules.Add([Microsoft.PowerShell.Commands.ModuleSpecification]::new($uniqueModule)) } - Write-Verbose '[RequiredModules] - Result' + Write-Host '[RequiredModules] - Result' $manifest.RequiredModules = $uniqueModules - $manifest.RequiredModules | ForEach-Object { Write-Verbose " - [$($_ | Out-String)]" } + $manifest.RequiredModules | ForEach-Object { Write-Host " - [$($_ | Out-String)]" } - Write-Verbose '[PowerShellVersion]' + Write-Host '[PowerShellVersion]' $capturedVersions = $capturedVersions | Sort-Object -Unique -Descending - $capturedVersions | ForEach-Object { Write-Verbose "[PowerShellVersion] - [$_]" } + $capturedVersions | ForEach-Object { Write-Host "[PowerShellVersion] - [$_]" } $manifest.PowerShellVersion = $capturedVersions.count -eq 0 ? [version]'5.1' : [version]($capturedVersions | Select-Object -First 1) - Write-Verbose '[PowerShellVersion] - Selecting version' - Write-Verbose "[PowerShellVersion] - [$($manifest.PowerShellVersion)]" + Write-Host '[PowerShellVersion] - Selecting version' + Write-Host "[PowerShellVersion] - [$($manifest.PowerShellVersion)]" - Write-Verbose '[CompatiblePSEditions]' + Write-Host '[CompatiblePSEditions]' $capturedPSEdition = $capturedPSEdition | Sort-Object -Unique if ($capturedPSEdition.count -eq 2) { throw "Conflict detected: The module requires both 'Desktop' and 'Core' editions." + "'Desktop' and 'Core' editions cannot be required at the same time." } if ($capturedPSEdition.count -eq 0 -and $manifest.PowerShellVersion -gt '5.1') { - Write-Verbose "[CompatiblePSEditions] - Defaulting to 'Core', as no PSEdition was specified and PowerShellVersion > 5.1" + Write-Host "[CompatiblePSEditions] - Defaulting to 'Core', as no PSEdition was specified and PowerShellVersion > 5.1" $capturedPSEdition = @('Core') } $manifest.CompatiblePSEditions = $capturedPSEdition.count -eq 0 ? @('Core', 'Desktop') : @($capturedPSEdition) - $manifest.CompatiblePSEditions | ForEach-Object { Write-Verbose "[CompatiblePSEditions] - [$_]" } + $manifest.CompatiblePSEditions | ForEach-Object { Write-Host "[CompatiblePSEditions] - [$_]" } if ($manifest.PowerShellVersion -gt '5.1' -and $manifest.CompatiblePSEditions -contains 'Desktop') { throw "Conflict detected: The module requires PowerShellVersion > 5.1 while CompatiblePSEditions = 'Desktop'" + "'Desktop' edition is not supported for PowerShellVersion > 5.1" } - Write-Verbose '[PrivateData]' + Write-Host '[PrivateData]' $privateData = $manifest.Keys -contains 'PrivateData' ? $null -ne $manifest.PrivateData ? $manifest.PrivateData : @{} : @{} if ($manifest.Keys -contains 'PrivateData') { $manifest.Remove('PrivateData') } - Write-Verbose '[HelpInfoURI]' + Write-Host '[HelpInfoURI]' $manifest.HelpInfoURI = $privateData.Keys -contains 'HelpInfoURI' ? $null -ne $privateData.HelpInfoURI ? $privateData.HelpInfoURI : '' : '' - Write-Verbose "[HelpInfoURI] - [$($manifest.HelpInfoURI)]" + Write-Host "[HelpInfoURI] - [$($manifest.HelpInfoURI)]" if ([string]::IsNullOrEmpty($manifest.HelpInfoURI)) { $manifest.Remove('HelpInfoURI') } - Write-Verbose '[DefaultCommandPrefix]' + Write-Host '[DefaultCommandPrefix]' $manifest.DefaultCommandPrefix = $privateData.Keys -contains 'DefaultCommandPrefix' ? $null -ne $privateData.DefaultCommandPrefix ? $privateData.DefaultCommandPrefix : '' : '' - Write-Verbose "[DefaultCommandPrefix] - [$($manifest.DefaultCommandPrefix)]" + Write-Host "[DefaultCommandPrefix] - [$($manifest.DefaultCommandPrefix)]" $PSData = $privateData.Keys -contains 'PSData' ? $null -ne $privateData.PSData ? $privateData.PSData : @{} : @{} - Write-Verbose '[Tags]' + Write-Host '[Tags]' try { $repoLabels = gh repo view --json repositoryTopics | ConvertFrom-Json | Select-Object -ExpandProperty repositoryTopics | Select-Object -ExpandProperty name } catch { @@ -365,7 +365,7 @@ function Build-PSModuleManifest { $manifestTags.Add('PSEdition_Core') } } - $manifestTags | ForEach-Object { Write-Verbose "[Tags] - [$_]" } + $manifestTags | ForEach-Object { Write-Host "[Tags] - [$_]" } $manifest.Tags = $manifestTags if ($PSData.Tags -contains 'PSEdition_Core' -and $manifest.PowerShellVersion -lt '6.0') { @@ -378,59 +378,59 @@ function Build-PSModuleManifest { https://learn.microsoft.com/en-us/powershell/gallery/concepts/package-manifest-affecting-ui?view=powershellget-2.x#tag-details #> - Write-Verbose '[LicenseUri]' + Write-Host '[LicenseUri]' $licenseUri = "https://github.com/$env:GITHUB_REPOSITORY_OWNER/$env:GITHUB_REPOSITORY_NAME/blob/main/LICENSE" $manifest.LicenseUri = $PSData.Keys -contains 'LicenseUri' ? $null -ne $PSData.LicenseUri ? $PSData.LicenseUri : $licenseUri : $licenseUri - Write-Verbose "[LicenseUri] - [$($manifest.LicenseUri)]" + Write-Host "[LicenseUri] - [$($manifest.LicenseUri)]" if ([string]::IsNullOrEmpty($manifest.LicenseUri)) { $manifest.Remove('LicenseUri') } - Write-Verbose '[ProjectUri]' + Write-Host '[ProjectUri]' $projectUri = gh repo view --json url | ConvertFrom-Json | Select-Object -ExpandProperty url $manifest.ProjectUri = $PSData.Keys -contains 'ProjectUri' ? $null -ne $PSData.ProjectUri ? $PSData.ProjectUri : $projectUri : $projectUri - Write-Verbose "[ProjectUri] - [$($manifest.ProjectUri)]" + Write-Host "[ProjectUri] - [$($manifest.ProjectUri)]" if ([string]::IsNullOrEmpty($manifest.ProjectUri)) { $manifest.Remove('ProjectUri') } - Write-Verbose '[IconUri]' + Write-Host '[IconUri]' $iconUri = "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY_OWNER/$env:GITHUB_REPOSITORY_NAME/main/icon/icon.png" $manifest.IconUri = $PSData.Keys -contains 'IconUri' ? $null -ne $PSData.IconUri ? $PSData.IconUri : $iconUri : $iconUri - Write-Verbose "[IconUri] - [$($manifest.IconUri)]" + Write-Host "[IconUri] - [$($manifest.IconUri)]" if ([string]::IsNullOrEmpty($manifest.IconUri)) { $manifest.Remove('IconUri') } - Write-Verbose '[ReleaseNotes]' + Write-Host '[ReleaseNotes]' $manifest.ReleaseNotes = $PSData.Keys -contains 'ReleaseNotes' ? $null -ne $PSData.ReleaseNotes ? $PSData.ReleaseNotes : '' : '' - Write-Verbose "[ReleaseNotes] - [$($manifest.ReleaseNotes)]" + Write-Host "[ReleaseNotes] - [$($manifest.ReleaseNotes)]" if ([string]::IsNullOrEmpty($manifest.ReleaseNotes)) { $manifest.Remove('ReleaseNotes') } - Write-Verbose '[PreRelease]' + Write-Host '[PreRelease]' # $manifest.PreRelease = "" # Is managed by the publish action - Write-Verbose '[RequireLicenseAcceptance]' + Write-Host '[RequireLicenseAcceptance]' $manifest.RequireLicenseAcceptance = $PSData.Keys -contains 'RequireLicenseAcceptance' ? $null -ne $PSData.RequireLicenseAcceptance ? $PSData.RequireLicenseAcceptance : $false : $false - Write-Verbose "[RequireLicenseAcceptance] - [$($manifest.RequireLicenseAcceptance)]" + Write-Host "[RequireLicenseAcceptance] - [$($manifest.RequireLicenseAcceptance)]" if ($manifest.RequireLicenseAcceptance -eq $false) { $manifest.Remove('RequireLicenseAcceptance') } - Write-Verbose '[ExternalModuleDependencies]' + Write-Host '[ExternalModuleDependencies]' $manifest.ExternalModuleDependencies = $PSData.Keys -contains 'ExternalModuleDependencies' ? $null -ne $PSData.ExternalModuleDependencies ? $PSData.ExternalModuleDependencies : @() : @() if (($manifest.ExternalModuleDependencies).count -eq 0) { $manifest.Remove('ExternalModuleDependencies') } else { - $manifest.ExternalModuleDependencies | ForEach-Object { Write-Verbose "[ExternalModuleDependencies] - [$_]" } + $manifest.ExternalModuleDependencies | ForEach-Object { Write-Host "[ExternalModuleDependencies] - [$_]" } } - Write-Verbose 'Creating new manifest file in outputs folder' + Write-Host 'Creating new manifest file in outputs folder' $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" - Write-Verbose "OutputManifestPath - [$outputManifestPath]" + Write-Host "OutputManifestPath - [$outputManifestPath]" New-ModuleManifest -Path $outputManifestPath @manifest } diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 2cb2f7a2..2220d0e0 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -6,28 +6,28 @@ param() $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') LogGroup "Loading helper scripts from [$path]" { Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object { - Write-Verbose "[$($_.FullName)]" + Write-Host "[$($_.FullName)]" . $_.FullName } } LogGroup 'Loading inputs' { $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name - Write-Verbose "Module name: [$moduleName]" + Write-Host "Module name: [$moduleName]" $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path $moduleName if (-not (Test-Path -Path $moduleSourceFolderPath)) { $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path } - Write-Verbose "Source module path: [$moduleSourceFolderPath]" + Write-Host "Source module path: [$moduleSourceFolderPath]" if (-not (Test-Path -Path $moduleSourceFolderPath)) { throw "Module path [$moduleSourceFolderPath] does not exist." } $modulesOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_ModulesOutputPath - Write-Verbose "Modules output path: [$modulesOutputFolderPath]" + Write-Host "Modules output path: [$modulesOutputFolderPath]" $docsOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_DocsOutputPath - Write-Verbose "Docs output path: [$docsOutputFolderPath]" + Write-Host "Docs output path: [$docsOutputFolderPath]" } $params = @{ From a2be9de2b3b63c380d9170ef14e52aeb7ea81b6f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:37:35 +0100 Subject: [PATCH 12/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Escape=20single?= =?UTF-8?q?=20quotes=20in=20module=20manifest=20description=20assignment?= =?UTF-8?q?=20to=20prevent=20formatting=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index c420b100..d9e3c60a 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -70,6 +70,7 @@ function Build-PSModuleManifest { $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription + $manifest.Description = $manifest.Description -replace "'", "`'" Write-Host "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null From a637a3b505fb061d786c9e26115c1d382950eab7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:40:49 +0100 Subject: [PATCH 13/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Correctly=20escap?= =?UTF-8?q?e=20single=20quotes=20in=20module=20manifest=20description=20as?= =?UTF-8?q?signment=20to=20prevent=20formatting=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index d9e3c60a..618d7983 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -70,7 +70,7 @@ function Build-PSModuleManifest { $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription - $manifest.Description = $manifest.Description -replace "'", "`'" + $manifest.Description = $manifest.Description -replace "'", "``'" Write-Host "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null From 3bd0cf7d06586e92a40745221ab6d0dc457d4bc8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:45:01 +0100 Subject: [PATCH 14/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Escape=20single?= =?UTF-8?q?=20quotes=20in=20module=20manifest=20description=20and=20add=20?= =?UTF-8?q?verbose=20logging=20for=20escaped=20values=20in=20hashtable=20c?= =?UTF-8?q?onversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Build/Build-PSModuleManifest.ps1 | 1 - .../helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 618d7983..c420b100 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -70,7 +70,6 @@ function Build-PSModuleManifest { $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription - $manifest.Description = $manifest.Description -replace "'", "``'" Write-Host "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 index 932f409d..d796d880 100644 --- a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 +++ b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 @@ -94,6 +94,7 @@ } } else { $value = $value -replace "'", "''" + Write-Verbose "Escaped value: $value" $lines += "$indent $key = '$value'" } } From bcbf47595526d4af598258a914869443e8a952de Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:49:04 +0100 Subject: [PATCH 15/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Correctly=20escap?= =?UTF-8?q?e=20single=20quotes=20in=20hashtable=20string=20conversion=20to?= =?UTF-8?q?=20prevent=20formatting=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Build/public/Hashtable/Convert-HashtableToString.ps1 | 3 +-- .../public/PowerShell/Module/Export-PowerShellDataFile.ps1 | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 index d796d880..703aac28 100644 --- a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 +++ b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 @@ -93,8 +93,7 @@ $lines += "$indent )" } } else { - $value = $value -replace "'", "''" - Write-Verbose "Escaped value: $value" + $value = $value -replace "'", "''''" $lines += "$indent $key = '$value'" } } diff --git a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 index f903cb99..376ef790 100644 --- a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 +++ b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 @@ -27,4 +27,5 @@ $content = Convert-HashtableToString -Hashtable $Hashtable $content | Out-File -FilePath $Path -Force:$Force Format-ModuleManifest -Path $Path + } From 38a9fae1fd82e97f9eb990b6ce048ea5a5a7f750 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:51:27 +0100 Subject: [PATCH 16/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Correctly=20escap?= =?UTF-8?q?e=20single=20quotes=20in=20hashtable=20string=20conversion=20to?= =?UTF-8?q?=20prevent=20formatting=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Build/public/Hashtable/Convert-HashtableToString.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 index 703aac28..5da87ab6 100644 --- a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 +++ b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 @@ -93,7 +93,7 @@ $lines += "$indent )" } } else { - $value = $value -replace "'", "''''" + $value = $value -replace "'", "'''" $lines += "$indent $key = '$value'" } } From 30220be36e258020970933465be9949b66256edb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:53:25 +0100 Subject: [PATCH 17/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Correctly=20escap?= =?UTF-8?q?e=20single=20quotes=20in=20hashtable=20string=20conversion=20to?= =?UTF-8?q?=20prevent=20formatting=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Build/public/Hashtable/Convert-HashtableToString.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 index 5da87ab6..932f409d 100644 --- a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 +++ b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 @@ -93,7 +93,7 @@ $lines += "$indent )" } } else { - $value = $value -replace "'", "'''" + $value = $value -replace "'", "''" $lines += "$indent $key = '$value'" } } From 3baa5d70cab70f3a44147609699c94c5c295c985 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:55:57 +0100 Subject: [PATCH 18/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Comment=20out=20t?= =?UTF-8?q?he=20Format-ModuleManifest=20call=20in=20Export-PowerShellDataF?= =?UTF-8?q?ile.ps1=20to=20prevent=20unnecessary=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/PowerShell/Module/Export-PowerShellDataFile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 index 376ef790..7c1b105a 100644 --- a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 +++ b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 @@ -26,6 +26,6 @@ $content = Convert-HashtableToString -Hashtable $Hashtable $content | Out-File -FilePath $Path -Force:$Force - Format-ModuleManifest -Path $Path + # Format-ModuleManifest -Path $Path } From 249ae183a06a3bb5db0e12f5d69f1de0e2e5d89d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 21:59:21 +0100 Subject: [PATCH 19/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Re-enable=20Forma?= =?UTF-8?q?t-ModuleManifest=20call=20in=20Export-PowerShellDataFile.ps1=20?= =?UTF-8?q?and=20add=20verbose=20logging=20for=20manifest=20content=20in?= =?UTF-8?q?=20Format-ModuleManifest.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/PowerShell/Module/Export-PowerShellDataFile.ps1 | 3 +-- .../Build/public/PowerShell/Module/Format-ModuleManifest.ps1 | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 index 7c1b105a..f903cb99 100644 --- a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 +++ b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 @@ -26,6 +26,5 @@ $content = Convert-HashtableToString -Hashtable $Hashtable $content | Out-File -FilePath $Path -Force:$Force - # Format-ModuleManifest -Path $Path - + Format-ModuleManifest -Path $Path } diff --git a/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 index d5b1267a..da2d66e4 100644 --- a/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 +++ b/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 @@ -25,7 +25,7 @@ $manifestContent = $manifestContent | Where-Object { $_ | IsNotNullOrEmpty } [System.IO.File]::WriteAllLines($Path, $manifestContent, $Utf8BomEncoding) $manifestContent = Get-Content -Path $Path -Raw - + Write-Verbose $manifestContent $content = Invoke-Formatter -ScriptDefinition $manifestContent [System.IO.File]::WriteAllLines($Path, $content, $Utf8BomEncoding) From d93b4cb479df69d6b78e46db9caf89a751385bd3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 22:03:48 +0100 Subject: [PATCH 20/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Add=20verbose=20l?= =?UTF-8?q?ogging=20to=20Set-ModuleManifest=20in=20Update-PSModuleManifest?= =?UTF-8?q?AliasesToExport=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 58b9cfc7..d38506b4 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -32,6 +32,6 @@ function Update-PSModuleManifestAliasesToExport { $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Verbose "Output manifest path: [$outputManifestPath]" Write-Verbose "Setting module manifest with AliasesToExport" - Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $aliases.Name + Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $aliases.Name -Verbose } } From 33627f70e3fb9cd0aee5173ad8029e0ba8480203 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 22:06:55 +0100 Subject: [PATCH 21/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Add=20verbose=20l?= =?UTF-8?q?ogging=20for=20escaped=20values=20in=20Convert-HashtableToStrin?= =?UTF-8?q?g=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 index 932f409d..d796d880 100644 --- a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 +++ b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 @@ -94,6 +94,7 @@ } } else { $value = $value -replace "'", "''" + Write-Verbose "Escaped value: $value" $lines += "$indent $key = '$value'" } } From 0f940410a5914c4012c50a5b2e120e5ff1871b1c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 22:14:01 +0100 Subject: [PATCH 22/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20escapin?= =?UTF-8?q?g=20of=20single=20quotes=20in=20Convert-HashtableToString=20and?= =?UTF-8?q?=20add=20verbose=20logging=20for=20formatted=20manifest=20conte?= =?UTF-8?q?nt=20in=20Format-ModuleManifest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Build/public/Hashtable/Convert-HashtableToString.ps1 | 2 +- .../Build/public/PowerShell/Module/Format-ModuleManifest.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 index d796d880..9070447e 100644 --- a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 +++ b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 @@ -93,7 +93,7 @@ $lines += "$indent )" } } else { - $value = $value -replace "'", "''" + $value = $value -replace "('+)", "''" Write-Verbose "Escaped value: $value" $lines += "$indent $key = '$value'" } diff --git a/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 index da2d66e4..3143e80f 100644 --- a/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 +++ b/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 @@ -27,6 +27,6 @@ $manifestContent = Get-Content -Path $Path -Raw Write-Verbose $manifestContent $content = Invoke-Formatter -ScriptDefinition $manifestContent + Write-Verbose $content [System.IO.File]::WriteAllLines($Path, $content, $Utf8BomEncoding) - } From 8a7799d3d92591f0bd561ce2caec9c5be44b9135 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 22:26:45 +0100 Subject: [PATCH 23/25] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Update=20module?= =?UTF-8?q?=20requirements=20in=20Get-PSModuleTest.ps1=20to=20use=20'Store?= =?UTF-8?q?'=20instead=20of=20'Utilities'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 | 3 +-- .../functions/public/PSModule/Get-PSModuleTest.ps1 | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 b/tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 index 73a5c620..86beb12d 100644 --- a/tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 +++ b/tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 @@ -1,7 +1,6 @@ -#Requires -Modules Utilities +#Requires -Modules Store #Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.0.0' } #Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' } -#Requires -Modules @{ ModuleName = 'Store'; ModuleVersion = '0.3.1' } function Get-PSModuleTest { <# diff --git a/tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1 b/tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1 index 73a5c620..86beb12d 100644 --- a/tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1 +++ b/tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1 @@ -1,7 +1,6 @@ -#Requires -Modules Utilities +#Requires -Modules Store #Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.0.0' } #Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' } -#Requires -Modules @{ ModuleName = 'Store'; ModuleVersion = '0.3.1' } function Get-PSModuleTest { <# From c5bdb966e91fb6c646a42469ba6d189380f24b1a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 22:32:14 +0100 Subject: [PATCH 24/25] =?UTF-8?q?=F0=9F=A9=B9=20[Cleanup]:=20Remove=20obso?= =?UTF-8?q?lete=20PowerShell=20module=20functions=20to=20streamline=20the?= =?UTF-8?q?=20codebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hashtable/Convert-HashtableToString.ps1 | 104 ------ .../public/Hashtable/ConvertTo-HashTable.ps1 | 70 ---- .../public/Hashtable/Merge-Hashtable.ps1 | 56 --- .../Module/Add-ModuleManifestData.ps1 | 164 --------- .../PowerShell/Module/Add-PSModulePath.ps1 | 29 -- .../Module/Export-PowerShellDataFile.ps1 | 30 -- .../Module/Format-ModuleManifest.ps1 | 32 -- .../PowerShell/Module/Get-ModuleManifest.ps1 | 121 ------- .../PowerShell/Module/Invoke-PruneModule.ps1 | 58 ---- .../Module/Invoke-ReinstallModule.ps1 | 61 ---- .../PowerShell/Module/Set-ModuleManifest.ps1 | 325 ------------------ .../PowerShell/Module/Uninstall-Pester.ps1 | 54 --- 12 files changed, 1104 deletions(-) delete mode 100644 scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 delete mode 100644 scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 delete mode 100644 scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 delete mode 100644 scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 diff --git a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 b/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 deleted file mode 100644 index 9070447e..00000000 --- a/scripts/helpers/Build/public/Hashtable/Convert-HashtableToString.ps1 +++ /dev/null @@ -1,104 +0,0 @@ -function Convert-HashtableToString { - <# - .SYNOPSIS - Converts a hashtable to its code representation. - - .DESCRIPTION - Recursively converts a hashtable to its code representation. - This function is useful for exporting hashtables to .psd1 files. - - .EXAMPLE - $hashtable = @{ - Key1 = 'Value1' - Key2 = @{ - NestedKey1 = 'NestedValue1' - NestedKey2 = 'NestedValue2' - } - Key3 = @(1, 2, 3) - Key4 = $true - } - Convert-HashtableToString -Hashtable $hashtable - - This will return the following string: - @{ - Key1 = 'Value1' - Key2 = @{ - NestedKey1 = 'NestedValue1' - NestedKey2 = 'NestedValue2' - } - Key3 = @(1, 2, 3) - Key4 = $true - } - - .NOTES - General notes - #> - [CmdletBinding()] - param ( - # The hashtable to convert to a string. - [Parameter(Mandatory)] - [object]$Hashtable, - - # The indentation level. - [Parameter()] - [int]$IndentLevel = 0 - ) - - $lines = @() - $lines += '@{' - $indent = ' ' * $IndentLevel - - foreach ($key in $Hashtable.Keys) { - Write-Verbose "Processing key: $key" - $value = $Hashtable[$key] - Write-Verbose "Processing value: $value" - if ($null -eq $value) { - Write-Verbose "Value type: `$null" - continue - } - Write-Verbose "Value type: $($value.GetType().Name)" - if (($value -is [System.Collections.Hashtable]) -or ($value -is [System.Collections.Specialized.OrderedDictionary])) { - $nestedString = Convert-HashtableToString -Hashtable $value -IndentLevel ($IndentLevel + 1) - $lines += "$indent $key = $nestedString" - } elseif ($value -is [System.Management.Automation.PSCustomObject]) { - $nestedString = Convert-HashtableToString -Hashtable $value -IndentLevel ($IndentLevel + 1) - $lines += "$indent $key = $nestedString" - } elseif ($value -is [System.Management.Automation.PSObject]) { - $nestedString = Convert-HashtableToString -Hashtable $value -IndentLevel ($IndentLevel + 1) - $lines += "$indent $key = $nestedString" - } elseif ($value -is [bool]) { - $lines += "$indent $key = `$$($value.ToString().ToLower())" - } elseif ($value -is [int]) { - $lines += "$indent $key = $value" - } elseif ($value -is [array]) { - if ($value.Count -eq 0) { - $lines += "$indent $key = @()" - } else { - $lines += "$indent $key = @(" - $value | ForEach-Object { - $nestedValue = $_ - Write-Verbose "Processing array element: $_" - Write-Verbose "Element type: $($_.GetType().Name)" - if (($nestedValue -is [System.Collections.Hashtable]) -or ($nestedValue -is [System.Collections.Specialized.OrderedDictionary])) { - $nestedString = Convert-HashtableToString -Hashtable $nestedValue -IndentLevel ($IndentLevel + 1) - $lines += "$indent $nestedString" - } elseif ($nestedValue -is [bool]) { - $lines += "$indent `$$($nestedValue.ToString().ToLower())" - } elseif ($nestedValue -is [int]) { - $lines += "$indent $nestedValue" - } else { - $lines += "$indent '$nestedValue'" - } - } - $lines += "$indent )" - } - } else { - $value = $value -replace "('+)", "''" - Write-Verbose "Escaped value: $value" - $lines += "$indent $key = '$value'" - } - } - - $lines += "$indent}" - return $lines -join "`n" -} diff --git a/scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 b/scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 deleted file mode 100644 index b9a381f5..00000000 --- a/scripts/helpers/Build/public/Hashtable/ConvertTo-HashTable.ps1 +++ /dev/null @@ -1,70 +0,0 @@ -filter ConvertTo-Hashtable { - <# - .SYNOPSIS - Converts an object to a hashtable. - - .DESCRIPTION - Recursively converts an object to a hashtable. This function is useful for converting complex objects - to hashtables for serialization or other purposes. - - .EXAMPLE - $object = [PSCustomObject]@{ - Name = 'John Doe' - Age = 30 - Address = [PSCustomObject]@{ - Street = '123 Main St' - City = 'Somewhere' - ZipCode = '12345' - } - Occupations = @( - [PSCustomObject]@{ - Title = 'Developer' - Company = 'TechCorp' - }, - [PSCustomObject]@{ - Title = 'Consultant' - Company = 'ConsultCorp' - } - ) - } - $hashtable = ConvertTo-Hashtable -InputObject $object - - This will return a hashtable representation of the object. - #> - param ( - # The object to convert to a hashtable. - [Parameter( - Mandatory, - ValueFromPipeline - )] - [PSObject] $InputObject - ) - - $hashtable = @{} - - # Iterate over each property of the object - $InputObject.PSObject.Properties | ForEach-Object { - $propertyName = $_.Name - $propertyValue = $_.Value - - if ($propertyValue -is [PSObject]) { - if ($propertyValue -is [Array] -or $propertyValue -is [System.Collections.IEnumerable]) { - # Handle arrays and enumerables - $hashtable[$propertyName] = @() - foreach ($item in $propertyValue) { - $hashtable[$propertyName] += ConvertTo-HashTable -InputObject $item - } - } elseif ($propertyValue.PSObject.Properties.Count -gt 0) { - # Handle nested objects - $hashtable[$propertyName] = ConvertTo-Hashtable -InputObject $propertyValue - } else { - # Handle simple properties - $hashtable[$propertyName] = $propertyValue - } - } else { - $hashtable[$propertyName] = $propertyValue - } - } - - return $hashtable -} diff --git a/scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 b/scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 deleted file mode 100644 index 8f698f30..00000000 --- a/scripts/helpers/Build/public/Hashtable/Merge-Hashtable.ps1 +++ /dev/null @@ -1,56 +0,0 @@ -function Merge-Hashtable { - <# - .SYNOPSIS - Merge two hashtables, with the second hashtable overriding the first - - .DESCRIPTION - Merge two hashtables, with the second hashtable overriding the first - - .EXAMPLE - $Main = [ordered]@{ - Action = '' - Location = 'Main' - Name = 'Main' - Mode = 'Main' - } - $Override1 = [ordered]@{ - Action = '' - Location = '' - Name = 'Override1' - Mode = 'Override1' - } - $Override2 = [ordered]@{ - Action = '' - Location = '' - Name = 'Override1' - Mode = 'Override2' - } - Merge-Hashtables -Main $Main -Overrides $Override1, $Override2 - #> - [OutputType([Hashtable])] - [Alias('Merge-Hashtables')] - [CmdletBinding()] - param ( - # Main hashtable - [Parameter(Mandatory)] - [object] $Main, - - # Hashtable with overrides. - # Providing a list of overrides will apply them in order. - # Last write wins. - [Parameter(Mandatory)] - [object[]] $Overrides - ) - $Output = $Main.Clone() - foreach ($Override in $Overrides) { - foreach ($Key in $Override.Keys) { - if (($Output.Keys) -notcontains $Key) { - $Output.$Key = $Override.$Key - } - if ($Override.item($Key) | IsNotNullOrEmpty) { - $Output.$Key = $Override.$Key - } - } - } - return $Output -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 deleted file mode 100644 index 00ba9e14..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Add-ModuleManifestData.ps1 +++ /dev/null @@ -1,164 +0,0 @@ -function Add-ModuleManifestData { - <# - .SYNOPSIS - Add data to a module manifest file property - - .DESCRIPTION - This function adds data to a module manifest file property. - If the property doesn't exist, it will be created. - If it does exist, the new data will be appended to the existing data. - - .EXAMPLE - Add-ModuleManifestData -Path 'MyModule.psd1' -RequiredModules 'pester', 'platyPS' - - Adds the modules 'pester' and 'platyPS' to the RequiredModules property of the module manifest file 'MyModule.psd1'. - #> - [CmdletBinding()] - param( - [Parameter(Mandatory)] - [ValidateScript({ Test-Path -Path $_ -PathType Leaf })] - [string]$Path, - - # Modules that must be imported into the global environment prior to importing this module. - [Parameter()] - [Object[]] $RequiredModules, - - # Compatible editions of PowerShell. - [Parameter()] - [string[]] $CompatiblePSEditions, - - # Assemblies that must be loaded prior to importing this module. - [Parameter()] - [string[]] $RequiredAssemblies, - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - [Parameter()] - [string[]] $ScriptsToProcess, - - # Type files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [string[]] $TypesToProcess, - - # Format files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [string[]] $FormatsToProcess, - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. - [Parameter()] - [Object[]] $NestedModules, - - # Functions to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no functions to export. - [Parameter()] - [string[]] $FunctionsToExport, - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no cmdlets to export. - [Parameter()] - [string[]] $CmdletsToExport, - - # Variables to export from this module. - [Parameter()] - [string[]] $VariablesToExport, - - # Aliases to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no aliases to export. - [Parameter()] - [string[]] $AliasesToExport, - - # DSC resources to export from this module. - [Parameter()] - [string[]] $DscResourcesToExport, - - # List of all modules packaged with this module. - [Parameter()] - [Object[]] $ModuleList, - - # List of all files packaged with this module. - [Parameter()] - [string[]] $FileList, - - # Tags applied to this module. These help with module discovery in online galleries. - [Parameter()] - [string[]] $Tags, - - # External dependent modules of this module. - [Parameter()] - [string[]] $ExternalModuleDependencies - ) - - $moduleManifest = Get-ModuleManifest -Path $Path - $changes = @{} - - if ($RequiredModules) { - $RequiredModules += $moduleManifest.RequiredModules - $changes.RequiredModules = $RequiredModules - } - if ($RequiredAssemblies) { - $RequiredAssemblies += $moduleManifest.RequiredAssemblies - $changes.RequiredAssemblies = $RequiredAssemblies - } - if ($CompatiblePSEditions) { - $CompatiblePSEditions += $moduleManifest.CompatiblePSEditions - $changes.CompatiblePSEditions = $CompatiblePSEditions - } - if ($ScriptsToProcess) { - $ScriptsToProcess += $moduleManifest.ScriptsToProcess - $changes.ScriptsToProcess = $ScriptsToProcess - } - if ($TypesToProcess) { - $TypesToProcess += $moduleManifest.TypesToProcess - $changes.TypesToProcess = $TypesToProcess - } - if ($FormatsToProcess) { - $FormatsToProcess += $moduleManifest.FormatsToProcess - $changes.FormatsToProcess = $FormatsToProcess - } - if ($NestedModules) { - $NestedModules += $moduleManifest.NestedModules - $changes.NestedModules = $NestedModules - } - if ($FunctionsToExport) { - $FunctionsToExport += $moduleManifest.FunctionsToExport - $changes.FunctionsToExport = $FunctionsToExport - } - if ($CmdletsToExport) { - $CmdletsToExport += $moduleManifest.CmdletsToExport - $changes.CmdletsToExport = $CmdletsToExport - } - if ($VariablesToExport) { - $VariablesToExport += $moduleManifest.VariablesToExport - $changes.VariablesToExport = $VariablesToExport - } - if ($AliasesToExport) { - $AliasesToExport += $moduleManifest.AliasesToExport - $changes.AliasesToExport = $AliasesToExport - } - if ($DscResourcesToExport) { - $DscResourcesToExport += $moduleManifest.DscResourcesToExport - $changes.DscResourcesToExport = $DscResourcesToExport - } - if ($ModuleList) { - $ModuleList += $moduleManifest.ModuleList - $changes.ModuleList = $ModuleList - } - if ($FileList) { - $FileList += $moduleManifest.FileList - $changes.FileList = $FileList - } - if ($Tags) { - $Tags += $moduleManifest.PrivateData.PSData.Tags - $changes.Tags = $Tags - } - if ($ExternalModuleDependencies) { - $ExternalModuleDependencies += $moduleManifest.PrivateData.PSData.ExternalModuleDependencies - $changes.ExternalModuleDependencies = $ExternalModuleDependencies - } - - foreach ($key in $changes.GetEnumerator().Name) { - $changes[$key] = $changes[$key] | Sort-Object -Unique | Where-Object { $_ | IsNotNullOrEmpty } - } - - Set-ModuleManifest -Path $Path @changes - -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 deleted file mode 100644 index f5abf042..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Add-PSModulePath.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Add-PSModulePath { - <# - .SYNOPSIS - Adds a path to the PSModulePath environment variable. - - .DESCRIPTION - Adds a path to the PSModulePath environment variable. - For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. - - .EXAMPLE - Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' - - Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. - #> - [CmdletBinding()] - param( - # Path to the folder where the module source code is located. - [Parameter(Mandatory)] - [string] $Path - ) - $PSModulePathSeparator = [System.IO.Path]::PathSeparator - - $env:PSModulePath += "$PSModulePathSeparator$Path" - - Write-Verbose 'PSModulePath:' - $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { - Write-Verbose " - [$_]" - } -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 deleted file mode 100644 index f903cb99..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Export-PowerShellDataFile.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Export-PowerShellDataFile { - <# - .SYNOPSIS - Export a hashtable to a .psd1 file. - - .DESCRIPTION - This function exports a hashtable to a .psd1 file. It also formats the .psd1 file using the Format-ModuleManifest cmdlet. - - .EXAMPLE - Export-PowerShellDataFile -Hashtable @{ Name = 'MyModule'; ModuleVersion = '1.0.0' } -Path 'MyModule.psd1' - #> - [CmdletBinding()] - param ( - # The hashtable to export to a .psd1 file. - [Parameter(Mandatory)] - [object] $Hashtable, - - # The path of the .psd1 file to export. - [Parameter(Mandatory)] - [string] $Path, - - # Force the export, even if the file already exists. - [Parameter()] - [switch] $Force - ) - - $content = Convert-HashtableToString -Hashtable $Hashtable - $content | Out-File -FilePath $Path -Force:$Force - Format-ModuleManifest -Path $Path -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 deleted file mode 100644 index 3143e80f..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Format-ModuleManifest.ps1 +++ /dev/null @@ -1,32 +0,0 @@ -function Format-ModuleManifest { - <# - .SYNOPSIS - Formats a module manifest file. - - .DESCRIPTION - This function formats a module manifest file, by removing comments and empty lines, - and then formatting the file using the `Invoke-Formatter` function. - - .EXAMPLE - Format-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' - #> - [CmdletBinding()] - param( - # Path to the module manifest file. - [Parameter(Mandatory)] - [string] $Path - ) - - $Utf8BomEncoding = New-Object System.Text.UTF8Encoding $true - - $manifestContent = Get-Content -Path $Path - $manifestContent = $manifestContent | ForEach-Object { $_ -replace '#.*' } - $manifestContent = $manifestContent | ForEach-Object { $_.TrimEnd() } - $manifestContent = $manifestContent | Where-Object { $_ | IsNotNullOrEmpty } - [System.IO.File]::WriteAllLines($Path, $manifestContent, $Utf8BomEncoding) - $manifestContent = Get-Content -Path $Path -Raw - Write-Verbose $manifestContent - $content = Invoke-Formatter -ScriptDefinition $manifestContent - Write-Verbose $content - [System.IO.File]::WriteAllLines($Path, $content, $Utf8BomEncoding) -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 deleted file mode 100644 index a3afd35b..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Get-ModuleManifest.ps1 +++ /dev/null @@ -1,121 +0,0 @@ -function Get-ModuleManifest { - <# - .SYNOPSIS - Get the module manifest. - - .DESCRIPTION - Get the module manifest as a path, file info, content, or hashtable. - - .EXAMPLE - Get-PSModuleManifest -Path 'src/PSModule/PSModule.psd1' -As Hashtable - #> - [OutputType([string], [System.IO.FileInfo], [System.Collections.Hashtable], [System.Collections.Specialized.OrderedDictionary])] - [CmdletBinding()] - param( - # Path to the module manifest file. - [Parameter(Mandatory)] - [string] $Path, - - # The format of the output. - [Parameter()] - [ValidateSet('FileInfo', 'Content', 'Hashtable')] - [string] $As = 'Hashtable' - ) - - if (-not (Test-Path -Path $Path)) { - Write-Warning 'No manifest file found.' - return $null - } - Write-Verbose "Found manifest file [$Path]" - - switch ($As) { - 'FileInfo' { - return Get-Item -Path $Path - } - 'Content' { - return Get-Content -Path $Path - } - 'Hashtable' { - $manifest = [System.Collections.Specialized.OrderedDictionary]@{} - $psData = [System.Collections.Specialized.OrderedDictionary]@{} - $privateData = [System.Collections.Specialized.OrderedDictionary]@{} - $tempManifest = Import-PowerShellDataFile -Path $Path - if ($tempManifest.ContainsKey('PrivateData')) { - $tempPrivateData = $tempManifest.PrivateData - if ($tempPrivateData.ContainsKey('PSData')) { - $tempPSData = $tempPrivateData.PSData - $tempPrivateData.Remove('PSData') - } - } - - $psdataOrder = @( - 'Tags' - 'LicenseUri' - 'ProjectUri' - 'IconUri' - 'ReleaseNotes' - 'Prerelease' - 'RequireLicenseAcceptance' - 'ExternalModuleDependencies' - ) - foreach ($key in $psdataOrder) { - if (($null -ne $tempPSData) -and ($tempPSData.ContainsKey($key))) { - $psData.$key = $tempPSData.$key - } - } - if ($psData.Count -gt 0) { - $privateData.PSData = $psData - } else { - $privateData.Remove('PSData') - } - foreach ($key in $tempPrivateData.Keys) { - $privateData.$key = $tempPrivateData.$key - } - - $manifestOrder = @( - 'RootModule' - 'ModuleVersion' - 'CompatiblePSEditions' - 'GUID' - 'Author' - 'CompanyName' - 'Copyright' - 'Description' - 'PowerShellVersion' - 'PowerShellHostName' - 'PowerShellHostVersion' - 'DotNetFrameworkVersion' - 'ClrVersion' - 'ProcessorArchitecture' - 'RequiredModules' - 'RequiredAssemblies' - 'ScriptsToProcess' - 'TypesToProcess' - 'FormatsToProcess' - 'NestedModules' - 'FunctionsToExport' - 'CmdletsToExport' - 'VariablesToExport' - 'AliasesToExport' - 'DscResourcesToExport' - 'ModuleList' - 'FileList' - 'HelpInfoURI' - 'DefaultCommandPrefix' - 'PrivateData' - ) - foreach ($key in $manifestOrder) { - if ($tempManifest.ContainsKey($key)) { - $manifest.$key = $tempManifest.$key - } - } - if ($privateData.Count -gt 0) { - $manifest.PrivateData = $privateData - } else { - $manifest.Remove('PrivateData') - } - - return $manifest - } - } -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 deleted file mode 100644 index 1b21131a..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Invoke-PruneModule.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -function Invoke-PruneModule { - <# - .SYNOPSIS - Remove all but the newest version of a module - - .DESCRIPTION - Remove all but the newest version of a module - - .EXAMPLE - Invoke-PruneModule -Name 'Az.*' -Scope CurrentUser - #> - [OutputType([void])] - [CmdletBinding()] - [Alias('Prune-Module')] - param ( - # Name of the module(s) to prune - [Parameter()] - [string[]] $Name = '*', - - # Scope of the module(s) to prune - [Parameter()] - [ValidateSet('CurrentUser', 'AllUsers')] - [string[]] $Scope = 'CurrentUser' - ) - - if ($Scope -eq 'AllUsers' -and -not (IsAdmin)) { - $message = 'Administrator rights are required to uninstall modules for all users. Please run the command again with' + - " elevated rights (Run as Administrator) or provide '-Scope CurrentUser' to your command." - - throw $message - } - - $UpdateableModules = Get-InstalledModule | Where-Object Name -Like "$Name" - $UpdateableModuleNames = $UpdateableModules.Name | Sort-Object -Unique - foreach ($UpdateableModuleName in $UpdateableModuleNames) { - $UpdateableModule = $UpdateableModules | Where-Object Name -EQ $UpdateableModuleName | Sort-Object -Property Version -Descending - Write-Verbose "[$($UpdateableModuleName)] - Found [$($UpdateableModule.Count)]" - - $NewestModule = $UpdateableModule | Select-Object -First 1 - Write-Verbose "[$($UpdateableModuleName)] - Newest [$($NewestModule.Version -join ', ')]" - - $OutdatedModules = $UpdateableModule | Select-Object -Skip 1 - Write-Verbose "[$($UpdateableModuleName)] - Outdated [$($OutdatedModules.Version -join ', ')]" - - foreach ($OutdatedModule in $OutdatedModules) { - Write-Verbose "[$($UpdateableModuleName)] - [$($OutdatedModule.Version)] - Removing" - $OutdatedModule | Remove-Module -Force - Write-Verbose "[$($UpdateableModuleName)] - [$($OutdatedModule.Version)] - Uninstalling" - Uninstall-Module -Name $OutdatedModule.Name -RequiredVersion -Force - try { - $OutdatedModule.ModuleBase | Remove-Item -Force -Recurse -ErrorAction Stop - } catch { - Write-Warning "[$($UpdateableModuleName)] - [$($OutdatedModule.Version)] - Failed to remove [$($OutdatedModule.ModuleBase)]" - continue - } - } - } -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 deleted file mode 100644 index 448deb1e..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Invoke-ReinstallModule.ps1 +++ /dev/null @@ -1,61 +0,0 @@ -function Invoke-ReinstallModule { - <# - .SYNOPSIS - Reinstalls module into a given scope. - - .DESCRIPTION - Reinstalls module into a given scope. This is useful when you want to reinstall or clean up your module versions. - With this command you always get the newest available version of the module and all the previous version wiped out. - - .PARAMETER Name - The name of the module to be reinstalled. Wildcards are supported. - - .PARAMETER Scope - The scope of the module to will be reinstalled to. - - .EXAMPLE - Reinstall-Module -Name Pester -Scope CurrentUser - - Reinstall Pester module for the current user. - - .EXAMPLE - Reinstall-Module -Scope CurrentUser - - Reinstall all reinstallable modules into the current user. - #> - [CmdletBinding()] - [Alias('Reinstall-Module')] - param ( - # Name of the module(s) to reinstall - [Parameter()] - [SupportsWildcards()] - [string[]] $Name = '*', - - # Scope of the module(s) to reinstall - [Parameter()] - [ValidateSet('CurrentUser', 'AllUsers')] - [string[]] $Scope = 'CurrentUser' - ) - - if ($Scope -eq 'AllUsers' -and -not (IsAdmin)) { - $message = 'Administrator rights are required to uninstall modules for all users. Please run the command again with' + - " elevated rights (Run as Administrator) or provide '-Scope CurrentUser' to your command." - - throw $message - } - - $modules = Get-InstalledModule | Where-Object Name -Like "$Name" - Write-Verbose "Found [$($modules.Count)] modules" - - $modules | ForEach-Object { - if ($_.name -eq 'Pester') { - Uninstall-Pester -All - continue - } - Uninstall-Module -Name $_ -AllVersions -Force -ErrorAction SilentlyContinue - } - - $modules.Name | ForEach-Object { - Install-Module -Name $_ -Scope $Scope -Force - } -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 deleted file mode 100644 index 558857af..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Set-ModuleManifest.ps1 +++ /dev/null @@ -1,325 +0,0 @@ -filter Set-ModuleManifest { - <# - .SYNOPSIS - Sets the values of a module manifest file. - - .DESCRIPTION - This function sets the values of a module manifest file. - Very much like the Update-ModuleManifest function, but allows values to be missing. - - .EXAMPLE - Set-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' -ModuleVersion '1.0.0' - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseShouldProcessForStateChangingFunctions', '', - Justification = 'Function does not change state.' - )] - [CmdletBinding()] - param( - # Path to the module manifest file. - [Parameter( - Mandatory, - ValueFromPipeline, - ValueFromPipelineByPropertyName - )] - [string] $Path, - - #Script module or binary module file associated with this manifest. - [Parameter()] - [AllowNull()] - [string] $RootModule, - - #Version number of this module. - [Parameter()] - [AllowNull()] - [Version] $ModuleVersion, - - # Supported PSEditions. - [Parameter()] - [AllowNull()] - [string[]] $CompatiblePSEditions, - - # ID used to uniquely identify this module. - [Parameter()] - [AllowNull()] - [guid] $GUID, - - # Author of this module. - [Parameter()] - [AllowNull()] - [string] $Author, - - # Company or vendor of this module. - [Parameter()] - [AllowNull()] - [string] $CompanyName, - - # Copyright statement for this module. - [Parameter()] - [AllowNull()] - [string] $Copyright, - - # Description of the functionality provided by this module. - [Parameter()] - [AllowNull()] - [string] $Description, - - # Minimum version of the PowerShell engine required by this module. - [Parameter()] - [AllowNull()] - [Version] $PowerShellVersion, - - # Name of the PowerShell host required by this module. - [Parameter()] - [AllowNull()] - [string] $PowerShellHostName, - - # Minimum version of the PowerShell host required by this module. - [Parameter()] - [AllowNull()] - [version] $PowerShellHostVersion, - - # Minimum version of Microsoft .NET Framework required by this module. - # This prerequisite is valid for the PowerShell Desktop edition only. - [Parameter()] - [AllowNull()] - [Version] $DotNetFrameworkVersion, - - # Minimum version of the common language runtime (CLR) required by this module. - # This prerequisite is valid for the PowerShell Desktop edition only. - [Parameter()] - [AllowNull()] - [Version] $ClrVersion, - - # Processor architecture (None,X86, Amd64) required by this module - [Parameter()] - [AllowNull()] - [System.Reflection.ProcessorArchitecture] $ProcessorArchitecture, - - # Modules that must be imported into the global environment prior to importing this module. - [Parameter()] - [AllowNull()] - [Object[]] $RequiredModules, - - # Assemblies that must be loaded prior to importing this module. - [Parameter()] - [AllowNull()] - [string[]] $RequiredAssemblies, - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - [Parameter()] - [AllowNull()] - [string[]] $ScriptsToProcess, - - # Type files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [AllowNull()] - [string[]] $TypesToProcess, - - # Format files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [AllowNull()] - [string[]] $FormatsToProcess, - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. - [Parameter()] - [AllowNull()] - [Object[]] $NestedModules, - - # Functions to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no functions to export. - [Parameter()] - [AllowNull()] - [string[]] $FunctionsToExport, - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no cmdlets to export. - [Parameter()] - [AllowNull()] - [string[]] $CmdletsToExport, - - # Variables to export from this module. - [Parameter()] - [AllowNull()] - [string[]] $VariablesToExport, - - # Aliases to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no aliases to export. - [Parameter()] - [AllowNull()] - [string[]] $AliasesToExport, - - # DSC resources to export from this module. - [Parameter()] - [AllowNull()] - [string[]] $DscResourcesToExport, - - # List of all modules packaged with this module. - [Parameter()] - [AllowNull()] - [Object[]] $ModuleList, - - # List of all files packaged with this module. - [Parameter()] - [AllowNull()] - [string[]] $FileList, - - # Tags applied to this module. These help with module discovery in online galleries. - [Parameter()] - [AllowNull()] - [string[]] $Tags, - - # A URL to the license for this module. - [Parameter()] - [AllowNull()] - [uri] $LicenseUri, - - # A URL to the main site for this project. - [Parameter()] - [AllowNull()] - [uri] $ProjectUri, - - # A URL to an icon representing this module. - [Parameter()] - [AllowNull()] - [uri] $IconUri, - - # ReleaseNotes of this module. - [Parameter()] - [AllowNull()] - [string] $ReleaseNotes, - - # Prerelease string of this module. - [Parameter()] - [AllowNull()] - [string] $Prerelease, - - # Flag to indicate whether the module requires explicit user acceptance for install/update/save. - [Parameter()] - [AllowNull()] - [bool] $RequireLicenseAcceptance, - - # External dependent modules of this module. - [Parameter()] - [AllowNull()] - [string[]] $ExternalModuleDependencies, - - # HelpInfo URI of this module. - [Parameter()] - [AllowNull()] - [String] $HelpInfoURI, - - # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. - [Parameter()] - [AllowNull()] - [string] $DefaultCommandPrefix, - - # Private data to pass to the module specified in RootModule/ModuleToProcess. - # This may also contain a PSData hashtable with additional module metadata used by PowerShell. - [Parameter()] - [AllowNull()] - [object] $PrivateData - ) - - $outManifest = [ordered]@{} - $outPSData = [ordered]@{} - $outPrivateData = [ordered]@{} - - $tempManifest = Get-ModuleManifest -Path $Path - if ($tempManifest.Keys.Contains('PrivateData')) { - $tempPrivateData = $tempManifest.PrivateData - if ($tempPrivateData.Keys.Contains('PSData')) { - $tempPSData = $tempPrivateData.PSData - $tempPrivateData.Remove('PSData') - } - } - - $psdataOrder = @( - 'Tags' - 'LicenseUri' - 'ProjectUri' - 'IconUri' - 'ReleaseNotes' - 'Prerelease' - 'RequireLicenseAcceptance' - 'ExternalModuleDependencies' - ) - foreach ($key in $psdataOrder) { - if (($null -ne $tempPSData) -and $tempPSData.Keys.Contains($key)) { - $outPSData[$key] = $tempPSData[$key] - } - if ($PSBoundParameters.Keys.Contains($key)) { - if ($null -eq $PSBoundParameters[$key]) { - $outPSData.Remove($key) - } else { - $outPSData[$key] = $PSBoundParameters[$key] - } - } - } - - if ($outPSData.Count -gt 0) { - $outPrivateData.PSData = $outPSData - } else { - $outPrivateData.Remove('PSData') - } - foreach ($key in $tempPrivateData.Keys) { - $outPrivateData[$key] = $tempPrivateData[$key] - } - foreach ($key in $PrivateData.Keys) { - $outPrivateData[$key] = $PrivateData[$key] - } - - $manifestOrder = @( - 'RootModule' - 'ModuleVersion' - 'CompatiblePSEditions' - 'GUID' - 'Author' - 'CompanyName' - 'Copyright' - 'Description' - 'PowerShellVersion' - 'PowerShellHostName' - 'PowerShellHostVersion' - 'DotNetFrameworkVersion' - 'ClrVersion' - 'ProcessorArchitecture' - 'RequiredModules' - 'RequiredAssemblies' - 'ScriptsToProcess' - 'TypesToProcess' - 'FormatsToProcess' - 'NestedModules' - 'FunctionsToExport' - 'CmdletsToExport' - 'VariablesToExport' - 'AliasesToExport' - 'DscResourcesToExport' - 'ModuleList' - 'FileList' - 'HelpInfoURI' - 'DefaultCommandPrefix' - 'PrivateData' - ) - foreach ($key in $manifestOrder) { - if ($tempManifest.Keys.Contains($key)) { - $outManifest[$key] = $tempManifest[$key] - } - if ($PSBoundParameters.Keys.Contains($key)) { - if ($null -eq $PSBoundParameters[$key]) { - $outManifest.Remove($key) - } else { - $outManifest[$key] = $PSBoundParameters[$key] - } - } - } - if ($outPrivateData.Count -gt 0) { - $outManifest['PrivateData'] = $outPrivateData - } else { - $outManifest.Remove('PrivateData') - } - - Remove-Item -Path $Path -Force - Export-PowerShellDataFile -Hashtable $outManifest -Path $Path - -} diff --git a/scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 b/scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 deleted file mode 100644 index 2b69a265..00000000 --- a/scripts/helpers/Build/public/PowerShell/Module/Uninstall-Pester.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -function Uninstall-Pester { - <# - .SYNOPSIS - Uninstall Pester 3 from Program Files and Program Files (x86) - - .DESCRIPTION - Uninstall Pester 3 from Program Files and Program Files (x86). This is useful - when you want to install Pester 4 and you have Pester 3 installed. - - .PARAMETER All - - .EXAMPLE - Uninstall-Pester - - Uninstall Pester 3 from Program Files and Program Files (x86). - - .EXAMPLE - Uninstall-Pester -All - - Completely remove all built-in Pester 3 installations. - #> - [OutputType([String])] - [CmdletBinding()] - param ( - # Completely remove all built-in Pester 3 installations - [Parameter()] - [switch] $All - ) - - $pesterPaths = foreach ($programFiles in ($env:ProgramFiles, ${env:ProgramFiles(x86)})) { - $path = "$programFiles\WindowsPowerShell\Modules\Pester" - if ($null -ne $programFiles -and (Test-Path $path)) { - if ($All) { - Get-Item $path - } else { - Get-ChildItem "$path\3.*" - } - } - } - - if (-not $pesterPaths) { - "There are no Pester$(if (-not $all) {' 3'}) installations in Program Files and Program Files (x86) doing nothing." - return - } - - foreach ($pesterPath in $pesterPaths) { - takeown /F $pesterPath /A /R - icacls $pesterPath /reset - # grant permissions to Administrators group, but use SID to do - # it because it is localized on non-us installations of Windows - icacls $pesterPath /grant '*S-1-5-32-544:F' /inheritance:d /T - Remove-Item -Path $pesterPath -Recurse -Force -Confirm:$false - } -} From 53bce57b8b1742caa43c0bdc1a9382937992c6c7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 28 Jan 2025 22:58:25 +0100 Subject: [PATCH 25/25] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Replace=20Wr?= =?UTF-8?q?ite-Verbose=20with=20Write-Host=20for=20improved=20output=20vis?= =?UTF-8?q?ibility=20in=20module=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Build/Build-PSModuleDocumentation.ps1 | 12 ++--- .../Build/Build-PSModuleRootModule.ps1 | 4 +- .../ConvertTo-EscapedHashtableString.ps1 | 47 ------------------- .../Build/Get-PSModuleAliasesToExport.ps1 | 4 +- .../Build/Get-PSModuleCmdletsToExport.ps1 | 4 +- .../Build/Get-PSModuleFunctionsToExport.ps1 | 12 ++--- .../Build/Get-PSModuleVariablesToExport.ps1 | 6 +-- scripts/helpers/Build/Import-PSModule.ps1 | 8 ++-- .../helpers/Build/Invoke-RecurseEscapeFix.ps1 | 34 -------------- .../Build/Resolve-PSModuleDependency.ps1 | 14 +++--- ...Update-PSModuleManifestAliasesToExport.ps1 | 14 +++--- 11 files changed, 39 insertions(+), 120 deletions(-) delete mode 100644 scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 delete mode 100644 scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 diff --git a/scripts/helpers/Build/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build/Build-PSModuleDocumentation.ps1 index 423c406d..5ae946a1 100644 --- a/scripts/helpers/Build/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build/Build-PSModuleDocumentation.ps1 @@ -34,7 +34,7 @@ function Build-PSModuleDocumentation { LogGroup 'Build docs - Generate markdown help' { $ModuleName | Remove-Module -Force Import-Module -Name $ModuleName -Force -RequiredVersion '999.0.0' - Write-Verbose ($ModuleName | Get-Module) + Write-Host ($ModuleName | Get-Module) $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose } @@ -75,13 +75,13 @@ function Build-PSModuleDocumentation { $PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { $file = $_ - Write-Verbose "Processing: $file" + Write-Host "Processing: $file" # find the source code file that matches the markdown file $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } - Write-Verbose "Found script path: $scriptPath" + Write-Host "Found script path: $scriptPath" $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') - Write-Verbose "Doc file path: $docsFilePath" + Write-Host "Doc file path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force @@ -89,9 +89,9 @@ function Build-PSModuleDocumentation { # Get the MD files that are in the public functions folder and move them to the same place in the docs folder Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { $file = $_ - Write-Verbose "Processing: $file" + Write-Host "Processing: $file" $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) - Write-Verbose "Doc file path: $docsFilePath" + Write-Host "Doc file path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force diff --git a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 index 623fb37f..28013b5b 100644 --- a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 +++ b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 @@ -129,7 +129,7 @@ $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { $exports.Add('Function', (Get-PSModuleFunctionsToExport -SourceFolderPath $ModuleOutputFolder)) $exports.Add('Variable', (Get-PSModuleVariablesToExport -SourceFolderPath $ModuleOutputFolder)) - Write-Verbose ($exports | Out-String) + Write-Host ($exports | Out-String) #endregion - Analyze source files #region - Module header @@ -223,7 +223,7 @@ Write-Debug "[`$scriptName] - $relativePath - Done" $exportsString = Convert-HashtableToString -Hashtable $exports - Write-Verbose ($exportsString | Out-String) + Write-Host ($exportsString | Out-String) $params = @{ Path = $rootModuleFile diff --git a/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 b/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 deleted file mode 100644 index 14c605da..00000000 --- a/scripts/helpers/Build/ConvertTo-EscapedHashtableString.ps1 +++ /dev/null @@ -1,47 +0,0 @@ - -filter ConvertTo-EscapedHashtableString { - <# - .SYNOPSIS - Converts a hashtable to a string with escaped single quotes. - - .DESCRIPTION - Converts a hashtable to a string with escaped single quotes. - - .EXAMPLE - $myHashtable = @{ - Name = "O'Brien" - Nested = @{ - Description = "It's a 'nested' value" - Array = @("String with 'quotes'", 123, @{'Another' = "Nested 'string'" }) - } - } - Escape-HashtableStrings -Hashtable $myHashtable - $myHashtable | Format-List -Force - - Name : Nested - Value : {[Description, It''s a ''nested'' value], [Array, System.Object[]]} - - Name : Name - Value : O''Brien - #> - param ( - # The hashtable to convert to a string with escaped single quotes. - [Parameter( - Mandatory, - ValueFromPipeline - )] - [hashtable] $Hashtable - ) - - # Loop through the hashtable and process each value - $keys = @($Hashtable.Keys) # Make a copy of the keys - Write-Verbose "Processing hashtable keys: $keys" - foreach ($key in $keys) { - Write-Verbose "Processing key: $key" - Write-Verbose "Value: [$($Hashtable[$key])]" - $Hashtable[$key] = Invoke-RecurseEscapeFix -Value $Hashtable[$key] - Write-Verbose "Escaped value: [$($Hashtable[$key])]" - } - - return $Hashtable -} diff --git a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 index 0d3a1545..6c016d7f 100644 --- a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 @@ -24,10 +24,10 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false - Write-Verbose "[$manifestPropertyName]" + Write-Host "[$manifestPropertyName]" $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or ($manifest.AliasesToExport | IsNullOrEmpty) ? '*' : $manifest.AliasesToExport $aliasesToExport | ForEach-Object { - Write-Verbose "[$manifestPropertyName] - [$_]" + Write-Host "[$manifestPropertyName] - [$_]" } $aliasesToExport diff --git a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 index aa0b1e9f..a51623f2 100644 --- a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 @@ -24,10 +24,10 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false - Write-Verbose "[$manifestPropertyName]" + Write-Host "[$manifestPropertyName]" $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or ($manifest.CmdletsToExport | IsNullOrEmpty) ? '' : $manifest.CmdletsToExport $cmdletsToExport | ForEach-Object { - Write-Verbose "[$manifestPropertyName] - [$_]" + Write-Host "[$manifestPropertyName] - [$_]" } $cmdletsToExport diff --git a/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 index 89c5d12f..99f34967 100644 --- a/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 @@ -19,22 +19,22 @@ $manifestPropertyName = 'FunctionsToExport' - Write-Verbose "[$manifestPropertyName]" - Write-Verbose "[$manifestPropertyName] - Checking path for functions and filters" + Write-Host "[$manifestPropertyName]" + Write-Host "[$manifestPropertyName] - Checking path for functions and filters" $publicFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'functions/public' if (-not (Test-Path -Path $publicFolderPath -PathType Container)) { - Write-Verbose "[$manifestPropertyName] - [Folder not found] - [$publicFolderPath]" + Write-Host "[$manifestPropertyName] - [Folder not found] - [$publicFolderPath]" return $functionsToExport } - Write-Verbose "[$manifestPropertyName] - [$publicFolderPath]" + Write-Host "[$manifestPropertyName] - [$publicFolderPath]" $functionsToExport = [Collections.Generic.List[string]]::new() $scriptFiles = Get-ChildItem -Path $publicFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.ps1' - Write-Verbose "[$manifestPropertyName] - [$($scriptFiles.Count)]" + Write-Host "[$manifestPropertyName] - [$($scriptFiles.Count)]" foreach ($file in $scriptFiles) { $fileContent = Get-Content -Path $file.FullName -Raw $containsFunction = ($fileContent -match 'function ') -or ($fileContent -match 'filter ') - Write-Verbose "[$manifestPropertyName] - [$($file.BaseName)] - [$containsFunction]" + Write-Host "[$manifestPropertyName] - [$($file.BaseName)] - [$containsFunction]" if ($containsFunction) { $functionsToExport.Add($file.BaseName) } diff --git a/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 index b8cd5234..004d6325 100644 --- a/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 @@ -19,11 +19,11 @@ $manifestPropertyName = 'VariablesToExport' - Write-Verbose "[$manifestPropertyName]" + Write-Host "[$manifestPropertyName]" $variableFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'variables/public' if (-not (Test-Path -Path $variableFolderPath -PathType Container)) { - Write-Verbose "[$manifestPropertyName] - [Folder not found] - [$variableFolderPath]" + Write-Host "[$manifestPropertyName] - [Folder not found] - [$variableFolderPath]" return $variablesToExport } $scriptFilePaths = Get-ChildItem -Path $variableFolderPath -Recurse -File -Filter *.ps1 | Select-Object -ExpandProperty FullName @@ -38,7 +38,7 @@ } $variablesToExport | ForEach-Object { - Write-Verbose "[$manifestPropertyName] - [$_]" + Write-Host "[$manifestPropertyName] - [$_]" } $variablesToExport diff --git a/scripts/helpers/Build/Import-PSModule.ps1 b/scripts/helpers/Build/Import-PSModule.ps1 index efdae829..dbcac47c 100644 --- a/scripts/helpers/Build/Import-PSModule.ps1 +++ b/scripts/helpers/Build/Import-PSModule.ps1 @@ -27,7 +27,7 @@ $manifestFilePath = Join-Path -Path $Path $manifestFileName $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose - Write-Verbose "Manifest file path: [$($manifestFile.FullName)]" -Verbose + Write-Host "Manifest file path: [$($manifestFile.FullName)]" -Verbose $existingModule = Get-Module -Name $ModuleName -ListAvailable $existingModule | Remove-Module -Force -Verbose $existingModule.RequiredModules | ForEach-Object { $_ | Remove-Module -Force -Verbose -ErrorAction SilentlyContinue } @@ -36,11 +36,11 @@ Resolve-PSModuleDependencies -ManifestFilePath $manifestFile Import-Module -Name $ModuleName -RequiredVersion '999.0.0' - Write-Verbose 'List loaded modules' + Write-Host 'List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize - Write-Verbose 'List commands' - Write-Verbose (Get-Command -Module $moduleName | Format-Table -AutoSize | Out-String) + Write-Host 'List commands' + Write-Host (Get-Command -Module $moduleName | Format-Table -AutoSize | Out-String) if ($ModuleName -notin $availableModules.Name) { throw 'Module not found' diff --git a/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 b/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 deleted file mode 100644 index 7866ee3f..00000000 --- a/scripts/helpers/Build/Invoke-RecurseEscapeFix.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -function Invoke-RecurseEscapeFix { - <# - .SYNOPSIS - Recurse through a hashtable and escape single quotes in strings. - #> - param( - [Parameter(Mandatory)] - [AllowEmptyString()] - [AllowNull()] - [object] $Value - ) - - if (-not $Value) { - return $Value - } - - if ($Value -is [string]) { - # Escape single quotes in strings - return $Value -replace "'", "''" - } elseif ($Value -is [hashtable]) { - # Recursively process nested hashtables - $keys = @($Value.Keys) # Make a copy of the keys - foreach ($key in $keys) { - $Value[$key] = Invoke-RecurseEscapeFix -Value $Value[$key] - } - } elseif ($Value -is [array]) { - # Recursively process arrays - for ($i = 0; $i -lt $Value.Count; $i++) { - $Value[$i] = Invoke-RecurseEscapeFix -Value $Value[$i] - } - } - - return $Value -} diff --git a/scripts/helpers/Build/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Build/Resolve-PSModuleDependency.ps1 index 7d8d0675..8a6ddca8 100644 --- a/scripts/helpers/Build/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Build/Resolve-PSModuleDependency.ps1 @@ -26,11 +26,11 @@ function Resolve-PSModuleDependency { [string] $ManifestFilePath ) - Write-Verbose 'Resolving dependencies' + Write-Host 'Resolving dependencies' $manifest = Import-PowerShellDataFile -Path $ManifestFilePath - Write-Verbose "Reading [$ManifestFilePath]" - Write-Verbose "Found [$($manifest.RequiredModules.Count)] modules to install" + Write-Host "Reading [$ManifestFilePath]" + Write-Host "Found [$($manifest.RequiredModules.Count)] modules to install" foreach ($requiredModule in $manifest.RequiredModules) { $installParams = @{} @@ -46,19 +46,19 @@ function Resolve-PSModuleDependency { $installParams.Force = $true $installParams.Verbose = $false - Write-Verbose "[$($installParams.Name)] - Installing module" + Write-Host "[$($installParams.Name)] - Installing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' Retry -Count 5 -Delay 10 { Install-Module @installParams -AllowPrerelease:$false } $VerbosePreference = $VerbosePreferenceOriginal - Write-Verbose "[$($installParams.Name)] - Importing module" + Write-Host "[$($installParams.Name)] - Importing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' Import-Module @installParams $VerbosePreference = $VerbosePreferenceOriginal - Write-Verbose "[$($installParams.Name)] - Done" + Write-Host "[$($installParams.Name)] - Done" } - Write-Verbose 'Resolving dependencies - Done' + Write-Host 'Resolving dependencies - Done' } diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index d38506b4..ac805c95 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -21,17 +21,17 @@ function Update-PSModuleManifestAliasesToExport { [Parameter(Mandatory)] [System.IO.DirectoryInfo] $ModuleOutputFolder ) - LogGroup "Updating aliases to export in module manifest" { - Write-Verbose "Module name: [$ModuleName]" - Write-Verbose "Module output folder: [$ModuleOutputFolder]" + LogGroup 'Updating aliases to export in module manifest' { + Write-Host "Module name: [$ModuleName]" + Write-Host "Module output folder: [$ModuleOutputFolder]" $aliases = Get-Command -Module $ModuleName -CommandType Alias - Write-Verbose "Found aliases: [$($aliases.Count)]" + Write-Host "Found aliases: [$($aliases.Count)]" foreach ($alias in $aliases) { - Write-Verbose "Alias: [$($alias.Name)]" + Write-Host "Alias: [$($alias.Name)]" } $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" - Write-Verbose "Output manifest path: [$outputManifestPath]" - Write-Verbose "Setting module manifest with AliasesToExport" + Write-Host "Output manifest path: [$outputManifestPath]" + Write-Host 'Setting module manifest with AliasesToExport' Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $aliases.Name -Verbose } }