From 7b891c44b2005207af8218589a26483256ea8951 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 27 Aug 2020 14:24:10 +0300 Subject: [PATCH 1/3] Cli: Suite install & update improvements resolves https://github.com/volosoft/volo/issues/3140 --- .../Volo/Abp/Cli/Commands/SuiteCommand.cs | 97 +++++++++++++++++-- 1 file changed, 88 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs index fbe7fa675f..a0ae74cf9c 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs @@ -1,10 +1,13 @@ using System; +using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using NuGet.Versioning; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Commands.Services; +using Volo.Abp.Cli.NuGet; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; @@ -13,12 +16,14 @@ namespace Volo.Abp.Cli.Commands public class SuiteCommand : IConsoleCommand, ITransientDependency { private readonly AbpNuGetIndexUrlService _nuGetIndexUrlService; + private readonly NuGetService _nuGetService; private const string SuitePackageName = "Volo.Abp.Suite"; public ILogger Logger { get; set; } - public SuiteCommand(AbpNuGetIndexUrlService nuGetIndexUrlService) + public SuiteCommand(AbpNuGetIndexUrlService nuGetIndexUrlService, NuGetService nuGetService) { _nuGetIndexUrlService = nuGetIndexUrlService; + _nuGetService = nuGetService; Logger = NullLogger.Instance; } @@ -26,21 +31,22 @@ namespace Volo.Abp.Cli.Commands { var operationType = NamespaceHelper.NormalizeNamespace(commandLineArgs.Target); + var preview = commandLineArgs.Options.ContainsKey(Options.Preview.Long); + switch (operationType) { case "": case null: + await CheckVersion(); RunSuite(); break; case "install": - Logger.LogInformation("Installing ABP Suite..."); - await InstallSuiteAsync(); + await InstallSuiteAsync(preview); break; case "update": - Logger.LogInformation("Updating ABP Suite..."); - await UpdateSuiteAsync(); + await UpdateSuiteAsync(preview); break; case "remove": @@ -50,8 +56,46 @@ namespace Volo.Abp.Cli.Commands } } - private async Task InstallSuiteAsync() + private async Task CheckVersion() + { + var currentSuiteVersionAsString = GetCurrentSuiteVersion(); + + if (string.IsNullOrEmpty(currentSuiteVersionAsString)) + { + await InstallSuiteAsync(); + return; + } + + var currentVersion = SemanticVersion.Parse(currentSuiteVersionAsString); + + var preview = currentVersion.IsPrerelease; + + var latestVersion = await GetLatestSuiteVersioAsync(preview); + + if (latestVersion > currentVersion) + { + await UpdateSuiteAsync(preview); + } + } + + private string GetCurrentSuiteVersion() + { + var dotnetToolList = CmdHelper.RunCmdAndGetOutput("dotnet tool list -g"); + + var suiteLine = dotnetToolList.Split(Environment.NewLine).FirstOrDefault(l => l.ToLower().StartsWith("volo.abp.suite ")); + + if (string.IsNullOrEmpty(suiteLine)) + { + return null; + } + + return suiteLine.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1]; + } + + private async Task InstallSuiteAsync(bool preview = false) { + Logger.LogInformation("Installing ABP Suite..."); + var nugetIndexUrl = await _nuGetIndexUrlService.GetAsync(); if (nugetIndexUrl == null) @@ -61,7 +105,9 @@ namespace Volo.Abp.Cli.Commands try { - var result = CmdHelper.RunCmd("dotnet tool install " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); + var versionOption = await GetVersionOption(preview); + + var result = CmdHelper.RunCmd($"dotnet tool install {SuitePackageName} {versionOption} --add-source {nugetIndexUrl} -g"); if (result == 0) { @@ -86,8 +132,10 @@ namespace Volo.Abp.Cli.Commands Logger.LogInformation("dotnet tool install -g Volo.Abp.Suite"); } - private async Task UpdateSuiteAsync() + private async Task UpdateSuiteAsync(bool preview = false) { + Logger.LogInformation("Updating ABP Suite..."); + var nugetIndexUrl = await _nuGetIndexUrlService.GetAsync(); if (nugetIndexUrl == null) @@ -97,7 +145,9 @@ namespace Volo.Abp.Cli.Commands try { - var result = CmdHelper.RunCmd("dotnet tool update " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); + var versionOption = await GetVersionOption(preview); + + var result = CmdHelper.RunCmd($"dotnet tool update {SuitePackageName} {versionOption} --add-source {nugetIndexUrl} -g"); if (result != 0) { @@ -111,6 +161,25 @@ namespace Volo.Abp.Cli.Commands } } + private async Task GetVersionOption(bool preview) + { + if (preview) + { + var latestVersion = await GetLatestSuiteVersioAsync(true); + if (latestVersion.IsPrerelease) + { + return $"--version {latestVersion.ToString()}"; + } + } + + return ""; + } + + private async Task GetLatestSuiteVersioAsync(bool preview) + { + return await _nuGetService.GetLatestVersionOrNullAsync(SuitePackageName, includeReleaseCandidates: preview); + } + private void ShowSuiteManualUpdateCommand() { Logger.LogError("You can also run the following command to update ABP Suite."); @@ -160,7 +229,9 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine(" abp suite"); sb.AppendLine(" abp suite install"); + sb.AppendLine(" abp suite install --preview"); sb.AppendLine(" abp suite update"); + sb.AppendLine(" abp suite update --preview"); sb.AppendLine(" abp suite remove"); sb.AppendLine(""); @@ -171,5 +242,13 @@ namespace Volo.Abp.Cli.Commands { return "Install, update, remove or start ABP Suite. See https://commercial.abp.io/tools/suite."; } + + public static class Options + { + public static class Preview + { + public const string Long = "preview"; + } + } } } \ No newline at end of file From f115d70b1affa0fa2ddca2440b1181be8ca7048c Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 27 Aug 2020 14:58:18 +0300 Subject: [PATCH 2/3] Update SuiteCommand.cs --- .../Volo/Abp/Cli/Commands/SuiteCommand.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs index a0ae74cf9c..25a3d8ea5c 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs @@ -63,18 +63,6 @@ namespace Volo.Abp.Cli.Commands if (string.IsNullOrEmpty(currentSuiteVersionAsString)) { await InstallSuiteAsync(); - return; - } - - var currentVersion = SemanticVersion.Parse(currentSuiteVersionAsString); - - var preview = currentVersion.IsPrerelease; - - var latestVersion = await GetLatestSuiteVersioAsync(preview); - - if (latestVersion > currentVersion) - { - await UpdateSuiteAsync(preview); } } From 7c6b0c454849e8c3dd6a22f437be9bcf1ae69fda Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 28 Aug 2020 09:30:07 +0300 Subject: [PATCH 3/3] Update SuiteCommand.cs --- .../Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs index 25a3d8ea5c..2d58474ed5 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs @@ -37,7 +37,7 @@ namespace Volo.Abp.Cli.Commands { case "": case null: - await CheckVersion(); + await InstallSuiteIfNotInstalledAsync(); RunSuite(); break; @@ -56,7 +56,7 @@ namespace Volo.Abp.Cli.Commands } } - private async Task CheckVersion() + private async Task InstallSuiteIfNotInstalledAsync() { var currentSuiteVersionAsString = GetCurrentSuiteVersion(); @@ -239,4 +239,4 @@ namespace Volo.Abp.Cli.Commands } } } -} \ No newline at end of file +}