Last active
November 2, 2018 21:28
-
-
Save Splaxi/ff7485a24f6ed9937f3e8da76b5d4840 to your computer and use it in GitHub Desktop.
Format comment based help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$moduleName = "d365fo.tools" | |
#$path = "C:\GIT\GITHUB\$moduleName.Workspace\$moduleName\$moduleName" | |
$path = "C:\GITHUB\LocalRepository\$moduleName" | |
function Get-Header ($text) { | |
$start = $text.IndexOf('<#') | |
$temp = $start - 2 | |
if($temp -gt 0) { | |
$text.SubString(0, $start - 2) | |
} | |
else { | |
"" | |
} | |
} | |
function Format-Help ($text) { | |
$start = $text.IndexOf('<#') | |
$end = $text.IndexOf('#>') | |
$help = $text.SubString($start + 2, $end - $start - 3) | |
$skipfirst = $null # to avoid trailing spaces | |
foreach ($newline in $help.Split("`n")) { | |
if (-not $skipfirst) { $skipfirst = $true; continue } | |
$trimmed = $newline.Trim() | |
foreach ($line in $trimmed) { | |
if ($line.StartsWith(".")) { | |
" $line" | |
} | |
else { | |
" $line" | |
} | |
} | |
} | |
} | |
function Get-Body ($text) { | |
$end = $text.IndexOf('#>') | |
$text.SubString($end, $text.Length - $end) | |
} | |
$files = New-Object System.Collections.ArrayList | |
$filesPublic = Get-ChildItem -Path "$path\functions\*.ps1" | |
$files.AddRange($filesPublic) | |
$filesInternal = Get-ChildItem -Path "$path\internal\functions\*.ps1" | |
$files.AddRange($filesInternal) | |
foreach ($file in $files) { | |
$text = ($file | Get-Content -Raw).Trim() | |
Set-Content -Path $file.FullName -Encoding UTF8 -Value (Get-Header $text).TrimEnd() | |
Add-Content -Path $file.FullName -Encoding UTF8 -Value "<#".Trim() | |
Add-Content -Path $file.FullName -Encoding UTF8 -Value (Format-Help $text) | |
Add-Content -Path $file.FullName -Encoding UTF8 -Value (Get-Body $text).TrimEnd() -NoNewline | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment