-
Notifications
You must be signed in to change notification settings - Fork 5
/
Generate-ScriptMarkdownHelp.ps1
55 lines (53 loc) · 2.37 KB
/
Generate-ScriptMarkdownHelp.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
function Generate-ScriptMarkdownHelp{
<#
.SYNOPSIS
The function that generated the Markdown help in this repository. (see Example for usage).
Generates markdown help for each function containing comment based help in the module (Description not empty) within a folder recursively and a summary table for the main README.md
.DESCRIPTION
platyPS is used to generate the function level help + the README.md is generated "manually".
.PARAMETER Module
Name of the Module to generate help for.
.PARAMETER RepoUrl
Url for the Git repository homepage
.EXAMPLE
Generate-ScriptMarkdownHelp -Module SearchLucene -RepoUrl https://github.com/DBremen/SearchLucene
#>
[CmdletBinding()]
Param($Module,$RepoUrl)
$summaryTable = @'
# SearchLucene
Full text search using PowerShell, Everything, and Lucene.
See [link to my blog post](https://powershellone.wordpress.com/2016/05/26/full-text-search-using-powershell-everything-and-lucene/) for more details.
| Function | Synopsis | Documentation |
| --- | --- | --- |
'@
Import-Module platyps
$htCheck = @{}
Import-Module $Module
$functions = Get-Command -Module $Module
foreach ($function in $functions){
try{
$help =Get-Help $function.Name | Where-Object {$_.Name -eq $function.Name} -ErrorAction Stop
}catch{
continue
}
if ($help.description -ne $null){
$htCheck[$function.Name] += 1
$link = $help.relatedLinks
if ($link){
$link = $link.navigationLink.uri | Where-Object {$_ -like '*powershellone*'}
}
$mdFile = $function.Name + '.md'
$summaryTable += "`n| $($function.Name) | $($help.Synopsis) | $("[Link]($($RepoUrl)/blob/master/docs/$mdFile)") |"
}
}
$docFolder = "$(Split-Path (Get-Module $Module)[0].Path)\docs"
$summaryTable | Set-Content "$(Split-Path $docFolder -Parent)/README.md" -Force
$documenation = New-MarkdownHelp -Module $Module -OutputFolder $docFolder -Force
foreach ($file in (dir $docFolder)){
$text = (Get-Content -Path $file.FullName | Select-Object -Skip 6) | Set-Content $file.FullName -Force
}
#sanity check if help file were generated for each script
[PSCustomObject]$htCheck
}
Generate-ScriptMarkdownHelp SearchLucene -RepoUrl https://github.com/DBremen/SearchLucene