Browse Source

Proxy Generator: ABP CLI should warn developer when project has @abp/ng.schematics with a different version

resolves https://github.com/abpframework/abp/issues/5266
pull/5563/head
Yunus Emre Kalkan 6 years ago
parent
commit
75ee59c197
  1. 15
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs
  2. 38
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs

15
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs

@ -73,7 +73,7 @@ namespace Volo.Abp.Cli
{ {
var assembly = typeof(CliService).Assembly; var assembly = typeof(CliService).Assembly;
var toolPath = GetToolPath(assembly); var toolPath = GetToolPath(assembly);
var currentCliVersion = await GetCurrentCliVersion(assembly); var currentCliVersion = await GetCurrentCliVersionInternalAsync(assembly);
var updateChannel = GetUpdateChannel(currentCliVersion); var updateChannel = GetUpdateChannel(currentCliVersion);
Logger.LogInformation($"Version {currentCliVersion} ({updateChannel})"); Logger.LogInformation($"Version {currentCliVersion} ({updateChannel})");
@ -94,7 +94,7 @@ namespace Volo.Abp.Cli
} }
} }
private static string GetToolPath(Assembly assembly) private string GetToolPath(Assembly assembly)
{ {
if (!assembly.Location.Contains(".store")) if (!assembly.Location.Contains(".store"))
{ {
@ -104,7 +104,12 @@ namespace Volo.Abp.Cli
return assembly.Location.Substring(0, assembly.Location.IndexOf(".store", StringComparison.Ordinal)); return assembly.Location.Substring(0, assembly.Location.IndexOf(".store", StringComparison.Ordinal));
} }
private static async Task<SemanticVersion> GetCurrentCliVersion(Assembly assembly) public async Task<SemanticVersion> GetCurrentCliVersionAsync(Assembly assembly)
{
return await GetCurrentCliVersionInternalAsync(assembly);
}
private async Task<SemanticVersion> GetCurrentCliVersionInternalAsync(Assembly assembly)
{ {
SemanticVersion currentCliVersion = default; SemanticVersion currentCliVersion = default;
@ -134,7 +139,7 @@ namespace Volo.Abp.Cli
return currentCliVersion; return currentCliVersion;
} }
private static UpdateChannel GetUpdateChannel(SemanticVersion currentCliVersion) private UpdateChannel GetUpdateChannel(SemanticVersion currentCliVersion)
{ {
if (!currentCliVersion.IsPrerelease) if (!currentCliVersion.IsPrerelease)
{ {
@ -172,7 +177,7 @@ namespace Volo.Abp.Cli
} }
} }
private static bool IsGlobalTool(string toolPath) private bool IsGlobalTool(string toolPath)
{ {
var globalPaths = new[] { @"%USERPROFILE%\.dotnet\tools\", "%HOME%/.dotnet/tools/", }; var globalPaths = new[] { @"%USERPROFILE%\.dotnet\tools\", "%HOME%/.dotnet/tools/", };
return globalPaths.Select(Environment.ExpandEnvironmentVariables).Contains(toolPath); return globalPaths.Select(Environment.ExpandEnvironmentVariables).Contains(toolPath);

38
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs

@ -2,7 +2,10 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NuGet.Versioning;
using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Utils; using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -11,14 +14,23 @@ namespace Volo.Abp.Cli.Commands
{ {
public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependency public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependency
{ {
public CliService CliService { get; }
public ILogger<HelpCommand> Logger { get; set; }
protected abstract string CommandName { get; } protected abstract string CommandName { get; }
protected abstract string SchematicsCommandName { get; } protected abstract string SchematicsCommandName { get; }
public Task ExecuteAsync(CommandLineArgs commandLineArgs) public ProxyCommandBase(CliService cliService)
{
CliService = cliService;
Logger = NullLogger<HelpCommand>.Instance;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{ {
CheckAngularJsonFile(); CheckAngularJsonFile();
CheckNgSchematics(); await CheckNgSchematicsAsync();
var prompt = commandLineArgs.Options.ContainsKey("p") || commandLineArgs.Options.ContainsKey("prompt"); var prompt = commandLineArgs.Options.ContainsKey("p") || commandLineArgs.Options.ContainsKey("prompt");
var defaultValue = prompt ? null : "__default"; var defaultValue = prompt ? null : "__default";
@ -51,11 +63,9 @@ namespace Volo.Abp.Cli.Commands
} }
CmdHelper.RunCmd(commandBuilder.ToString()); CmdHelper.RunCmd(commandBuilder.ToString());
return Task.CompletedTask;
} }
private void CheckNgSchematics() private async Task CheckNgSchematicsAsync()
{ {
var packageJsonPath = $"package.json"; var packageJsonPath = $"package.json";
@ -68,10 +78,10 @@ namespace Volo.Abp.Cli.Commands
); );
} }
var schematicsPackageNode = var schematicsVersion =
(string) JObject.Parse(File.ReadAllText(packageJsonPath))["devDependencies"]?["@abp/ng.schematics"]; (string) JObject.Parse(File.ReadAllText(packageJsonPath))["devDependencies"]?["@abp/ng.schematics"];
if (schematicsPackageNode == null) if (schematicsVersion == null)
{ {
throw new CliUsageException( throw new CliUsageException(
"\"@abp/ng.schematics\" NPM package should be installed to the devDependencies before running this command!" + "\"@abp/ng.schematics\" NPM package should be installed to the devDependencies before running this command!" +
@ -79,6 +89,20 @@ namespace Volo.Abp.Cli.Commands
GetUsageInfo() GetUsageInfo()
); );
} }
var parseError = SemanticVersion.TryParse(schematicsVersion.TrimStart('~', '^', 'v'), out var semanticSchematicsVersion);
if (parseError)
{
Logger.LogWarning("Couldn't determinate version of \"@abp/ng.schematics\" package.");
return;
}
var cliVersion = await CliService.GetCurrentCliVersionAsync(typeof(CliService).Assembly);
if (semanticSchematicsVersion < cliVersion)
{
Logger.LogWarning("\"@abp/ng.schematics\" version is lower than ABP Cli version.");
return;
}
} }
private void CheckAngularJsonFile() private void CheckAngularJsonFile()

Loading…
Cancel
Save