-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-docs.ps1
64 lines (57 loc) · 2.14 KB
/
update-docs.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
56
57
58
59
60
61
62
63
64
param (
[string] $class,
[string] $scope
)
$sourceFile = ".\docs\_data\$($class.ToLower()).json"
$destinationFile = ".\docs\_docs\$($scope.ToLower())-$($class.ToLower())s.md"
########### Create a markdown table ##########
Write-Host "Creating new version of $destinationFile based on $sourceFile ..."
$elapsed = Measure-Command -Expression {
$members = Get-Content -Path $sourceFile | ConvertFrom-Json
$members = $members | where {$_.Scope -ieq $scope} | Sort-Object Name
Write-Host "`t$($members.Count) $($class.ToLower())s found within scope $scope"
$text=""
$keywords=@()
ForEach($member in $members) {
$keywords += $member.Name
$doc += "##### $($member.Name)`r`n"
$doc += "###### Overview`r`n`r`n$($member.Summary)`r`n"
if($member.Parameters.Length -gt 0) {
$doc += "`r`n###### Parameter"
if($member.Parameters.Length -gt 1) {
$doc += "s"
}
$doc += "`r`n"
foreach ($parameter in $member.Parameters) {
$doc += "* $($parameter.Name)"
if($parameter.Optional) {
$doc += " (optional) "
}
$doc += ": $($parameter.Summary)`r`n"
}
}
$doc += "`r`n"
}
########### Update the sub-part of the docs file ##########
Write-Host "`tReplacing content in $destinationFile ..."
$text = ""
[bool] $skip = $false
ForEach ($line in Get-Content -Path $destinationFile) {
if($line -eq "<!-- END AUTO-GENERATED -->") {
$skip = $false
}
if (-not $skip) {
if ($line.EndsWith("# AUTO-GENERATED KEYWORDS")) {
$text += "keywords: [$($keywords -join ', ')] # AUTO-GENERATED KEYWORDS`r`n"
} else {
$text += $line + "`r`n"
}
}
if ($line -eq "<!-- START AUTO-GENERATED -->"){
$skip = $true
$text += $doc
}
}
$text | Out-File -FilePath $destinationFile -NoNewline -Encoding ascii
}
Write-Host "New version of $destinationFile created in $($elapsed.TotalSeconds) seconds"