Public/Get-PCNextVersion.ps1

<#
.SYNOPSIS
    Calculates the next semantic version.
.DESCRIPTION
    Determines the next version number based on the current version
    and the increment type (Major, Minor, or Patch).
.PARAMETER IncrementType
    Type of version increment: Major, Minor, or Patch.
.PARAMETER Path
    Project directory. Defaults to current directory.
.PARAMETER CurrentVersion
    Override auto-detection by specifying the current version string.
.EXAMPLE
    Get-PCNextVersion -IncrementType Patch
    # If current is 1.2.3, returns "1.2.4"
.EXAMPLE
    Get-PCNextVersion -IncrementType Minor -CurrentVersion "v2.1.0"
    # Returns "2.2.0"
.OUTPUTS
    [string] The next version (without 'v' prefix).
#>

function Get-PCNextVersion {
    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter(Mandatory)]
        [ValidateSet('Major', 'Minor', 'Patch')]
        [string]$IncrementType,

        [Parameter()]
        [string]$Path = (Get-Location).Path,

        [Parameter()]
        [string]$CurrentVersion
    )

    if (-not $CurrentVersion) {
        $versionInfo = Get-PCProjectVersion -Path $Path
        $CurrentVersion = $versionInfo.Version
    }

    Write-Verbose "Calculating next $IncrementType version from: $CurrentVersion"

    $version = Get-SemanticVersion -Version $CurrentVersion

    $newMajor = $version.Major
    $newMinor = $version.Minor
    $newPatch = $version.Patch

    switch ($IncrementType) {
        'Major' {
            $newMajor++
            $newMinor = 0
            $newPatch = 0
        }
        'Minor' {
            $newMinor++
            $newPatch = 0
        }
        'Patch' {
            $newPatch++
        }
    }

    $nextVersion = "$newMajor.$newMinor.$newPatch"
    Write-Verbose "Next version: $nextVersion"

    return $nextVersion
}