add Suite cli command to Abp Cli.

rel-1.1
Alper Ebicoglu 6 years ago
parent e45d2c07d0
commit f940f9142e

@ -33,6 +33,7 @@ namespace Volo.Abp.Cli
options.Commands["add-module"] = typeof(AddModuleCommand);
options.Commands["login"] = typeof(LoginCommand);
options.Commands["logout"] = typeof(LogoutCommand);
options.Commands["suite"] = typeof(SuiteCommand);
});
}
}

@ -4,10 +4,21 @@
{
#if DEBUG
public const string WwwAbpIo = "https://localhost:44328/";
public const string AccountAbpIo = "https://localhost:44333/";
public const string NuGetRootPath = "https://localhost:44373/";
#else
public const string WwwAbpIo = "https://abp.io/";
public const string AccountAbpIo = "https://account.abp.io/";
public const string NuGetRootPath = "https://nuget.abp.io/";
#endif
public static string GetNuGetServiceIndexUrl(string apiKey)
{
return NuGetRootPath + apiKey + "/v3/index.json";
}
}
}

@ -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…
Cancel
Save