From 937f4ff177eb35473ea8c537fded58a85e83d4f4 Mon Sep 17 00:00:00 2001 From: Bart Simons Date: Sun, 24 Mar 2019 14:15:01 +0100 Subject: [PATCH 1/3] Improve checking/validation of module markdown files in GetMarkdownFilesFromPath --- src/platyPS/platyPS.psm1 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/platyPS/platyPS.psm1 b/src/platyPS/platyPS.psm1 index 91c5bc32..6fe0db49 100644 --- a/src/platyPS/platyPS.psm1 +++ b/src/platyPS/platyPS.psm1 @@ -1512,7 +1512,22 @@ function GetMarkdownFilesFromPath } } - return $MarkdownFiles + $MarkdownFilesFiltered = @() + + If ($IncludeModulePage) { + $MarkdownFilesFiltered = $MarkdownFiles + } Else { + ForEach ($File in $MarkdownFiles) { + $Matches = [regex]::Match((Get-Content $File.FullName -Raw), 'Module Name: (.+)').Captures.Groups + if ($Matches.Length -ge 2) { + if (($Matches[1].Value.replace("`n","").replace("`r","")) -ne $File.BaseName) { + $MarkdownFilesFiltered += $File + } + } + } + } + + return $MarkdownFilesFiltered } function GetParserMode From 17aa4b72b0a7ce123fb43237078595007910d8cd Mon Sep 17 00:00:00 2001 From: Bart Simons Date: Sat, 30 Mar 2019 21:27:09 +0100 Subject: [PATCH 2/3] Improve module file markdown check --- src/platyPS/platyPS.psm1 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/platyPS/platyPS.psm1 b/src/platyPS/platyPS.psm1 index 6fe0db49..e2ebb533 100644 --- a/src/platyPS/platyPS.psm1 +++ b/src/platyPS/platyPS.psm1 @@ -1518,11 +1518,9 @@ function GetMarkdownFilesFromPath $MarkdownFilesFiltered = $MarkdownFiles } Else { ForEach ($File in $MarkdownFiles) { - $Matches = [regex]::Match((Get-Content $File.FullName -Raw), 'Module Name: (.+)').Captures.Groups - if ($Matches.Length -ge 2) { - if (($Matches[1].Value.replace("`n","").replace("`r","")) -ne $File.BaseName) { - $MarkdownFilesFiltered += $File - } + $Matches = [regex]::Match((Get-Content $File.FullName -Raw), "# $($File.BaseName) Module").Captures.Groups + if ($Matches.Length -eq 0) { + $MarkdownFilesFiltered += $File } } } From 1aa208782937cbafd70ad27b89ddf0fca0b0cf33 Mon Sep 17 00:00:00 2001 From: Bart Simons Date: Wed, 10 Apr 2019 22:54:43 +0200 Subject: [PATCH 3/3] Implement extra tests for generating external help files. --- test/Pester/PlatyPs.Tests.ps1 | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/Pester/PlatyPs.Tests.ps1 b/test/Pester/PlatyPs.Tests.ps1 index abf18616..2077c718 100644 --- a/test/Pester/PlatyPs.Tests.ps1 +++ b/test/Pester/PlatyPs.Tests.ps1 @@ -657,6 +657,90 @@ Describe 'New-ExternalHelp' { $xml = [xml] (Get-Content (Join-Path $TestDrive 'TestOrderFunction.xml')) $xml.helpItems.namespaceuri | Should Be 'http://msh' } + + It "Checks if external help files are generated correctly" { + New-Item -ItemType Directory -Path (Join-Path $TestDrive "\docs\") + New-Item -ItemType Directory -Path (Join-Path $TestDrive "\en-US\") + + Set-Content -Path (Join-Path $TestDrive "\docs\TestModule.md") -Value @' +--- +Module Name: TestModule +Module Guid: 3790ec3e-4ec0-41cb-9ebf-ae083b883b74 +Download Help Link: https://test.com/release/TestModule/docs/TestModule.md +Help Version: 0.1.0 +Locale: en-US +--- + +# TestModule Module +## Description +Blablablabla + +## TestModule Cmdlets +### [Invoke-Test](Invoke-Test.md) +TBD + + + +'@ + + Set-Content -Path (Join-Path $TestDrive "\docs\Invoke-Test.md") -Value @' +--- +external help file: TestModule-help.xml +Module Name: TestModule +online version: https://test.com +schema: 2.0.0 +--- + +# Invoke-Test + +## SYNOPSIS +TBD + +## SYNTAX + +``` +Invoke-Test [] +``` + +## DESCRIPTION +TBD + +## EXAMPLES + +### EXAMPLE 1 +``` +TBD +``` + +## PARAMETERS + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +Author: Bart + +## RELATED LINKS + +[https://test.com](https://test.com) + + +'@ + + (New-ExternalHelp -Path "$TestDrive\docs" -OutputPath "$TestDrive\en-US" -Force)[0].Name | Should Be 'TestModule-help.xml' + } + + It "Checks if external help files are generated correctly with dash in module markdown file" { + Rename-Item -Path (Join-Path $TestDrive "\docs\TestModule.md") -NewName "Test-Module.md" + (Get-Content "$TestDrive\docs\Test-Module.md") -replace "TestModule", "Test-Module" | Set-Content "$TestDrive\docs\Test-Module.md" + + (New-ExternalHelp -Path "$TestDrive\docs" -OutputPath "$TestDrive\en-US" -Force)[0].Name | Should Be 'TestModule-help.xml' + } } Describe 'New-ExternalHelp -ErrorLogFile' {