Skip to content
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
c50f986
🩹 [Patch]: Improve output formatting and streamline markdown file han…
MariusStorhaug Oct 6, 2025
0a86bdb
🩹 [Patch]: Fix path resolution for documentation output folder in Bui…
MariusStorhaug Oct 6, 2025
0b67829
🩹 [Patch]: Refactor variable names for clarity in Build-PSModuleDocum…
MariusStorhaug Oct 6, 2025
8ca2d56
🩹 [Patch]: Replace Import-Module with Get-Module for improved module …
MariusStorhaug Oct 6, 2025
8968498
🩹 [Patch]: Refactor to use $docsOutputFolder instead of $moduleDocsFo…
MariusStorhaug Oct 6, 2025
342a1ae
🩹 [Patch]: Replace Import-Module with Get-Module for improved module …
MariusStorhaug Oct 6, 2025
d85818b
🩹 [Patch]: Enhance output formatting by adding group markers for comm…
MariusStorhaug Oct 6, 2025
ef95348
Update scripts/helpers/Build-PSModuleDocumentation.ps1
MariusStorhaug Oct 6, 2025
4260607
Update scripts/helpers/Build-PSModuleDocumentation.ps1
MariusStorhaug Oct 6, 2025
e9eafda
🩹 [Patch]: Update output messages for clarity in command processing a…
MariusStorhaug Oct 6, 2025
499e4a5
Merge branch 'fixFolders' of https://github.com/PSModule/Document-PSM…
MariusStorhaug Oct 6, 2025
2efb31e
🩹 [Patch]: Sort markdown files by name before displaying in Build-PSM…
MariusStorhaug Oct 6, 2025
e7afed1
🩹 [Patch]: Add end group marker in Build-PSModuleDocumentation for be…
MariusStorhaug Oct 6, 2025
e6d2caa
🩹 [Patch]: Improve markdown file output by sorting and displaying rel…
MariusStorhaug Oct 6, 2025
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
43 changes: 22 additions & 21 deletions scripts/helpers/Build-PSModuleDocumentation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@

Write-Host '::group::Build docs - Generate markdown help - Raw'
Install-PSModule -Path $ModuleOutputFolder
$moduleInfo = Import-Module -Name $ModuleName -Force -PassThru
$moduleInfo = Import-Module -Name $ModuleName -PassThru -Verbose:$false -Force

# Get all exported commands from the module
$commands = $moduleInfo.ExportedCommands.Values | Where-Object { $_.CommandType -ne 'Alias' }

Write-Host "Found $($commands.Count) commands to process"

Write-Host "::group::Build docs - Generating markdown help files for $($commands.Count) commands in [$docsOutputFolder]"
foreach ($command in $commands) {
try {
Write-Host "$($command.Name)" -NoNewline
Expand All @@ -66,21 +65,24 @@
Force = $true
}
$null = New-MarkdownCommandHelp @params
Write-Host ' - ✓' -ForegroundColor Green
Write-Host " - $($PSStyle.Foreground.Green)✓$($PSStyle.Reset)"
} catch {
Write-Host ' - ✗' -ForegroundColor Red
Write-Host " - $($PSStyle.Foreground.Red)✗$($PSStyle.Reset)"
$_
}
}

Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$fileName = $_.Name
Write-Host "::group:: - [$fileName]"
Write-Host '::group::Build docs - Generated files'
Get-ChildItem -Path $docsOutputFolder -Recurse | Select-Object -ExpandProperty FullName

Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | Sort-Object FullName | ForEach-Object {
$relPath = [System.IO.Path]::GetRelativePath($docsOutputFolder, $_.FullName)
Write-Host "::group:: - [$relPath]"
Show-FileContent -Path $_
}

Write-Host '::group::Build docs - Fix markdown code blocks'
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$content = Get-Content -Path $_.FullName
$fixedOpening = $false
$newContent = @()
Expand All @@ -99,7 +101,7 @@
}

Write-Host '::group::Build docs - Fix markdown escape characters'
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$content = Get-Content -Path $_.FullName -Raw
$content = $content -replace '\\`', '`'
$content = $content -replace '\\\[', '['
Expand All @@ -112,50 +114,49 @@

Write-Host '::group::Build docs - Structure markdown files to match source files'
$PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item
$moduleDocsFolder = Join-Path $DocsOutputFolder.FullName $ModuleName
Get-ChildItem -Path $moduleDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$file = $_
$relPath = [System.IO.Path]::GetRelativePath($moduleDocsFolder, $file.FullName)
$relPath = [System.IO.Path]::GetRelativePath($docsOutputFolder, $file.FullName)
Write-Host " - $relPath"
Write-Host " Path: $file"

# find the source code file that matches the markdown file
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
Write-Host " PS1 path: $scriptPath"
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $moduleDocsFolder).Replace('.ps1', '.md')
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $docsOutputFolder).Replace('.ps1', '.md')
Write-Host " MD path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
}

Write-Host '::group::Build docs - Fix frontmatter title'
Get-ChildItem -Path $moduleDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$content = Get-Content -Path $_.FullName -Raw
# Replace 'title:' with 'ms.title:' in frontmatter only (between --- markers)
$content = $content -replace '(?s)^(---.*?)title:(.*?---)', '$1ms.title:$2'
$content | Set-Content -Path $_.FullName
}

Write-Host '::group::Build docs - Move markdown files from source files to docs'
$moduleDocsFolder = Join-Path $DocsOutputFolder.FullName $ModuleName
Write-Host '::group::Build docs - Move markdown files from public functions folder to docs output folder'
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$file = $_
$relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName)
Write-Host " - $relPath"
Write-Host " Path: $file"

$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $moduleDocsFolder)
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $docsOutputFolder)
Write-Host " MD path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
}
Write-Host '::endgroup::'

Write-Host '────────────────────────────────────────────────────────────────────────────────'
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$fileName = $_.Name
Write-Host "::group:: - [$fileName]"
Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | Sort-Object FullName | ForEach-Object {
$relPath = [System.IO.Path]::GetRelativePath($docsOutputFolder, $_.FullName)
Write-Host "::group:: - [$relPath]"
Show-FileContent -Path $_
}
}
Loading