Skip to content

Commit 21d07b9

Browse files
mjr4077aufflaten
andauthored
- Allow specification of markdown files to process with New-DocusaurusHelp. (#201) [release]
* - Allow specification of markdown files to process with `New-DocusaurusHelp`. * - Rework new `New-DocusaurusHelp` parameter `-MarkdownCachePath` to `-PlatyPSMarkdownPath`. As requested, place it into a separate parameter set and munge out the module's name from the supplied files. * - Don't use the caller's relative path within `build-module.ps1`. * - Ensure that `New-DocusaurusHelp`'s `-PlatyPSMarkdownPath` parameter is mandatory within its parameter set. Co-authored-by: Frode Flaten <[email protected]> * - Rework module name ascertaining for `-PlatyPSMarkdownPath` code. * - Rate-limit the module name ascertaining for `-PlatyPSMarkdownPath` code to the first 10 files. * - Properly guard off the module importing code when `-PlatyPSMarkdownPath` is used. * - Rework "- Rate-limit the module name ascertaining for `-PlatyPSMarkdownPath` code to the first 10 files." to the correct intention of the reviewer. * - Revert an aspect of the module import code in `New-DocusaurusHelp` to be 1:1 before I started so Pester doesn't have a sad. * - Update documents export for website. --------- Co-authored-by: Frode Flaten <[email protected]>
1 parent ae54305 commit 21d07b9

File tree

4 files changed

+114
-46
lines changed

4 files changed

+114
-46
lines changed

Source/Public/New-DocusaurusHelp.ps1

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ function New-DocusaurusHelp() {
4949
5050
You may specify a module name, a `.psd1` file or a `.psm1` file.
5151
52+
.PARAMETER PlatyPSMarkdownPath
53+
Specifies a path containing already prepared PlatyPS markdown files for processing.
54+
55+
If not provided, this function will generate the necessary files as required.
56+
5257
.PARAMETER DocsFolder
5358
Specifies the absolute or relative **path** to the Docusaurus `docs` folder.
5459
@@ -148,7 +153,10 @@ function New-DocusaurusHelp() {
148153
#>
149154
[cmdletbinding()]
150155
param(
151-
[Parameter(Mandatory = $True)][string]$Module,
156+
[Parameter(Mandatory = $True, ParameterSetName = 'Module')][string]$Module,
157+
[Parameter(Mandatory = $True, ParameterSetName = 'PlatyPSMarkdownPath')]
158+
[ValidateScript({ [System.IO.Directory]::Exists($_) })]
159+
[string]$PlatyPSMarkdownPath,
152160
[Parameter(Mandatory = $False)][string]$DocsFolder = "docusaurus/docs",
153161
[Parameter(Mandatory = $False)][string]$Sidebar = "commands",
154162
[Parameter(Mandatory = $False)][array]$Exclude = @(),
@@ -167,18 +175,57 @@ function New-DocusaurusHelp() {
167175

168176
GetCallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
169177

170-
# make sure the passed module is valid
171-
if (Test-Path($Module)) {
172-
Import-Module $Module -Force -Global
173-
$Module = [System.IO.Path]::GetFileNameWithoutExtension($Module)
174-
}
178+
# Get the module's name fromn the supplied markdown files.
179+
if ($PSCmdlet.ParameterSetName.Equals('PlatyPSMarkdownPath'))
180+
{
181+
# Get the module's name from the supplied markdown files.
182+
$moduleName = Get-ChildItem -LiteralPath $PlatyPSMarkdownPath -Filter *.md |
183+
Get-Content -ReadCount 10 -TotalCount 10 |
184+
ForEach-Object { $_ -match '^Module Name: ' -replace '^Module Name:\s+' } |
185+
Select-Object -Unique
186+
187+
# Throw if null or we've got more than one item.
188+
if ($null -eq $moduleName)
189+
{
190+
$errSentence1 = 'Unable to determine the module name from the supplied markdown files.'
191+
$errSentence2 = 'Please confirm their validity and try again.'
192+
$PSCmdlet.ThrowTerminatingError([System.Management.Automation.ErrorRecord]::new(
193+
[System.ArgumentException]::new("$errSentence1 $errSentence2", 'PlatyPSMarkdownPath'),
194+
'ModuleNameIndeterminateError',
195+
[System.Management.Automation.ErrorCategory]::InvalidResult,
196+
$moduleName
197+
))
198+
}
199+
elseif ($moduleName -isnot [System.String])
200+
{
201+
$errSentence1 = "More than one module name was found within the supplied markdown files ('$([System.String]::Join("', '", $moduleName))')."
202+
$errSentence2 = 'Please supply unique markdown files for a single module and try again.'
203+
$PSCmdlet.ThrowTerminatingError([System.Management.Automation.ErrorRecord]::new(
204+
[System.ArgumentException]::new("$errSentence1 $errSentence2", 'PlatyPSMarkdownPath'),
205+
'DuplicateModuleNameError',
206+
[System.Management.Automation.ErrorCategory]::InvalidResult,
207+
$moduleName
208+
))
209+
}
175210

176-
if (-Not(Get-Module -Name $Module)) {
177-
$Module = $Module
178-
throw "New-DocusaurusHelp: Specified module '$Module' is not loaded"
211+
# Trim off the leading characters before continuing.
212+
$Module = $moduleName
179213
}
214+
else
215+
{
216+
# make sure the passed module is valid
217+
if (Test-Path($Module)) {
218+
Import-Module $Module -Force -Global
219+
$Module = [System.IO.Path]::GetFileNameWithoutExtension($Module)
220+
}
180221

181-
$moduleName = [io.path]::GetFileName($module)
222+
if (-Not(Get-Module -Name $Module)) {
223+
$Module = $Module
224+
throw "New-DocusaurusHelp: Specified module '$Module' is not loaded"
225+
}
226+
227+
$moduleName = [io.path]::GetFileName($module)
228+
}
182229

183230
# get version of this module so we can e.g. add version tag to generated files
184231
$alt3Version = Split-Path -Leaf $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase
@@ -194,8 +241,16 @@ function New-DocusaurusHelp() {
194241
InitializeTempFolder -Path $tempFolder
195242

196243
# generate PlatyPs markdown files
197-
Write-Verbose "Generating PlatyPS files."
198-
New-MarkdownHelp -Module $Module -OutputFolder $tempFolder -Force | Out-Null
244+
if ($PSCmdlet.ParameterSetName.Equals('Module'))
245+
{
246+
Write-Verbose "Generating PlatyPS files."
247+
New-MarkdownHelp -Module $Module -OutputFolder $tempFolder -Force | Out-Null
248+
}
249+
else
250+
{
251+
Write-Verbose "Copying cached markdown files to temp folder."
252+
Copy-Item -Path $PlatyPSMarkdownPath\*.md -Destination $tempFolder -Force -Confirm:$false
253+
}
199254

200255
# remove files matching excluded commands
201256
Write-Verbose "Removing excluded files:"

build-module.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ param(
4747

4848
# Build new Alt3 module
4949
Write-Output "Building new module"
50-
Build-Module -SourcePath .\Source -VersionedOutputDirectory
50+
Build-Module -SourcePath $PSScriptRoot\Source -VersionedOutputDirectory
5151

5252
# Prevent duplicate module versions breaking PlatyPS
5353
Remove-Module Alt3.Docusaurus.Powershell -Force -ErrorAction SilentlyContinue
5454

5555
# Determine latest module version
56-
$outputFolder = ".\Output\Alt3.Docusaurus.Powershell"
56+
$outputFolder = "$PSScriptRoot\Output\Alt3.Docusaurus.Powershell"
5757
$latestModuleVersion = (Get-ChildItem -Path $outputFolder -Directory | Sort-Object CreationTime | Select-Object -Last 1).Name
5858
Write-Output "Importing newly built module $latestModuleVersion"
5959

website/docs/commands/New-DocusaurusHelp.mdx

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ Generates Get-Help documentation in Docusaurus compatible `.mdx` format.
2121

2222
## SYNTAX
2323

24+
### Module
25+
26+
```powershell
27+
New-DocusaurusHelp -Module <String> [-DocsFolder <String>] [-Sidebar <String>] [-Exclude <Array>]
28+
[-EditUrl <String>] [-MetaDescription <String>] [-MetaKeywords <Array>] [-PrependMarkdown <String>]
29+
[-AppendMarkdown <String>] [-KeepHeader1] [-HideTitle] [-HideTableOfContents] [-NoPlaceHolderExamples]
30+
[-Monolithic] [-VendorAgnostic] [<CommonParameters>]
31+
```
32+
33+
### PlatyPSMarkdownPath
34+
2435
```powershell
25-
New-DocusaurusHelp [-Module] <String> [[-DocsFolder] <String>] [[-Sidebar] <String>] [[-Exclude] <Array>]
26-
[[-EditUrl] <String>] [[-MetaDescription] <String>] [[-MetaKeywords] <Array>] [[-PrependMarkdown] <String>]
27-
[[-AppendMarkdown] <String>] [-KeepHeader1] [-HideTitle] [-HideTableOfContents] [-NoPlaceHolderExamples]
28-
[-Monolithic] [-VendorAgnostic] [-ProgressAction <ActionPreference>] [<CommonParameters>]
36+
New-DocusaurusHelp -PlatyPSMarkdownPath <String> [-DocsFolder <String>] [-Sidebar <String>] [-Exclude <Array>]
37+
[-EditUrl <String>] [-MetaDescription <String>] [-MetaKeywords <Array>] [-PrependMarkdown <String>]
38+
[-AppendMarkdown <String>] [-KeepHeader1] [-HideTitle] [-HideTableOfContents] [-NoPlaceHolderExamples]
39+
[-Monolithic] [-VendorAgnostic] [<CommonParameters>]
2940
```
3041

3142
## DESCRIPTION
@@ -83,11 +94,29 @@ You may specify a module name, a `.psd1` file or a `.psm1` file.
8394

8495
```yaml
8596
Type: String
86-
Parameter Sets: (All)
97+
Parameter Sets: Module
8798
Aliases:
8899

89100
Required: True
90-
Position: 1
101+
Position: Named
102+
Default value: None
103+
Accept pipeline input: False
104+
Accept wildcard characters: False
105+
```
106+
107+
### -PlatyPSMarkdownPath
108+
109+
Specifies a path containing already prepared PlatyPS markdown files for processing.
110+
111+
If not provided, this function will generate the necessary files as required.
112+
113+
```yaml
114+
Type: String
115+
Parameter Sets: PlatyPSMarkdownPath
116+
Aliases:
117+
118+
Required: True
119+
Position: Named
91120
Default value: None
92121
Accept pipeline input: False
93122
Accept wildcard characters: False
@@ -105,7 +134,7 @@ Parameter Sets: (All)
105134
Aliases:
106135
107136
Required: False
108-
Position: 2
137+
Position: Named
109138
Default value: Docusaurus/docs
110139
Accept pipeline input: False
111140
Accept wildcard characters: False
@@ -123,7 +152,7 @@ Parameter Sets: (All)
123152
Aliases:
124153
125154
Required: False
126-
Position: 3
155+
Position: Named
127156
Default value: Commands
128157
Accept pipeline input: False
129158
Accept wildcard characters: False
@@ -139,7 +168,7 @@ Parameter Sets: (All)
139168
Aliases:
140169
141170
Required: False
142-
Position: 4
171+
Position: Named
143172
Default value: @()
144173
Accept pipeline input: False
145174
Accept wildcard characters: False
@@ -157,7 +186,7 @@ Parameter Sets: (All)
157186
Aliases:
158187
159188
Required: False
160-
Position: 5
189+
Position: Named
161190
Default value: None
162191
Accept pipeline input: False
163192
Accept wildcard characters: False
@@ -175,7 +204,7 @@ Parameter Sets: (All)
175204
Aliases:
176205
177206
Required: False
178-
Position: 6
207+
Position: Named
179208
Default value: None
180209
Accept pipeline input: False
181210
Accept wildcard characters: False
@@ -191,7 +220,7 @@ Parameter Sets: (All)
191220
Aliases:
192221
193222
Required: False
194-
Position: 7
223+
Position: Named
195224
Default value: None
196225
Accept pipeline input: False
197226
Accept wildcard characters: False
@@ -209,7 +238,7 @@ Parameter Sets: (All)
209238
Aliases:
210239
211240
Required: False
212-
Position: 8
241+
Position: Named
213242
Default value: None
214243
Accept pipeline input: False
215244
Accept wildcard characters: False
@@ -227,7 +256,7 @@ Parameter Sets: (All)
227256
Aliases:
228257
229258
Required: False
230-
Position: 9
259+
Position: Named
231260
Default value: None
232261
Accept pipeline input: False
233262
Accept wildcard characters: False
@@ -352,22 +381,6 @@ Accept pipeline input: False
352381
Accept wildcard characters: False
353382
```
354383

355-
### -ProgressAction
356-
357-
\{\{ Fill ProgressAction Description \}\}
358-
359-
```yaml
360-
Type: ActionPreference
361-
Parameter Sets: (All)
362-
Aliases: proga
363-
364-
Required: False
365-
Position: Named
366-
Default value: None
367-
Accept pipeline input: False
368-
Accept wildcard characters: False
369-
```
370-
371384
### CommonParameters
372385

373386
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).
@@ -399,4 +412,4 @@ $tempFolder = Get-Item (Join-Path -Path ([System.IO.Path]::GetTempPath()) -Child
399412

400413
## ADDITIONAL INFORMATION
401414

402-
This page was auto-generated using the comment based help in Alt3.Docusaurus.Powershell 1.0.35.
415+
This page was auto-generated using the comment based help in Alt3.Docusaurus.Powershell 1.0.36.

website/docs/commands/docusaurus.sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Import this file in your Docusaurus `sidebars.js` file.
33
*
4-
* Auto-generated by Alt3.Docusaurus.Powershell 1.0.35.
4+
* Auto-generated by Alt3.Docusaurus.Powershell 1.0.36.
55
*
66
* Copyright (c) 2019-present, ALT3 B.V.
77
*

0 commit comments

Comments
 (0)