|
47 | 47 |
|
48 | 48 | Write-Host '::group::Build docs - Generate markdown help - Raw' |
49 | 49 | Install-PSModule -Path $ModuleOutputFolder |
50 | | - $moduleInfo = Import-Module -Name $ModuleName -Force -PassThru |
| 50 | + $moduleInfo = Import-Module -Name $ModuleName -PassThru -Verbose:$false -Force |
51 | 51 |
|
52 | 52 | # Get all exported commands from the module |
53 | 53 | $commands = $moduleInfo.ExportedCommands.Values | Where-Object { $_.CommandType -ne 'Alias' } |
54 | 54 |
|
55 | | - Write-Host "Found $($commands.Count) commands to process" |
56 | | - |
| 55 | + Write-Host "::group::Build docs - Generating markdown help files for $($commands.Count) commands in [$docsOutputFolder]" |
57 | 56 | foreach ($command in $commands) { |
58 | 57 | try { |
59 | 58 | Write-Host "$($command.Name)" -NoNewline |
|
66 | 65 | Force = $true |
67 | 66 | } |
68 | 67 | $null = New-MarkdownCommandHelp @params |
69 | | - Write-Host ' - ✓' -ForegroundColor Green |
| 68 | + Write-Host " - $($PSStyle.Foreground.Green)✓$($PSStyle.Reset)" |
70 | 69 | } catch { |
71 | | - Write-Host ' - ✗' -ForegroundColor Red |
| 70 | + Write-Host " - $($PSStyle.Foreground.Red)✗$($PSStyle.Reset)" |
72 | 71 | $_ |
73 | 72 | } |
74 | 73 | } |
75 | 74 |
|
76 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
77 | | - $fileName = $_.Name |
78 | | - Write-Host "::group:: - [$fileName]" |
| 75 | + Write-Host '::group::Build docs - Generated files' |
| 76 | + Get-ChildItem -Path $docsOutputFolder -Recurse | Select-Object -ExpandProperty FullName |
| 77 | + |
| 78 | + Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | Sort-Object FullName | ForEach-Object { |
| 79 | + $relPath = [System.IO.Path]::GetRelativePath($docsOutputFolder, $_.FullName) |
| 80 | + Write-Host "::group:: - [$relPath]" |
79 | 81 | Show-FileContent -Path $_ |
80 | 82 | } |
81 | 83 |
|
82 | 84 | Write-Host '::group::Build docs - Fix markdown code blocks' |
83 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 85 | + Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
84 | 86 | $content = Get-Content -Path $_.FullName |
85 | 87 | $fixedOpening = $false |
86 | 88 | $newContent = @() |
|
99 | 101 | } |
100 | 102 |
|
101 | 103 | Write-Host '::group::Build docs - Fix markdown escape characters' |
102 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 104 | + Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
103 | 105 | $content = Get-Content -Path $_.FullName -Raw |
104 | 106 | $content = $content -replace '\\`', '`' |
105 | 107 | $content = $content -replace '\\\[', '[' |
|
112 | 114 |
|
113 | 115 | Write-Host '::group::Build docs - Structure markdown files to match source files' |
114 | 116 | $PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item |
115 | | - $moduleDocsFolder = Join-Path $DocsOutputFolder.FullName $ModuleName |
116 | | - Get-ChildItem -Path $moduleDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 117 | + Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
117 | 118 | $file = $_ |
118 | | - $relPath = [System.IO.Path]::GetRelativePath($moduleDocsFolder, $file.FullName) |
| 119 | + $relPath = [System.IO.Path]::GetRelativePath($docsOutputFolder, $file.FullName) |
119 | 120 | Write-Host " - $relPath" |
120 | 121 | Write-Host " Path: $file" |
121 | 122 |
|
122 | 123 | # find the source code file that matches the markdown file |
123 | 124 | $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } |
124 | 125 | Write-Host " PS1 path: $scriptPath" |
125 | | - $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $moduleDocsFolder).Replace('.ps1', '.md') |
| 126 | + $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $docsOutputFolder).Replace('.ps1', '.md') |
126 | 127 | Write-Host " MD path: $docsFilePath" |
127 | 128 | $docsFolderPath = Split-Path -Path $docsFilePath -Parent |
128 | 129 | $null = New-Item -Path $docsFolderPath -ItemType Directory -Force |
129 | 130 | Move-Item -Path $file.FullName -Destination $docsFilePath -Force |
130 | 131 | } |
131 | 132 |
|
132 | 133 | Write-Host '::group::Build docs - Fix frontmatter title' |
133 | | - Get-ChildItem -Path $moduleDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 134 | + Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
134 | 135 | $content = Get-Content -Path $_.FullName -Raw |
135 | 136 | # Replace 'title:' with 'ms.title:' in frontmatter only (between --- markers) |
136 | 137 | $content = $content -replace '(?s)^(---.*?)title:(.*?---)', '$1ms.title:$2' |
137 | 138 | $content | Set-Content -Path $_.FullName |
138 | 139 | } |
139 | 140 |
|
140 | | - Write-Host '::group::Build docs - Move markdown files from source files to docs' |
141 | | - $moduleDocsFolder = Join-Path $DocsOutputFolder.FullName $ModuleName |
| 141 | + Write-Host '::group::Build docs - Move markdown files from public functions folder to docs output folder' |
142 | 142 | Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
143 | 143 | $file = $_ |
144 | 144 | $relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName) |
145 | 145 | Write-Host " - $relPath" |
146 | 146 | Write-Host " Path: $file" |
147 | 147 |
|
148 | | - $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $moduleDocsFolder) |
| 148 | + $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $docsOutputFolder) |
149 | 149 | Write-Host " MD path: $docsFilePath" |
150 | 150 | $docsFolderPath = Split-Path -Path $docsFilePath -Parent |
151 | 151 | $null = New-Item -Path $docsFolderPath -ItemType Directory -Force |
152 | 152 | Move-Item -Path $file.FullName -Destination $docsFilePath -Force |
153 | 153 | } |
| 154 | + Write-Host '::endgroup::' |
154 | 155 |
|
155 | 156 | Write-Host '────────────────────────────────────────────────────────────────────────────────' |
156 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
157 | | - $fileName = $_.Name |
158 | | - Write-Host "::group:: - [$fileName]" |
| 157 | + Get-ChildItem -Path $docsOutputFolder -Recurse -Force -Include '*.md' | Sort-Object FullName | ForEach-Object { |
| 158 | + $relPath = [System.IO.Path]::GetRelativePath($docsOutputFolder, $_.FullName) |
| 159 | + Write-Host "::group:: - [$relPath]" |
159 | 160 | Show-FileContent -Path $_ |
160 | 161 | } |
161 | 162 | } |
0 commit comments