From 0347c2e36fc14940d44195ff5a64603f924a1f77 Mon Sep 17 00:00:00 2001 From: Matthew Lonisis Date: Wed, 4 Dec 2019 19:30:47 -0500 Subject: [PATCH 1/4] Update Get-PSScriptInfoString.ps1 Removed trailing whitespace on line 90. Refactored lines 96-97 to be a one line code. This enhancement functions like the original code, but now won't add an extra newline if the release notes provided are null or empty. --- .../private/functions/Get-PSScriptInfoString.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PowerShellGet/private/functions/Get-PSScriptInfoString.ps1 b/src/PowerShellGet/private/functions/Get-PSScriptInfoString.ps1 index d6fa9f37..fb7a29a5 100644 --- a/src/PowerShellGet/private/functions/Get-PSScriptInfoString.ps1 +++ b/src/PowerShellGet/private/functions/Get-PSScriptInfoString.ps1 @@ -87,14 +87,13 @@ function Get-PSScriptInfoString .ICONURI$(if ($IconUri) {" $IconUri"}) -.EXTERNALMODULEDEPENDENCIES$(if ($ExternalModuleDependencies) {" $($ExternalModuleDependencies -join ',')"}) +.EXTERNALMODULEDEPENDENCIES$(if ($ExternalModuleDependencies) {" $($ExternalModuleDependencies -join ',')"}) .REQUIREDSCRIPTS$(if ($RequiredScripts) {" $($RequiredScripts -join ',')"}) .EXTERNALSCRIPTDEPENDENCIES$(if ($ExternalScriptDependencies) {" $($ExternalScriptDependencies -join ',')"}) -.RELEASENOTES -$($ReleaseNotes -join "`r`n") +.RELEASENOTES$(if ($ReleaseNotes) {`r`n$($ReleaseNotes -join "`r`n")}) .PRIVATEDATA$(if ($PrivateData) {" $PrivateData"}) From 0fc61569b47c0d0f049c424deb7d6b583de1d9d6 Mon Sep 17 00:00:00 2001 From: Matthew Lonisis Date: Wed, 4 Dec 2019 19:31:24 -0500 Subject: [PATCH 2/4] Update Get-ScriptCommentHelpInfoString.ps1 Removed trailing whitespace from the help info text. --- .../Get-ScriptCommentHelpInfoString.ps1 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/PowerShellGet/private/functions/Get-ScriptCommentHelpInfoString.ps1 b/src/PowerShellGet/private/functions/Get-ScriptCommentHelpInfoString.ps1 index 258431b2..0920b52d 100644 --- a/src/PowerShellGet/private/functions/Get-ScriptCommentHelpInfoString.ps1 +++ b/src/PowerShellGet/private/functions/Get-ScriptCommentHelpInfoString.ps1 @@ -47,11 +47,11 @@ function Get-ScriptCommentHelpInfoString Process { - $ScriptCommentHelpInfoString = "<# `r`n`r`n.DESCRIPTION `r`n $Description `r`n`r`n" + $ScriptCommentHelpInfoString = "<#`r`n`r`n.DESCRIPTION`r`n$Description`r`n`r`n" if("$Synopsis".Trim()) { - $ScriptCommentHelpInfoString += ".SYNOPSIS `r`n$Synopsis `r`n`r`n" + $ScriptCommentHelpInfoString += ".SYNOPSIS`r`n$Synopsis`r`n`r`n" } if("$Example".Trim()) @@ -59,7 +59,7 @@ function Get-ScriptCommentHelpInfoString $Example | ForEach-Object { if($_) { - $ScriptCommentHelpInfoString += ".EXAMPLE `r`n$_ `r`n`r`n" + $ScriptCommentHelpInfoString += ".EXAMPLE`r`n$_`r`n`r`n" } } } @@ -69,7 +69,7 @@ function Get-ScriptCommentHelpInfoString $Inputs | ForEach-Object { if($_) { - $ScriptCommentHelpInfoString += ".INPUTS `r`n$_ `r`n`r`n" + $ScriptCommentHelpInfoString += ".INPUTS`r`n$_`r`n`r`n" } } } @@ -79,14 +79,14 @@ function Get-ScriptCommentHelpInfoString $Outputs | ForEach-Object { if($_) { - $ScriptCommentHelpInfoString += ".OUTPUTS `r`n$_ `r`n`r`n" + $ScriptCommentHelpInfoString += ".OUTPUTS`r`n$_`r`n`r`n" } } } if("$Notes".Trim()) { - $ScriptCommentHelpInfoString += ".NOTES `r`n$($Notes -join "`r`n") `r`n`r`n" + $ScriptCommentHelpInfoString += ".NOTES`r`n$($Notes -join "`r`n")`r`n`r`n" } if("$Link".Trim()) @@ -94,27 +94,27 @@ function Get-ScriptCommentHelpInfoString $Link | ForEach-Object { if($_) { - $ScriptCommentHelpInfoString += ".LINK `r`n$_ `r`n`r`n" + $ScriptCommentHelpInfoString += ".LINK`r`n$_`r`n`r`n" } } } if("$Component".Trim()) { - $ScriptCommentHelpInfoString += ".COMPONENT `r`n$($Component -join "`r`n") `r`n`r`n" + $ScriptCommentHelpInfoString += ".COMPONENT`r`n$($Component -join "`r`n")`r`n`r`n" } if("$Role".Trim()) { - $ScriptCommentHelpInfoString += ".ROLE `r`n$($Role -join "`r`n") `r`n`r`n" + $ScriptCommentHelpInfoString += ".ROLE`r`n$($Role -join "`r`n")`r`n`r`n" } if("$Functionality".Trim()) { - $ScriptCommentHelpInfoString += ".FUNCTIONALITY `r`n$($Functionality -join "`r`n") `r`n`r`n" + $ScriptCommentHelpInfoString += ".FUNCTIONALITY`r`n$($Functionality -join "`r`n")`r`n`r`n" } - $ScriptCommentHelpInfoString += "#> `r`n" + $ScriptCommentHelpInfoString += "#>`r`n" return $ScriptCommentHelpInfoString } From 8cce2c460e7b8efd46e3ba76c0cbcaa6485e5f62 Mon Sep 17 00:00:00 2001 From: Matthew Lonisis Date: Wed, 4 Dec 2019 19:33:18 -0500 Subject: [PATCH 3/4] Update Update-ScriptFileInfo.ps1 1. Removed trailing whitespace on line 444 (now line 454) 2. Refactored lines 399 to no longer add extra whitespace in the event that $requiredStrings is the empty string 3. Added new code between lines 405 and 406 to fully resolve issue #165 --- .../psgetfunctions/Update-ScriptFileInfo.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 b/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 index 860dd556..0586b851 100644 --- a/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 +++ b/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 @@ -396,13 +396,23 @@ function Update-ScriptFileInfo { $PSScriptInfoString = $PSScriptInfoString.TrimStart() $requiresStrings = $requiresStrings.TrimEnd() - $tempContents += "$PSScriptInfoString `r`n`r`n$($requiresStrings -join "`r`n")" + if ("$requiresStrings".Trim()) { + $tempContents += "$PSScriptInfoString`r`n`r`n$($requiresStrings -join "`r`n")" + } else { + $tempContents += $PSScriptInfoString + } $IsNewPScriptInfoAdded = $true } } elseif ($line -notmatch "\s*#Requires\s+-Module") { # Add the existing lines if they are not part of PSScriptInfo comment or not containing #Requires -Module statements. $tempContents += $line + } elseif (($scriptFileContents[$i + 1] -eq "`r`n" -or $scriptFileContents[$i + 1] -eq "") -and (($i + 1) -lt $scriptFileContents.Count)) { + # This condition will only be met if the line is a Requires -Module statement. + # To adding newlines everytime the function is called on a script, we must increment i by 1 + # if the next line after the caught Requires -Module statement is the empty string or a `r`n + # This prevents extra newlines from being inserted + $i = $i + 1 } } @@ -441,7 +451,7 @@ function Update-ScriptFileInfo { if ($line.Trim().StartsWith("#>", [System.StringComparison]::OrdinalIgnoreCase) -or $line.Trim().StartsWith(".", [System.StringComparison]::OrdinalIgnoreCase)) { - $tempContents += ".DESCRIPTION `r`n$($Description -join "`r`n")`r`n" + $tempContents += ".DESCRIPTION`r`n$($Description -join "`r`n")`r`n" $IsDescriptionAdded = $true $tempContents += $line } From b6839c431df6b56ffb5e277f04017f17b1b86d3d Mon Sep 17 00:00:00 2001 From: Matthew Lonisis Date: Wed, 4 Dec 2019 19:46:28 -0500 Subject: [PATCH 4/4] Update Update-ScriptFileInfo.ps1 --- .../public/psgetfunctions/Update-ScriptFileInfo.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 b/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 index 0586b851..dd90bf58 100644 --- a/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 +++ b/src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1 @@ -396,7 +396,7 @@ function Update-ScriptFileInfo { $PSScriptInfoString = $PSScriptInfoString.TrimStart() $requiresStrings = $requiresStrings.TrimEnd() - if ("$requiresStrings".Trim()) { + if ($requiresStrings.Trim() -ne "") { $tempContents += "$PSScriptInfoString`r`n`r`n$($requiresStrings -join "`r`n")" } else { $tempContents += $PSScriptInfoString