Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 4a0665f

Browse files
committed
Fix issue #338 and issue #339
1 parent 85e6783 commit 4a0665f

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
to the relevant DSC resource GitHub Wiki ([issue #142](https://github.com/PowerShell/DscResource.Tests/issues/142)).
5757
- Update New-DscResourcePowerShellHelp to optionally output the PowerShell help files to
5858
the resource specific path and fix the example processing.
59+
- The files are now outputted as UTF-8 (ASCII).
5960
- Added processing to `Test-PublishMetaData` for the InvalidGUID error from Test-ScriptFileInfo
6061
([issue #330](https://github.com/PowerShell/DscResource.Tests/issues/330)).
6162

DscResource.DocumentationHelper/PowerShellHelp.psm1

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,43 @@ $moduleName = $ExecutionContext.SessionState.Module
2424
$script:localizedData = Get-LocalizedData -ModuleName $moduleName -ModuleRoot $PSScriptRoot
2525

2626
<#
27-
.SYNOPSIS
28-
New-DscResourcePowerShellHelp generates PowerShell compatible help files for a DSC
29-
resource module
30-
31-
.DESCRIPTION
32-
The New-DscResourcePowerShellHelp cmdlet will review all of the MOF based resources
33-
in a specified module directory and will inject PowerShell help files for each resource.
34-
These help files include details on the property types for each resource, as well as a text
35-
description and examples where they exist.
27+
.SYNOPSIS
28+
New-DscResourcePowerShellHelp generates PowerShell compatible help files for a DSC
29+
resource module
3630
37-
The help files are output to the OutputPath directory if specified, or if not, they are
38-
output to the releveant resource's 'en-US' directory.
31+
.DESCRIPTION
32+
The New-DscResourcePowerShellHelp cmdlet will review all of the MOF based resources
33+
in a specified module directory and will inject PowerShell help files for each resource.
34+
These help files include details on the property types for each resource, as well as a text
35+
description and examples where they exist.
3936
40-
A README.md with a text description must exist in the resource's subdirectory for the
41-
help file to be generated.
37+
The help files are output to the OutputPath directory if specified, or if not, they are
38+
output to the releveant resource's 'en-US' directory.
4239
43-
These help files can then be read by passing the name of the resource as a parameter to Get-Help.
40+
A README.md with a text description must exist in the resource's subdirectory for the
41+
help file to be generated.
4442
45-
.PARAMETER ModulePath
46-
The path to the root of the DSC resource module (where the PSD1 file is found, not the folder for
47-
each individual DSC resource)
43+
These help files can then be read by passing the name of the resource as a parameter to Get-Help.
4844
49-
.EXAMPLE
50-
This example shows how to generate help for a specific module
45+
.PARAMETER ModulePath
46+
The path to the root of the DSC resource module (where the PSD1 file is found, not the folder for
47+
each individual DSC resource)
5148
52-
New-DscResourcePowerShellHelp -ModulePath C:\repos\SharePointdsc
49+
.EXAMPLE
50+
This example shows how to generate help for a specific module
5351
52+
New-DscResourcePowerShellHelp -ModulePath C:\repos\SharePointdsc
5453
#>
5554
function New-DscResourcePowerShellHelp
5655
{
5756
[CmdletBinding()]
5857
param
5958
(
60-
[parameter(Mandatory = $true)]
59+
[Parameter(Mandatory = $true)]
6160
[System.String]
6261
$ModulePath,
6362

64-
[parameter()]
63+
[Parameter()]
6564
[System.String]
6665
$OutputPath
6766
)
@@ -70,14 +69,17 @@ function New-DscResourcePowerShellHelp
7069

7170
$mofSearchPath = (Join-Path -Path $ModulePath -ChildPath '\**\*.schema.mof')
7271
$mofSchemas = Get-ChildItem -Path $mofSearchPath -Recurse
72+
7373
Write-Verbose -Message ($script:localizedData.FoundMofFilesMessage -f $mofSchemas.Count, $ModulePath)
74+
7475
$mofSchemas | ForEach-Object {
7576
$mofFileObject = $_
7677

7778
$result = (Get-MofSchemaObject -FileName $_.FullName) | Where-Object -FilterScript {
7879
($_.ClassName -eq $mofFileObject.Name.Replace('.schema.mof', '')) `
7980
-and ($null -ne $_.FriendlyName)
8081
}
82+
8183
$descriptionPath = Join-Path -Path $mofFileObject.DirectoryName -ChildPath 'readme.md'
8284

8385
if (Test-Path -Path $descriptionPath)
@@ -89,8 +91,11 @@ function New-DscResourcePowerShellHelp
8991
$output += [Environment]::NewLine + [Environment]::NewLine
9092

9193
$descriptionContent = Get-Content -Path $descriptionPath -Raw
92-
$descriptionContent = $descriptionContent -replace "\n", "`n "
93-
$descriptionContent = $descriptionContent -replace "# Description\r\n ", ".DESCRIPTION"
94+
95+
$descriptionContent = $descriptionContent -replace '\n', "`n "
96+
$descriptionContent = $descriptionContent -replace '# Description\r\n ', '.DESCRIPTION'
97+
$descriptionContent = $descriptionContent -replace '\r\n\s{4}\r\n', "`n`n"
98+
$descriptionContent = $descriptionContent -replace '\s{4}$', ''
9499

95100
$output += $descriptionContent
96101
$output += [Environment]::NewLine
@@ -150,8 +155,10 @@ function New-DscResourcePowerShellHelp
150155
{
151156
$savePath = Join-Path -Path $mofFileObject.DirectoryName -ChildPath 'en-US' | Join-Path -ChildPath $outputFileName
152157
}
158+
153159
Write-Verbose -Message ($script:localizedData.OutputHelpDocumentMessage -f $savePath)
154-
$output | Out-File -FilePath $savePath -Encoding utf8 -Force
160+
161+
$output | Out-File -FilePath $savePath -Encoding ascii -Force
155162
}
156163
else
157164
{

0 commit comments

Comments
 (0)