|
| 1 | +param |
| 2 | +( |
| 3 | + [Parameter()] |
| 4 | + [System.IO.DirectoryInfo] |
| 5 | + $ProjectPath = (property ProjectPath $BuildRoot), |
| 6 | + |
| 7 | + [Parameter()] |
| 8 | + [System.String] |
| 9 | + $ProjectName = (property ProjectName ''), |
| 10 | + |
| 11 | + [Parameter()] |
| 12 | + [System.String] |
| 13 | + $SourcePath = (property SourcePath ''), |
| 14 | + |
| 15 | + [Parameter()] |
| 16 | + [System.String] |
| 17 | + $HelpSourceFolder = (property HelpSourceFolder 'docs'), |
| 18 | + |
| 19 | + [Parameter()] |
| 20 | + [System.String] |
| 21 | + $OutputDirectory = (property OutputDirectory 'output'), |
| 22 | + |
| 23 | + [Parameter()] |
| 24 | + [System.String] |
| 25 | + $BuiltModuleSubdirectory = (property BuiltModuleSubdirectory ''), |
| 26 | + |
| 27 | + [Parameter()] |
| 28 | + [System.Management.Automation.SwitchParameter] |
| 29 | + $VersionedOutputDirectory = (property VersionedOutputDirectory $true), |
| 30 | + |
| 31 | + [Parameter()] |
| 32 | + [System.String] |
| 33 | + $HelpOutputFolder = (property HelpOutputFolder 'help'), |
| 34 | + |
| 35 | + [Parameter()] |
| 36 | + [cultureInfo] |
| 37 | + $HelpCultureInfo = 'en-US', |
| 38 | + |
| 39 | + [Parameter()] |
| 40 | + [System.Management.Automation.SwitchParameter] |
| 41 | + $CopyHelpMamlToBuiltModuleBase = (property CopyHelpMamlToBuiltModuleBase $true), |
| 42 | + |
| 43 | + # Build Configuration object |
| 44 | + [Parameter()] |
| 45 | + [System.Collections.Hashtable] |
| 46 | + $BuildInfo = (property BuildInfo @{ }) |
| 47 | +) |
| 48 | + |
| 49 | +function Get-GenerateHelpPSVariables |
| 50 | +{ |
| 51 | + param () |
| 52 | + |
| 53 | + $script:PesterOutputFolder = Get-SamplerAbsolutePath -Path $PesterOutputFolder -RelativeTo $OutputDirectory |
| 54 | + |
| 55 | + "`tPester Output Folder = '$PesterOutputFolder" |
| 56 | + |
| 57 | + $script:HelpSourceFolder = Get-SamplerAbsolutePath -Path $HelpSourceFolder -RelativeTo $ProjectPath |
| 58 | + "`tHelp Source Folder = '$HelpSourceFolder'" |
| 59 | + |
| 60 | + $script:HelpOutputFolder = Get-SamplerAbsolutePath -Path $HelpOutputFolder -RelativeTo $OutputDirectory |
| 61 | + "`tHelp output Folder = '$HelpOutputFolder'" |
| 62 | + |
| 63 | + if ($ModuleVersion) |
| 64 | + { |
| 65 | + $script:HelpOutputVersionFolder = Get-SamplerAbsolutePath -Path $ModuleVersion -RelativeTo $HelpOutputFolder |
| 66 | + } |
| 67 | + |
| 68 | + "`tHelp output Version Folder = '$HelpOutputVersionFolder'" |
| 69 | + |
| 70 | + $script:HelpOutputCultureFolder = Get-SamplerAbsolutePath -Path $HelpCultureInfo -RelativeTo $HelpOutputVersionFolder |
| 71 | + "`tHelp output Culture path = '$HelpOutputCultureFolder'" |
| 72 | + |
| 73 | + $script:DocOutputFolder = Get-SamplerAbsolutePath -Path 'docs' -RelativeTo $OutputDirectory |
| 74 | + "`tDocs output folder path = '$DocOutputFolder'" |
| 75 | +} |
| 76 | + |
| 77 | +# Synopsis: Produces markdown help files from the built module. |
| 78 | +task generate_docs { |
| 79 | + . Set-SamplerTaskVariable |
| 80 | + |
| 81 | + Get-GenerateHelpPSVariables |
| 82 | + |
| 83 | + $env:PSModulePath = $Env:PSModulePath |
| 84 | + #$targetModule = Import-Module -Name '$ProjectName' -ErrorAction Stop -PassThru |
| 85 | + $targetModule = Import-Module '.\output\module\FabricTools\0.0.1\FabricTools.psd1' -ErrorAction Stop -PassThru |
| 86 | + |
| 87 | + $helpDestination = Join-Path $HelpSourceFolder -ChildPath $HelpCultureInfo |
| 88 | + $currentCultureInfo = [System.Globalization.CultureInfo]::CurrentCulture.Name |
| 89 | + |
| 90 | + if (!(Test-Path -Path $helpDestination)) { |
| 91 | + New-Item -Path $helpDestination -ItemType Directory -Force -ErrorAction Ignore | Out-Null |
| 92 | + } |
| 93 | + |
| 94 | + $docOutputFolder = Join-Path $DocOutputFolder -ChildPath $ProjectName |
| 95 | + |
| 96 | + $commandsArray = @() |
| 97 | + foreach ($publicFunction in $targetModule.ExportedFunctions.Keys) { |
| 98 | + $command = Get-Command -Name $publicFunction -Module $targetModule |
| 99 | + |
| 100 | + $newMarkdownCommandHelpParams = @{ |
| 101 | + CommandInfo = $command |
| 102 | + OutputFolder = $DocOutputFolder |
| 103 | + HelpVersion = $targetModule.Version |
| 104 | + Locale = $HelpCultureInfo |
| 105 | + Encoding = "utf8" |
| 106 | + Force = $true |
| 107 | + } |
| 108 | + $Output = New-MarkdownCommandHelp @newMarkdownCommandHelpParams |
| 109 | + |
| 110 | + $helpCommand = Import-MarkdownCommandHelp -Path $Output -ErrorAction Ignore |
| 111 | + |
| 112 | + # Add the command to the array |
| 113 | + $commandsArray += $helpCommand |
| 114 | + |
| 115 | + $alias = Get-Alias -Definition $command.Name -ErrorAction Ignore |
| 116 | + |
| 117 | + if ($alias) { |
| 118 | + $helpCommand.Aliases = @($alias.Name) |
| 119 | + } else { |
| 120 | + $helpCommand.Aliases = @() |
| 121 | + } |
| 122 | + |
| 123 | + $helpCommand | Export-MarkdownCommandHelp -OutputFolder "$DocOutputFolder" -Force |
| 124 | + |
| 125 | + # Due to issue https://github.com/PowerShell/platyPS/issues/763 we need to manually replace the locale in the generated markdown file |
| 126 | + $oldString = "Locale: $currentCultureInfo" |
| 127 | + $newString = "Locale: $HelpCultureInfo" |
| 128 | + (Get-Content -Path "$Output") -replace $oldString, $newString | Set-Content -Path "$Output" -Encoding utf8 |
| 129 | + |
| 130 | + Copy-Item -Path $Output -Destination $helpDestination -Force |
| 131 | + } |
| 132 | + |
| 133 | + $newMarkdownModuleFileParams = @{ |
| 134 | + CommandHelp = $commandsArray |
| 135 | + OutputFolder = "$DocOutputFolder" |
| 136 | + Force = $true |
| 137 | + } |
| 138 | + $markdownFile = New-MarkdownModuleFile @newMarkdownModuleFileParams |
| 139 | + |
| 140 | + if ($markdownFile) { |
| 141 | + Copy-Item -Path $markdownFile -Destination $helpDestination -Force |
| 142 | + } |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +} |
0 commit comments