|
7 | 7 | Builds a module. |
8 | 8 | #> |
9 | 9 | [CmdletBinding()] |
10 | | - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
11 | | - 'PSReviewUnusedParameter', '', Scope = 'Function', |
12 | | - Justification = 'LogGroup - Scoping affects the variables line of sight.' |
13 | | - )] |
14 | 10 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
15 | 11 | 'PSAvoidUsingWriteHost', '', Scope = 'Function', |
16 | 12 | Justification = 'Want to just write to the console, not the pipeline.' |
17 | 13 | )] |
18 | | - #Requires -Modules GitHub |
19 | | - #Requires -Modules Utilities |
20 | 14 | param( |
21 | 15 | # Name of the module. |
22 | 16 | [Parameter(Mandatory)] |
|
35 | 29 | [string] $DocsOutputFolderPath |
36 | 30 | ) |
37 | 31 |
|
38 | | - LogGroup "Documenting module [$ModuleName]" { |
39 | | - Write-Host "Source path: [$ModuleSourceFolderPath]" |
40 | | - if (-not (Test-Path -Path $ModuleSourceFolderPath)) { |
41 | | - Write-Error "Source folder not found at [$ModuleSourceFolderPath]" |
42 | | - exit 1 |
43 | | - } |
44 | | - $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath |
45 | | - Write-Host "Module source folder: [$moduleSourceFolder]" |
| 32 | + Write-Host "::group::Documenting module [$ModuleName]" |
| 33 | + Write-Host "Source path: [$ModuleSourceFolderPath]" |
| 34 | + if (-not (Test-Path -Path $ModuleSourceFolderPath)) { |
| 35 | + Write-Error "Source folder not found at [$ModuleSourceFolderPath]" |
| 36 | + exit 1 |
| 37 | + } |
| 38 | + $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath |
| 39 | + Write-Host "Module source folder: [$moduleSourceFolder]" |
46 | 40 |
|
47 | | - $moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force |
48 | | - Write-Host "Module output folder: [$moduleOutputFolder]" |
| 41 | + $moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force |
| 42 | + Write-Host "Module output folder: [$moduleOutputFolder]" |
49 | 43 |
|
50 | | - $docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force |
51 | | - Write-Host "Docs output folder: [$docsOutputFolder]" |
52 | | - } |
| 44 | + $docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force |
| 45 | + Write-Host "Docs output folder: [$docsOutputFolder]" |
53 | 46 |
|
54 | | - LogGroup 'Build docs - Generate markdown help' { |
55 | | - Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) |
56 | | - Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName |
57 | | - Write-Host ($ModuleName | Get-Module) |
58 | | - $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose |
59 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
60 | | - $fileName = $_.Name |
61 | | - LogGroup " - [$fileName]" { |
62 | | - Show-FileContent -Path $_ |
63 | | - } |
64 | | - } |
| 47 | + Write-Host '::group::Build docs - Generate markdown help' |
| 48 | + Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) |
| 49 | + Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName |
| 50 | + Write-Host ($ModuleName | Get-Module) |
| 51 | + $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose |
| 52 | + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 53 | + $fileName = $_.Name |
| 54 | + Write-Host "::group:: - [$fileName]" |
| 55 | + Show-FileContent -Path $_ |
65 | 56 | } |
66 | 57 |
|
67 | | - LogGroup 'Build docs - Fix markdown code blocks' { |
68 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
69 | | - $content = Get-Content -Path $_.FullName |
70 | | - $fixedOpening = $false |
71 | | - $newContent = @() |
72 | | - foreach ($line in $content) { |
73 | | - if ($line -match '^```$' -and -not $fixedOpening) { |
74 | | - $line = $line -replace '^```$', '```powershell' |
75 | | - $fixedOpening = $true |
76 | | - } elseif ($line -match '^```.+$') { |
77 | | - $fixedOpening = $true |
78 | | - } elseif ($line -match '^```$') { |
79 | | - $fixedOpening = $false |
80 | | - } |
81 | | - $newContent += $line |
| 58 | + Write-Host '::group::Build docs - Fix markdown code blocks' |
| 59 | + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 60 | + $content = Get-Content -Path $_.FullName |
| 61 | + $fixedOpening = $false |
| 62 | + $newContent = @() |
| 63 | + foreach ($line in $content) { |
| 64 | + if ($line -match '^```$' -and -not $fixedOpening) { |
| 65 | + $line = $line -replace '^```$', '```powershell' |
| 66 | + $fixedOpening = $true |
| 67 | + } elseif ($line -match '^```.+$') { |
| 68 | + $fixedOpening = $true |
| 69 | + } elseif ($line -match '^```$') { |
| 70 | + $fixedOpening = $false |
82 | 71 | } |
83 | | - $newContent | Set-Content -Path $_.FullName |
| 72 | + $newContent += $line |
84 | 73 | } |
| 74 | + $newContent | Set-Content -Path $_.FullName |
85 | 75 | } |
86 | 76 |
|
87 | | - LogGroup 'Build docs - Fix markdown escape characters' { |
88 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
89 | | - $content = Get-Content -Path $_.FullName -Raw |
90 | | - $content = $content -replace '\\`', '`' |
91 | | - $content = $content -replace '\\\[', '[' |
92 | | - $content = $content -replace '\\\]', ']' |
93 | | - $content = $content -replace '\\\<', '<' |
94 | | - $content = $content -replace '\\\>', '>' |
95 | | - $content = $content -replace '\\\\', '\' |
96 | | - $content | Set-Content -Path $_.FullName |
97 | | - } |
| 77 | + Write-Host '::group::Build docs - Fix markdown escape characters' |
| 78 | + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 79 | + $content = Get-Content -Path $_.FullName -Raw |
| 80 | + $content = $content -replace '\\`', '`' |
| 81 | + $content = $content -replace '\\\[', '[' |
| 82 | + $content = $content -replace '\\\]', ']' |
| 83 | + $content = $content -replace '\\\<', '<' |
| 84 | + $content = $content -replace '\\\>', '>' |
| 85 | + $content = $content -replace '\\\\', '\' |
| 86 | + $content | Set-Content -Path $_.FullName |
98 | 87 | } |
99 | 88 |
|
100 | | - LogGroup 'Build docs - Structure markdown files to match source files' { |
101 | | - $PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item |
102 | | - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
103 | | - $file = $_ |
104 | | - Write-Host "Processing: $file" |
| 89 | + Write-Host '::group::Build docs - Structure markdown files to match source files' |
| 90 | + $PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item |
| 91 | + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 92 | + $file = $_ |
| 93 | + Write-Host "Processing: $file" |
105 | 94 |
|
106 | | - # find the source code file that matches the markdown file |
107 | | - $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } |
108 | | - Write-Host "Found script path: $scriptPath" |
109 | | - $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') |
110 | | - Write-Host "Doc file path: $docsFilePath" |
111 | | - $docsFolderPath = Split-Path -Path $docsFilePath -Parent |
112 | | - New-Item -Path $docsFolderPath -ItemType Directory -Force |
113 | | - Move-Item -Path $file.FullName -Destination $docsFilePath -Force |
114 | | - } |
115 | | - # Get the MD files that are in the public functions folder and move them to the same place in the docs folder |
116 | | - Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
117 | | - $file = $_ |
118 | | - Write-Host "Processing: $file" |
119 | | - $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) |
120 | | - Write-Host "Doc file path: $docsFilePath" |
121 | | - $docsFolderPath = Split-Path -Path $docsFilePath -Parent |
122 | | - New-Item -Path $docsFolderPath -ItemType Directory -Force |
123 | | - Move-Item -Path $file.FullName -Destination $docsFilePath -Force |
124 | | - } |
| 95 | + # find the source code file that matches the markdown file |
| 96 | + $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } |
| 97 | + Write-Host "Found script path: $scriptPath" |
| 98 | + $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') |
| 99 | + Write-Host "Doc file path: $docsFilePath" |
| 100 | + $docsFolderPath = Split-Path -Path $docsFilePath -Parent |
| 101 | + New-Item -Path $docsFolderPath -ItemType Directory -Force |
| 102 | + Move-Item -Path $file.FullName -Destination $docsFilePath -Force |
| 103 | + } |
| 104 | + # Get the MD files that are in the public functions folder and move them to the same place in the docs folder |
| 105 | + Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
| 106 | + $file = $_ |
| 107 | + Write-Host "Processing: $file" |
| 108 | + $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) |
| 109 | + Write-Host "Doc file path: $docsFilePath" |
| 110 | + $docsFolderPath = Split-Path -Path $docsFilePath -Parent |
| 111 | + New-Item -Path $docsFolderPath -ItemType Directory -Force |
| 112 | + Move-Item -Path $file.FullName -Destination $docsFilePath -Force |
125 | 113 | } |
126 | 114 |
|
127 | 115 | Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { |
128 | 116 | $fileName = $_.Name |
129 | 117 | $hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash |
130 | | - LogGroup " - [$fileName] - [$hash]" { |
131 | | - Show-FileContent -Path $_ |
132 | | - } |
| 118 | + Write-Host "::group:: - [$fileName] - [$hash]" |
| 119 | + Show-FileContent -Path $_ |
133 | 120 | } |
134 | 121 | } |
0 commit comments