summaryrefslogtreecommitdiff
path: root/update-docs.ps1
blob: ada3e6b1a4e1c0ff4c93435c1a7ea2c724cb647d (plain)
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
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"
)

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 ParseChanges
{
    param
    ( 
        [string]$dllPath, 
        [string]$docsPath,
        [string[]]$changes
    )

    $suggestedCommands = @()

    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.Replace("\", "/"))/$(ClassToXMLPath($matches[1]))"
                Write-Host "$modified was modified"
                $suggestedCommands += "git add $modified"
            }

        } 

        if($changes[$n] -match "^New Type: (.*)"){
            $modified = "$($docsPath.Replace("\", "/"))/$(ClassToXMLPath($matches[1]))"
            Write-Host "$modified was added"
            $suggestedCommands += "git add $modified"
        }

        $n = $n + 1
    }

    if($suggestedCommands.Length -gt 0) {
        Write-Host "Suggested git commands:"
        $suggestedCommands | % { Write-Host $_ }
    } else {
        Write-Host "No actual docs changes were made."
    }
}

function ClassToXMLPath
{
    param( [string]$class )
    $lastDot = $class.LastIndexOf(".")
    return $class.Substring(0, $lastDot) + "/" + $class.Substring($lastDot + 1, $class.Length - $lastDot - 1) + ".xml"
}

# Core
$dllPath = "Xamarin.Forms.Core\bin\Debug\Xamarin.Forms.Core.dll"
$docsPath = "docs\Xamarin.Forms.Core"
$changes = Update $dllPath $docsPath
ParseChanges $dllPath $docsPath $changes

Write-Host

# Xaml
$dllPath = "Xamarin.Forms.Xaml\bin\Debug\Xamarin.Forms.Xaml.dll"
$docsPath = "docs\Xamarin.Forms.Xaml"
$changes = Update $dllPath $docsPath
ParseChanges $dllPath $docsPath $changes

Write-Host

# Maps
$dllPath = "Xamarin.Forms.Maps\bin\Debug\Xamarin.Forms.Maps.dll"
$docsPath = "docs\Xamarin.Forms.Maps"
$changes = Update $dllPath $docsPath
ParseChanges $dllPath $docsPath $changes