forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-docs.ps1
164 lines (133 loc) · 4.13 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
param(
[Parameter(Position = 0)]
[String]$MdocPath = ".\tools\mdoc\mdoc.exe",
[Parameter(Position = 1)]
[String]$ProfilePath = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259",
[Parameter(Position = 2)]
[switch]$FailOnChanges
)
function Update
{
param
(
[string]$dllPath,
[string]$docsPath
)
Write-Host "Updating docs for $dllPath ..."
if(Test-Path $dllPath) {
& $MdocPath update --delete $dllPath -L $ProfilePath --out $docsPath
} else {
Write-Warning "$dllPath was not found; you may need to rebuild"
}
}
function ReportChanges
{
param
(
[string]$dllPath,
[string]$docsPath,
[string[]]$changes
)
$docsPath = $docsPath.Replace("\", "/")
if($changes.Length -eq 0){
return
}
$changes | % {$n=0} {
if($changes[$n+1] -match "Member Added:" -or $changes[$n+1] -match "Member Removed:") {
if($changes[$n] -match "^Updating: (.*)") {
$modified = "$($docsPath)/$(ClassToXMLPath $matches[1])"
Write-Host "$modified was modified"
}
}
if($changes[$n] -match "^New Type: (.*)") {
$modified = "$($docsPath)/$(ClassToXMLPath $matches[1])"
Write-Host "$modified was added"
}
if($changes[$n] -match "^Class no longer present; file renamed: (.*)") {
$modified = $matches[1].Replace(".remove", "")
Write-Host "$modified was removed"
}
$n = $n + 1
}
}
function ClassToXMLPath
{
param([string]$class)
$lastDot = $class.LastIndexOf(".")
$output = $class.Substring(0, $lastDot) + "/" + $class.Substring($lastDot + 1, $class.Length - $lastDot - 1) + ".xml"
# Unfortunate but necessary fix for IOpenGlViewController
# Because git is case sensitive but Windows isn't, and Windows has the filename
# set to IOpenGlViewController by default
$output = $output.Replace("IOpenGlViewController", "IOpenGLViewController")
return $output
}
# Resets the line endings changed by mdoc
# So we don't see a lot of 'modified docs' which really aren't changed
function FixLineEndings
{
param
(
[string[]]$changes,
[string]$docsPath
)
Write-Host "Resetting line endings modified by mdoc..."
$docsPath = $docsPath.Replace("\", "/")
$changes | % {
if($_ -match "^Updating: (.*)"){
$modified = "$($docsPath)/$(ClassToXMLPath $matches[1])"
(Get-Content $modified).Replace("`n", "`r`n") | Set-Content $modified
}
}
}
function CheckForFailure
{
param( [string]$docsPath )
if(-not $FailOnChanges){
return $false
}
$docsPath = $docsPath.Replace("\", "/")
$diffs = git diff $($docsPath) 2> $null
if($diffs){
return $true
}
return $false
}
$failed = $false
# Core
$dllPath = "Xamarin.Forms.Core\bin\Debug\Xamarin.Forms.Core.dll"
$docsPath = "docs\Xamarin.Forms.Core"
$changes = Update $dllPath $docsPath
$changes = ($changes | % { $_.Replace("/", "+") }) # Fix-up for nested types
ReportChanges $dllPath $docsPath $changes
FixLineEndings $changes $docsPath
if(-not $failed){
$failed = CheckForFailure $docsPath
}
Write-Host
# Xaml
$dllPath = "Xamarin.Forms.Xaml\bin\Debug\Xamarin.Forms.Xaml.dll"
$docsPath = "docs\Xamarin.Forms.Xaml"
$changes = Update $dllPath $docsPath
$changes = ($changes | % { $_.Replace("/", "+") }) # Fix-up for nested types
ReportChanges $dllPath $docsPath $changes
FixLineEndings $changes $docsPath
if(-not $failed){
$failed = CheckForFailure $docsPath
}
Write-Host
# Maps
$dllPath = "Xamarin.Forms.Maps\bin\Debug\Xamarin.Forms.Maps.dll"
$docsPath = "docs\Xamarin.Forms.Maps"
$changes = Update $dllPath $docsPath
$changes = ($changes | % { $_.Replace("/", "+") }) # Fix-up for nested types
ReportChanges $dllPath $docsPath $changes
FixLineEndings $changes $docsPath
if(-not $failed){
$failed = CheckForFailure $docsPath
}
if($failed){
Write-Warning "Not all of the documentation changes have been committed"
exit 1
} else {
exit 0
}