Public/ConvertTo-NcrementVersionNumber.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
function ConvertTo-NcrementVersionNumber
{
    Param(
        [Parameter(Mandatory, ValueFromPipeline)]
        $InputObject,

        [string]$CurrentBranch = "*"
    )
    PROCESS
    {
        $manifest = $InputObject;
        $path = ConvertTo-Path $InputObject;
        if ((-not [string]::IsNullOrEmpty($path)) -and (Test-Path $path -PathType Leaf))
        {
            $manifest = Get-Content $path | ConvertFrom-Json;
        }

        if ($manifest -ne $null)
        {
            [string]$suffix = "";
            if (($manifest | Get-Member "branchSuffixMap") -and ($manifest.branchSuffixMap | Get-Member $CurrentBranch))
            {
                $suffix = $manifest.branchSuffixMap.$CurrentBranch;
            }

            return [PSCustomObject]@{
                "Suffix"=$suffix;
                "Version"="$($manifest.version.major).$($manifest.version.minor).$($manifest.version.patch)";
                "FullVersion"="$($manifest.version.major).$($manifest.version.minor).$($manifest.version.patch)$suffix";
            };
        }
        else { Write-Error "The 'InputObject' cannot be null or empty."; }
    }
}