Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Mlonis fix for issue 165 #555

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simplifies the code into one line and further prevents the addition of a new line when the release notes section is being left blank or empty.


.PRIVATEDATA$(if ($PrivateData) {" $PrivateData"})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ 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())
{
$Example | ForEach-Object {
if($_)
{
$ScriptCommentHelpInfoString += ".EXAMPLE `r`n$_ `r`n`r`n"
$ScriptCommentHelpInfoString += ".EXAMPLE`r`n$_`r`n`r`n"
}
}
}
Expand All @@ -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"
}
}
}
Expand All @@ -79,42 +79,42 @@ 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())
{
$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
}
Expand Down
14 changes: 12 additions & 2 deletions src/PowerShellGet/public/psgetfunctions/Update-ScriptFileInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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() -ne "") {
$tempContents += "$PSScriptInfoString`r`n`r`n$($requiresStrings -join "`r`n")"
} else {
$tempContents += $PSScriptInfoString
}
Comment on lines +399 to +403
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resolves issue #165 by not adding extra newlines if the user did not supply any required modules. If the user does not supply any required modules, Get-RequiresString returns the empty string.

$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
Comment on lines +410 to +415
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section accounts for the edge case where a script file already has Requires -Module statements and prevents the addition of new lines by incrementing $i when it detects that the line following the last Requires -Modules statement is a character return newline sequence or the empty string.

}
}

Expand Down Expand Up @@ -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
}
Expand Down