diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs index 74bc1bf9f5..ab680ce4b8 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs @@ -2,6 +2,8 @@ using System; using System.IO; using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; @@ -12,19 +14,50 @@ namespace Volo.Abp.Cli.Commands { public Task ExecuteAsync(CommandLineArgs commandLineArgs) { - var angularPath = $"angular.json"; - if (!File.Exists(angularPath)) + CheckAngularJsonFile(); + CheckNgSchematics(); + + CmdHelper.RunCmd("npx ng g @abp/ng.schematics:proxy"); + + return Task.CompletedTask; + } + + private void CheckNgSchematics() + { + var packageJsonPath = $"package.json"; + + if (!File.Exists(packageJsonPath)) { throw new CliUsageException( - "angular.json file not found. You must run this command in the angular folder." + - Environment.NewLine + Environment.NewLine + - GetUsageInfo() - ); + "package.json file not found" + + Environment.NewLine + + GetUsageInfo() + ); } - CmdHelper.RunCmd("npx ng g @abp/ng.schematics:proxy"); + var schematicsPackageNode = (string) JObject.Parse(File.ReadAllText(packageJsonPath))["devDependencies"]?["@abp/ng.schematics"]; - return Task.CompletedTask; + if (schematicsPackageNode == null) + { + throw new CliUsageException( + "\"@abp/ng.schematics\" NPM package should be installed to the devDependencies before running this command!" + + Environment.NewLine + + GetUsageInfo() + ); + } + } + + private void CheckAngularJsonFile() + { + var angularPath = $"angular.json"; + if (!File.Exists(angularPath)) + { + throw new CliUsageException( + "angular.json file not found. You must run this command in the angular folder." + + Environment.NewLine + Environment.NewLine + + GetUsageInfo() + ); + } } public string GetUsageInfo()