From 96d4df9647d432b0e7d0dfebffc769e0e32360ba Mon Sep 17 00:00:00 2001 From: Michael Flanakin Date: Wed, 13 Dec 2023 01:15:31 -0800 Subject: [PATCH] Add -AsDotNetVersion option to the Get-Version script --- src/scripts/Get-Version.ps1 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/scripts/Get-Version.ps1 b/src/scripts/Get-Version.ps1 index aee59ee3a..44c85a6fa 100644 --- a/src/scripts/Get-Version.ps1 +++ b/src/scripts/Get-Version.ps1 @@ -18,7 +18,21 @@ Gets the current version number. #> -return (Get-Content (Join-Path $PSScriptRoot ../../package.json) | ConvertFrom-Json).version ` +param( + [switch] + $AsDotNetVersion +) + +$ver = (Get-Content (Join-Path $PSScriptRoot ../../package.json) | ConvertFrom-Json).version ` -replace '^[^\d]*((\d+\.\d+)(\.\d+)?(-[a-z]+)?(\.\d+)?)[^\d]*$', '$1' ` -replace '^(\d+\.\d+)(\.\d+)?(-[a-z]+)?(\.0)?$', '$1$2$3' ` -replace '^(\d+\.\d+)(\.0)?(-[a-z]+)?(\.\d+)?$', '$1$3$4' + +if ($AsDotNetVersion -and $ver.Contains('-')) +{ + $arr = (($ver -replace '-[^\.0-9]+', '') -split '\.') + @(0, 0) + $arr[3] += 1000000000 + return $arr[0..3] -Join '.' +} + +return $ver