-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Generate-Documentation.ps1
37 lines (32 loc) · 1.3 KB
/
Generate-Documentation.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
Write-Output $PSScriptRoot
$RootFolder = "$PSScriptRoot\PSGuacamole"
$Folders = Get-ChildItem -Path "$RootFolder\Public"
foreach ($Folder in $Folders)
{
$TableContent = ""
$Content = ""
$DocumentationFile = "$PSScriptRoot\Documentation\$Folder.md"
Remove-Item -Path $DocumentationFile
$Title = "# $Folder `n"
$Functions = Get-ChildItem -Path $Folder.FullName
foreach ($Function in $Functions)
{
$FunctionName = ($Function.Name).Replace(".ps1","")
$TableContent += " - [$FunctionName](#"+$FunctionName.toLower()+")`n"
$Path = $Function.FullName
$TheStart = (Select-String -Path $Path -Pattern '<#').lineNumber
$TheEnd = (Select-String -Path $Path -Pattern '#>').lineNumber
Write-Warning "Processing $FunctionName $Path"
$Example = [string]::Join("`r`n",(Get-Content -Path $Path)[$TheStart..($TheEnd - 2)])
$Content += "## $FunctionName"
$Example = $Example.Replace("#","")
$Example = '
```Powershell
'+$Example+'
```'
$Content += $Example + "`n"
}
Add-Content -Path $DocumentationFile -Value $Title
Add-Content -Path $DocumentationFile -Value $TableContent
Add-Content -Path $DocumentationFile -Value $Content
}