summaryrefslogtreecommitdiff
path: root/update-docs.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'update-docs.ps1')
-rw-r--r--update-docs.ps1116
1 files changed, 93 insertions, 23 deletions
diff --git a/update-docs.ps1 b/update-docs.ps1
index ada3e6b1..6f3b84e9 100644
--- a/update-docs.ps1
+++ b/update-docs.ps1
@@ -2,7 +2,9 @@
[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"
+ [String]$ProfilePath = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259",
+ [Parameter(Position = 2)]
+ [switch]$FailOnChanges
)
function Update
@@ -21,7 +23,7 @@ function Update
}
}
-function ParseChanges
+function ReportChanges
{
param
(
@@ -30,52 +32,103 @@ function ParseChanges
[string[]]$changes
)
- $suggestedCommands = @()
+ $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+1] -match "Member Added:" -or $changes[$n+1] -match "Member Removed:") {
- if($changes[$n] -match "^Updating: (.*)"){
- $modified = "$($docsPath.Replace("\", "/"))/$(ClassToXMLPath($matches[1]))"
+ if($changes[$n] -match "^Updating: (.*)") {
+ $modified = "$($docsPath)/$(ClassToXMLPath $matches[1])"
Write-Host "$modified was modified"
- $suggestedCommands += "git add $modified"
}
-
}
- if($changes[$n] -match "^New Type: (.*)"){
- $modified = "$($docsPath.Replace("\", "/"))/$(ClassToXMLPath($matches[1]))"
+ if($changes[$n] -match "^New Type: (.*)") {
+ $modified = "$($docsPath)/$(ClassToXMLPath $matches[1])"
Write-Host "$modified was added"
- $suggestedCommands += "git add $modified"
}
- $n = $n + 1
- }
+ if($changes[$n] -match "^Class no longer present; file renamed: (.*)") {
+ $modified = $matches[1].Replace(".remove", "")
+ Write-Host "$modified was removed"
+ }
- if($suggestedCommands.Length -gt 0) {
- Write-Host "Suggested git commands:"
- $suggestedCommands | % { Write-Host $_ }
- } else {
- Write-Host "No actual docs changes were made."
+ $n = $n + 1
}
}
function ClassToXMLPath
{
- param( [string]$class )
+ param([string]$class)
+
$lastDot = $class.LastIndexOf(".")
- return $class.Substring(0, $lastDot) + "/" + $class.Substring($lastDot + 1, $class.Length - $lastDot - 1) + ".xml"
+ $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
-ParseChanges $dllPath $docsPath $changes
+$changes = ($changes | % { $_.Replace("/", "+") }) # Fix-up for nested types
+ReportChanges $dllPath $docsPath $changes
+FixLineEndings $changes $docsPath
+if(-not $failed){
+ $failed = CheckForFailure $docsPath
+}
Write-Host
@@ -83,7 +136,12 @@ Write-Host
$dllPath = "Xamarin.Forms.Xaml\bin\Debug\Xamarin.Forms.Xaml.dll"
$docsPath = "docs\Xamarin.Forms.Xaml"
$changes = Update $dllPath $docsPath
-ParseChanges $dllPath $docsPath $changes
+$changes = ($changes | % { $_.Replace("/", "+") }) # Fix-up for nested types
+ReportChanges $dllPath $docsPath $changes
+FixLineEndings $changes $docsPath
+if(-not $failed){
+ $failed = CheckForFailure $docsPath
+}
Write-Host
@@ -91,4 +149,16 @@ Write-Host
$dllPath = "Xamarin.Forms.Maps\bin\Debug\Xamarin.Forms.Maps.dll"
$docsPath = "docs\Xamarin.Forms.Maps"
$changes = Update $dllPath $docsPath
-ParseChanges $dllPath $docsPath $changes \ No newline at end of file
+$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
+}