forked from pester/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-command-reference.ps1
124 lines (106 loc) · 4.1 KB
/
generate-command-reference.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<#
.SYNOPSIS
Generates the MDX files used for the website's "Command Reference" pages.
.NOTES
Uses the latest Pester version unless a specific -PesterVersion is given.
.EXAMPLE
.\generate-command-reference.ps1
.EXAMPLE
.\generate-command-reference.ps1 -PesterVersion 4.10.1
.LINK
https://docusaurus-powershell.netlify.app/docs/faq/ci-cd
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $False)][string] $PesterVersion,
[Parameter(Mandatory = $False)][string] $PlatyPSVersion,
[Parameter(Mandatory = $False)][string] $DocusaurusVersion,
[switch]$SkipModuleImport
)
Set-StrictMode -Version Latest
$PSDefaultParameterValues['*:ErrorAction'] = "Stop"
Write-Host "Generating MDX files for website Command Reference" -BackgroundColor DarkGreen
# -----------------------------------------------------------------------------
# Install required modules
# -----------------------------------------------------------------------------
$ModuleList = [ordered]@{
'PlatyPS' = $PlatyPSVersion
'Alt3.Docusaurus.PowerShell' = $DocusaurusVersion
'Pester' = $PesterVersion
}
# Can't use the original enumerator here because we may modify the dictionary mid-process
$ModuleList.Keys.Clone() | ForEach-Object {
$ModuleName = $_
$RequestedVersion = $ModuleList.Item($ModuleName)
Write-Host "Requires $ModuleName $RequestedVersion"
if ([String]::IsNullOrEmpty($RequestedVersion)) {
Write-Host "=> Fetching module versions of $ModuleName from PSGallery..."
$RequestedVersion = (Find-Module -Name $ModuleName).Version
$ModuleList.Item($ModuleName) = $RequestedVersion
Write-Host "=> PSGallery version is $RequestedVersion"
}
$Installed = Get-Module -ListAvailable $ModuleName
if ($Installed -and ($Installed.Version -contains $RequestedVersion)) {
Write-Host "=> required version already installed"
} else {
if (-not $Installed) {
Write-Host "=> no versions installed: installing $RequestedVersion"
} else {
Write-Host "=> no matching version installed: installing $RequestedVersion"
}
Install-Module $ModuleName -RequiredVersion $RequestedVersion -Force -SkipPublisherCheck -AllowClobber -Scope CurrentUser
}
if (-not $SkipModuleImport) {
Write-Host "=> importing"
Import-Module -Name $ModuleName -RequiredVersion $RequestedVersion -Force
}
}
# -----------------------------------------------------------------------------
# Use below settings to manipulate the rendered MDX files
# -----------------------------------------------------------------------------
$docusaurusOptions = @{
Module = "Pester"
DocsFolder = "./docs"
SideBar = "commands"
EditUrl = "null" # prevent the `Edit this Page` button from appearing
Exclude = @(
"Get-MockDynamicParameter"
"Invoke-Mock"
"SafeGetCommand"
"Set-DynamicParameterVariable"
)
MetaDescription = 'Help page for the PowerShell Pester "%1" command'
MetaKeywords = @(
"PowerShell"
"Pester"
"Help"
"Documentation"
)
PrependMarkdown = @"
:::info This page was generated
Contributions are welcome in [Pester-repo](https://github.com/pester/pester).
:::
"@
AppendMarkdown = @"
## VERSION
*This page was generated using comment-based help in [Pester $($ModuleList.Pester)](https://github.com/pester/pester).*
"@
}
# -----------------------------------------------------------------------------
# Generate the new MDX files
# -----------------------------------------------------------------------------
Push-Location $PSScriptRoot
Write-Host (Get-Location)
Write-Host "Removing existing MDX files" -ForegroundColor Magenta
$outputFolder = Join-Path -Path $docusaurusOptions.DocsFolder -ChildPath $docusaurusOptions.Sidebar | Join-Path -ChildPath "*.*"
if (Test-Path -Path $outputFolder) {
Remove-Item -Path $outputFolder
}
Write-Host "Generating new MDX files" -ForegroundColor Magenta
New-DocusaurusHelp @docusaurusOptions
Write-Host "Render completed successfully" -BackgroundColor DarkGreen
Pop-Location
if ($ENV:GITHUB_ACTIONS) {
# Output Workflow information
Write-Host "::set-output name=pester-version::$($ModuleList.Item('Pester'))"
}