Skip to content
Permalink
Browse files

Added script to build help docs.

  • Loading branch information...
michaellwest committed Dec 28, 2018
1 parent 97f5d40 commit 5e626f69372aedb93c53e0d928218155fc6a7b28
@@ -0,0 +1,121 @@
---
ID: "cbdfcd46-655d-47dd-9589-d6073d6d07ef"
Parent: "01bb164c-5e8e-4c9b-941f-e5340bdd520c"
Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43"
Path: /sitecore/system/Modules/PowerShell/Script Library/SPE/Core/Platform/Development/PowerShell Extensions Maintenance/Generate Help Documentation
DB: master
SharedFields:
- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0"
Hint: Script
Value: |
$documentation = Join-Path -Path "$SitecoreDataFolder\temp" -ChildPath "documentation"
$summaryUrl = "https://github.com/SitecorePowerShell/Book/blob/master/SUMMARY.md"
$response = Invoke-WebRequest -UseBasicParsing -Uri $summaryUrl
$pages = $response.Links |
Where-Object { $_.href.StartsWith("/SitecorePowerShell/Book/blob/master/appendix/") } |
Where-Object { !$_.href.EndsWith("README.md") } |
ForEach-Object { "https://raw.githubusercontent.com$($_.href)".Replace("blob/","") }
function ConvertPage {
param(
[string]$Page
)
$markdown = Invoke-WebRequest -UseBasicParsing -Uri $Page | Select-Object -ExpandProperty Content
$r = $markdown
$options = [System.Text.RegularExpressions.RegexOptions]::Multiline
# h1 - h4 and hr
$r = [regex]::new("^#### (.*)=*", $options).Replace($r, "`$1")
$r = [regex]::new("^# (.*)=*", $options).Replace($r, ".SYNOPSIS`n`$1")
$r = [regex]::new("^## Detailed Description(.*)=*", $options).Replace($r, ".DESCRIPTION`n`$1")
$r = [regex]::new("^## Parameters(.*)=*", $options).Replace($r, "")
$r = [regex]::new("^## Notes(.*)=*", $options).Replace($r, ".NOTES")
$r = [regex]::new("^## Syntax(.*)=*", $options).Replace($r, ".SYNTAX")
$r = [regex]::new("^## Notes(.*)=*", $options).Replace($r, ".NOTES")
$r = [regex]::new("^## Examples(.*)=*", $options).Replace($r, "")
$r = [regex]::new("^## Related Topics(.*)=*", $options).Replace($r, ".LINK")
$r = [regex]::new("^## Inputs(.*)=*", $options).Replace($r, ".INPUTS")
$r = [regex]::new("^## Outputs(.*)=*", $options).Replace($r, ".OUTPUTS")
$r = [regex]::new("^### -(.*)=*", $options).Replace($r, ".PARAMETER `$1")
$r = [regex]::new("^### EXAMPLE [0-9]{0,2}(.*)=*", $options).Replace($r, ".EXAMPLE `$1")
#$r = [regex]::new("^[-*][-*][-*]+", $options).Replace($r, "<hr />")
# Replace links
$r = [regex]::new("\[https?.*\]\((https?.*)\)", $options).Replace($r, "`$1")
# Replace page references to just the command name
$r = [regex]::new("\[(?<name>.*)\]\(.*\)", $options).Replace($r, "`$1")
# Replace code sample format
$r = [regex]::new("[\r\n]``````text", $options).Replace($r, "")
$r = [regex]::new("[\r\n]``````", $options).Replace($r, "")
# Remove Aliases table
$r = [regex]::new("[\r\n](\|.*\|.*\|)", $options).Replace($r, "")
$r = $r.Replace("&lt;","<").Replace("&gt;",">")
$r = $r.Replace("\[","[").Replace("\]","]")
$r = $r.Replace("\_","_")
$r = $r.Replace("&copy;","(c)")
$r = $r.Replace("2010-2018","2010-$([datetime]::Today.Year)")
$r = $r.Replace("2010-2017","2010-$([datetime]::Today.Year)")
$r = [regex]::new("\.SYNTAX[\s\S]*(?=\.DESCRIPTION)", $options).Replace($r, "")
$linkSection = [regex]::new("\.LINK[\r\n]*([\*\s\w\W])*(?=\.[\w])", $options).Match($r).Value
$linkSection = [regex]::new("\.LINK[\r\n]*", $options).Replace($linkSection, "")
$linkSection = [regex]::new("^\*\s(.*)$", $options).Replace($linkSection, ".LINK`n`$1`n")
$r = [regex]::new("\.LINK[\r\n]*([\*\s\w\W])*(?=\.[\w])", $options).Replace($r, $linkSection)
$r
}
foreach($page in $pages) {
Write-Host "Processing $($page)"
$pageName = $page.Split("/")[-1].Replace(".md",".ps1")
$convertedPage = ConvertPage -Page $page
$content = "<#`n$($convertedPage)`n#>"
[System.IO.File]::WriteAllText("$($documentation)\$($pageName)",$content, [System.Text.Encoding]::UTF8)
}
$config = [Sitecore.Configuration.Factory]::GetConfiguration()
$speSourceFolder = $config.sitecore."sc.variable" |
Where-Object { $_.Name -eq "speSourceFolder" } |
Select-Object -First 1 -Expand value
$repo = Split-Path $speSourceFolder -Parent
$help = Join-Path -Path $speSourceFolder -ChildPath "sitecore modules\PowerShell\Assets"
$moduleLibraryPath = (Join-Path -Path $AppPath -ChildPath "bin\Cognifide.PowerShell.dll")
if(!(Test-Path -Path $moduleLibraryPath)) {
Write-Error "Module Library Path not found"
}
$helpLibraryPath = (Join-Path -Path $repo -ChildPath "Libraries\PowerShell.MamlGenerator.dll")
if(!(Test-Path -Path $helpLibraryPath)) {
Write-Error "Help Library Path not found"
}
if(-not(Test-Path -Path $documentation)) {
Write-Error "The documenation directory is empty"
}
$files = [System.IO.Directory]::GetFiles($documentation, "*.ps1")
Add-Type -Path $helpLibraryPath
[PowerShell.MamlGenerator.CmdletHelpGenerator]::GenerateHelp($moduleLibraryPath, $help, $files)
Remove-Item "$help/*.maml" -Force
Get-Item "$help/*.xml" | Rename-Item -NewName { $_.name -replace '\.xml','.maml' }
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20181228T032249Z
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f"
Hint: __Created by
Value: |
sitecore\Admin

0 comments on commit 5e626f6

Please sign in to comment.
You can’t perform that action at this time.