mirror of https://github.com/abpframework/abp.git
5 changed files with 84 additions and 20 deletions
@ -1,11 +0,0 @@ |
|||
namespace Volo.Docs.Utils |
|||
{ |
|||
public static class VersionHelper |
|||
{ |
|||
|
|||
public static bool IsPreRelease(string version) |
|||
{ |
|||
return (version?.Split("-").Length ?? 0) > 1; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Docs.Projects; |
|||
|
|||
namespace Volo.Docs.Version |
|||
{ |
|||
public interface IVersionHelper |
|||
{ |
|||
List<string> OrderByDescending(List<string> versions); |
|||
|
|||
List<VersionInfoDto> OrderByDescending(List<VersionInfoDto> versions); |
|||
|
|||
bool IsPreRelease(string version); |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using NuGet.Versioning; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Docs.Projects; |
|||
|
|||
namespace Volo.Docs.Version |
|||
{ |
|||
public class SemanticVersionHelper : IVersionHelper, ITransientDependency |
|||
{ |
|||
public List<string> OrderByDescending(List<string> versions) |
|||
{ |
|||
return versions.OrderByDescending(v=> SemanticVersion.Parse(NormalizeVersion(v)), new VersionComparer()).ToList(); |
|||
} |
|||
|
|||
public List<VersionInfoDto> OrderByDescending(List<VersionInfoDto> versions) |
|||
{ |
|||
return versions.OrderByDescending(v => SemanticVersion.Parse(NormalizeVersion(v.Name)), new VersionComparer()).ToList(); |
|||
} |
|||
|
|||
public bool IsPreRelease(string version) |
|||
{ |
|||
return SemanticVersion.Parse(NormalizeVersion(version)).IsPrerelease; |
|||
} |
|||
|
|||
private string NormalizeVersion(string version) |
|||
{ |
|||
version = version.RemovePreFix("v"); |
|||
|
|||
var normalizedVersion = ""; |
|||
|
|||
var versionParts = version.Split("-"); |
|||
|
|||
if (versionParts[0].Split(".").Length > 3) |
|||
{ |
|||
normalizedVersion = string.Join(".",versionParts[0].Split(".").Take(3)); |
|||
} |
|||
else |
|||
{ |
|||
normalizedVersion = versionParts[0]; |
|||
} |
|||
|
|||
if (versionParts.Length > 1) |
|||
{ |
|||
return normalizedVersion + "-" + string.Join("-", versionParts.Skip(1)); |
|||
} |
|||
|
|||
return normalizedVersion; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue