mirror of https://github.com/abpframework/abp.git
6 changed files with 228 additions and 0 deletions
@ -0,0 +1,136 @@ |
|||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using ICSharpCode.SharpZipLib.Core; |
||||
|
using ICSharpCode.SharpZipLib.Zip; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
|
using Volo.Abp.Cli.Args; |
||||
|
using Volo.Abp.Cli.Licensing; |
||||
|
using Volo.Abp.Cli.ProjectBuilding; |
||||
|
using Volo.Abp.Cli.ProjectBuilding.Building; |
||||
|
using Volo.Abp.Cli.Utils; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.Commands |
||||
|
{ |
||||
|
public class SuiteCommand : IConsoleCommand, ITransientDependency |
||||
|
{ |
||||
|
private const string SuitePackageName = "Volo.Abp.Suite"; |
||||
|
public ILogger<SuiteCommand> Logger { get; set; } |
||||
|
private readonly IApiKeyService _apiKeyService; |
||||
|
|
||||
|
public SuiteCommand(IApiKeyService apiKeyService) |
||||
|
{ |
||||
|
_apiKeyService = apiKeyService; |
||||
|
Logger = NullLogger<SuiteCommand>.Instance; |
||||
|
} |
||||
|
|
||||
|
public async Task ExecuteAsync(CommandLineArgs commandLineArgs) |
||||
|
{ |
||||
|
var operationType = NamespaceHelper.NormalizeNamespace(commandLineArgs.Target); |
||||
|
|
||||
|
switch (operationType) |
||||
|
{ |
||||
|
case "": |
||||
|
Logger.LogInformation("Running Suite..."); |
||||
|
RunSuite(); |
||||
|
break; |
||||
|
|
||||
|
case "install": |
||||
|
case "i": |
||||
|
Logger.LogInformation("Installing Suite..."); |
||||
|
await InstallSuiteAsync(); |
||||
|
break; |
||||
|
|
||||
|
case "update": |
||||
|
case "u": |
||||
|
Logger.LogInformation("Updating Suite..."); |
||||
|
UpdateSuite(); |
||||
|
break; |
||||
|
|
||||
|
case "remove": |
||||
|
case "r": |
||||
|
Logger.LogInformation("Removing Suite..."); |
||||
|
RemoveSuite(); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private async Task InstallSuiteAsync() |
||||
|
{ |
||||
|
var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); |
||||
|
if (apiKeyResult == null || string.IsNullOrEmpty(apiKeyResult.ApiKey)) |
||||
|
{ |
||||
|
Logger.LogInformation("Couldn't retrieve the API Key for Nuget!"); |
||||
|
await Task.CompletedTask; |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
var nugetIndexUrl = CliUrls.GetNuGetServiceIndexUrl(apiKeyResult.ApiKey); |
||||
|
CmdHelper.RunCmd("dotnet tool install " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); |
||||
|
} |
||||
|
|
||||
|
private static void UpdateSuite() |
||||
|
{ |
||||
|
CmdHelper.RunCmd("dotnet tool update " + SuitePackageName + " -g"); |
||||
|
} |
||||
|
|
||||
|
private static void RemoveSuite() |
||||
|
{ |
||||
|
CmdHelper.RunCmd("dotnet tool uninstall " + SuitePackageName + " -g"); |
||||
|
} |
||||
|
|
||||
|
private void RunSuite() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
if (!GlobalToolHelper.IsGlobalToolInstalled("abp-suite")) |
||||
|
{ |
||||
|
Logger.LogWarning("Suite is not installed! To install it you can run the command: \"abp suite install\""); |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
Logger.LogWarning("Couldn't check Suite installed status: " + ex.Message); |
||||
|
} |
||||
|
|
||||
|
CmdHelper.RunCmd("abp-suite"); |
||||
|
} |
||||
|
|
||||
|
public string GetUsageInfo() |
||||
|
{ |
||||
|
var sb = new StringBuilder(); |
||||
|
|
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("Usage:"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine(" abp suite [options]"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("Options:"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("<no argument> (runs Suite)"); |
||||
|
sb.AppendLine("-i|--install (installs Suite as a dotnet global tool)"); |
||||
|
sb.AppendLine("-u|--update (updates Suite to the latest)"); |
||||
|
sb.AppendLine("-r|--remove (uninstalls Suite)"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("Examples:"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine(" abp suite"); |
||||
|
sb.AppendLine(" abp suite install"); |
||||
|
sb.AppendLine(" abp suite update"); |
||||
|
sb.AppendLine(""); |
||||
|
|
||||
|
return sb.ToString(); |
||||
|
} |
||||
|
|
||||
|
public string GetShortDescription() |
||||
|
{ |
||||
|
return "Shortcut commands to use Abp Suite tool."; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
using System.IO; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.Utils |
||||
|
{ |
||||
|
public class GlobalToolHelper |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Checks whether the tool is installed or not.
|
||||
|
/// </summary>
|
||||
|
/// <param name="toolCommandName">Eg: For AbpSuite tool it's "abp-suite", for ABP CLI tool it's "abp"</param>
|
||||
|
public static bool IsGlobalToolInstalled(string toolCommandName) |
||||
|
{ |
||||
|
if (PlatformHelper.GetPlatform() == RuntimePlatform.LinuxOrMacOs) |
||||
|
{ |
||||
|
return File.Exists("%HOME%/.dotnet/tools/" + toolCommandName); |
||||
|
} |
||||
|
|
||||
|
return File.Exists(@"%USERPROFILE%\.dotnet\tools\" + toolCommandName + ".exe"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.Utils |
||||
|
{ |
||||
|
public class PlatformHelper |
||||
|
{ |
||||
|
public static OSPlatform GetOperatingSystem() |
||||
|
{ |
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) |
||||
|
{ |
||||
|
//MAC
|
||||
|
return OSPlatform.OSX; |
||||
|
} |
||||
|
|
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) |
||||
|
{ |
||||
|
return OSPlatform.Linux; |
||||
|
} |
||||
|
|
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
||||
|
{ |
||||
|
return OSPlatform.Windows; |
||||
|
} |
||||
|
|
||||
|
throw new Exception("Cannot determine operating system!"); |
||||
|
} |
||||
|
|
||||
|
public static RuntimePlatform GetPlatform() |
||||
|
{ |
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || |
||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) |
||||
|
{ |
||||
|
return RuntimePlatform.LinuxOrMacOs; |
||||
|
} |
||||
|
|
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
||||
|
{ |
||||
|
return RuntimePlatform.Windows; |
||||
|
} |
||||
|
|
||||
|
throw new Exception("Cannot determine runtime platform!"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum RuntimePlatform |
||||
|
{ |
||||
|
Windows = 1, |
||||
|
LinuxOrMacOs = 2 |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"profiles": { |
||||
|
"Volo.Abp.Cli": { |
||||
|
"commandName": "Project", |
||||
|
"commandLineArgs": "suite i" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue