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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
<#
.SYNOPSIS Returns a version number. .DESCRIPTION This cmdlet creates a version number from the specified input. The input can be a '.json' file or an object. .PARAMETER InputObject The file-path or instance of a [Manifest] object. .PARAMETER CurrentBrach The branch name of the current repository. #> function ConvertTo-NcrementVersionNumber { Param( [ValidateNotNull()] [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")) { if ($manifest.branchSuffixMap | Get-Member $CurrentBranch) { $suffix = $manifest.branchSuffixMap.$CurrentBranch; } elseif ($manifest.branchSuffixMap | Get-Member "*") { $suffix = $manifest.branchSuffixMap."*"; } } $tag = ""; if (-not [string]::IsNullOrEmpty($suffix)) { $tag = "-$suffix"; } return [PSCustomObject]@{ "Suffix"=$suffix; "Version"="$($manifest.version.major).$($manifest.version.minor).$($manifest.version.patch)"; "FullVersion"="$($manifest.version.major).$($manifest.version.minor).$($manifest.version.patch)$tag"; }; } else { Write-Error "The 'InputObject' cannot be null or empty."; } } } |