From 220c33ed978bb2729f663633269ef4289286d260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BE=D1=81=D0=BE=D0=B2?= Date: Fri, 6 Dec 2024 19:41:10 +0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug=20when=20js=20version?= =?UTF-8?q?=20start=20with=20'v'.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TUI.Engine/Extensions.cs | 7 ++++++- src/TUI/Domain/Version.cs | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/TUI.Engine/Extensions.cs b/src/TUI.Engine/Extensions.cs index 3f7ed4f..6b1c864 100644 --- a/src/TUI.Engine/Extensions.cs +++ b/src/TUI.Engine/Extensions.cs @@ -40,9 +40,14 @@ public static class Extensions return stringInfo.LengthInTextElements; } + public static string RemoveVersionPrefix(this string version) + { + return version.Replace("^", "").Replace("v", "").Replace("~", ""); + } + public static Version ToVersion(this string textVersion) { - var version = textVersion.Replace("^", "").Replace("v", "").Replace("~", "").Split("."); + var version = textVersion.RemoveVersionPrefix().Split("."); var major = Convert.ToInt32(version[0]); var minor = Convert.ToInt32(version[1]); var patch = Convert.ToInt32(version[2].Split('-')[0]); diff --git a/src/TUI/Domain/Version.cs b/src/TUI/Domain/Version.cs index ed61736..1ebb405 100644 --- a/src/TUI/Domain/Version.cs +++ b/src/TUI/Domain/Version.cs @@ -1,4 +1,5 @@ using TUI.Controls.Components; +using TUI.Engine; namespace TUI.Domain; @@ -8,17 +9,17 @@ public class Version public readonly int Minor; public readonly int Patch; public readonly VersionType Type; - + public Version(string version) { var parts = version.Split('.'); - - Major = Convert.ToInt32(parts[0].Replace("^", "").Replace("~", "")); + + Major = Convert.ToInt32(parts[0].RemoveVersionPrefix()); Minor = Convert.ToInt32(parts[1]); Patch = Convert.ToInt32(string.Join("", parts[2].TakeWhile(char.IsDigit))); - + var extension = parts[2].Replace(Patch.ToString(), ""); - + Type = extension switch { not null when extension.Contains("rc") => VersionType.Candidate,