diff --git a/project.json b/project.json index c86c16d..b37e9c8 100644 --- a/project.json +++ b/project.json @@ -1,7 +1,7 @@ { "ProjectName": "ModuleTools", "Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.", - "Version": "1.1.0", + "Version": "1.1.3", "copyResourcesToModuleRoot": false, "Manifest": { "Author": "Manjunath Beli", diff --git a/src/private/Build.Manifest.ps1 b/src/private/Build.Manifest.ps1 index 0fa0cdc..956be1b 100644 --- a/src/private/Build.Manifest.ps1 +++ b/src/private/Build.Manifest.ps1 @@ -13,15 +13,19 @@ function Build-Manifest { } $ManfiestAllowedParams = (Get-Command New-ModuleManifest).Parameters.Keys - + $sv = [semver]$data.Version $ParmsManifest = @{ Path = $data.ManifestFilePSD1 Description = $data.Description FunctionsToExport = $functionToExport AliasesToExport = $aliasToExport RootModule = "$($data.ProjectName).psm1" - ModuleVersion = $data.Version + ModuleVersion = [version]$sv } + + if ($sv.PreReleaseLabel) { + $ParmsManifest['Prerelease'] = $sv.PreReleaseLabel + } # Accept only valid Manifest Parameters $data.Manifest.Keys | ForEach-Object { diff --git a/src/public/UpdateModVersion.ps1 b/src/public/UpdateModVersion.ps1 index 6920265..ade6e1b 100644 --- a/src/public/UpdateModVersion.ps1 +++ b/src/public/UpdateModVersion.ps1 @@ -1,14 +1,17 @@ <# .SYNOPSIS -Updates the version number of a module in project.json file. +Updates the version number of a module in project.json file. Uses [semver] object type. .DESCRIPTION -This script updates the version number of a PowerShell module by modifying the project.json file, which gets written into module manifest file (.psd1). -It increments the version number based on the specified version part (Major, Minor, Patch). +This script updates the version number of a PowerShell module by modifying the project.json file, which gets written into module manifest file (.psd1). [semver] is supported only powershell 7 and above. +It increments the version number based on the specified version part (Major, Minor, Patch). Can also attach preview/stable release to Release property of .PARAMETER Label The part of the version number to increment (Major, Minor, Patch). Default is patch. +.PARAMETER PreviewRelease +Use this to use semantic version and attach release name as 'preview' which is supported by PowerShell gallery, to remove it use stable release parameter + .EXAMPLE Update-MTModuleVersion -Label Major Updates the Major version part of the module. Version 2.1.3 will become 3.1.3 @@ -24,28 +27,33 @@ function Update-MTModuleVersion { [CmdletBinding(SupportsShouldProcess = $true)] param( [ValidateSet('Major', 'Minor', 'Patch')] - [string]$Label = 'Patch' + [string]$Label = 'Patch', + [switch]$PreviewRelease, + [switch]$StableRelease ) Write-Verbose 'Running Version Update' $data = Get-MTProjectInfo $jsonContent = Get-Content -Path $data.ProjecJSON | ConvertFrom-Json - $currentVersion = $jsonContent.Version - $versionComponents = $currentVersion.Split('.') + [semver]$CurrentVersion = $jsonContent.Version - # Increment the last component - switch ($Label) { - 'Major' { $versionComponents[0] = [int]$versionComponents[0] + 1 } - 'Minor' { $versionComponents[1] = [int]$versionComponents[1] + 1 } - 'Patch' { $versionComponents[2] = [int]$versionComponents[2] + 1 } + $Major = ($Label -eq 'Major') ? ($CurrentVersion.Major + 1) : $CurrentVersion.Major + $Minor = ($Label -eq 'Minor') ? ($CurrentVersion.Minor + 1) : $CurrentVersion.Minor + $Patch = ($Label -eq 'Patch') ? ($CurrentVersion.Patch + 1) : $CurrentVersion.Patch + + if ($PreviewRelease) { + $ReleaseType = 'preview' + } elseif ($StableRelease) { + $ReleaseType = $null + } else { + $ReleaseType = $CurrentVersion.PreReleaseLabel } - # Join the version components back into a string - $newVersion = $versionComponents -join '.' + $newVersion = [semver]::new($Major, $Minor, $Patch, $ReleaseType, $null) # Update the version in the JSON object - $jsonContent.Version = $newVersion + $jsonContent.Version = $newVersion.ToString() Write-Host "Version bumped to : $newVersion" # Convert the JSON object back to JSON format