From 0fe58cb3939705baa4a3659c5f3b900aed143f7c Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Jul 2023 14:54:09 +0300 Subject: [PATCH] Cli: Allow Suite to be opened with a target solution --- .../Volo/Abp/Cli/Commands/SuiteCommand.cs | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 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 b35efb6f36..ec0d2aacfe 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 @@ -83,7 +83,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency case null: await InstallSuiteIfNotInstalledAsync(currentSuiteVersionAsString); _abpSuitePort = await _suiteAppSettingsService.GetSuitePortAsync(currentSuiteVersionAsString); - RunSuite(); + RunSuite(commandLineArgs); break; case "generate": @@ -418,7 +418,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency CmdHelper.RunCmd("dotnet tool uninstall " + SuitePackageName + " -g"); } - private void RunSuite() + private void RunSuite(CommandLineArgs commandLineArgs) { try { @@ -433,11 +433,16 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency { Logger.LogWarning("Couldn't check ABP Suite installed status: " + ex.Message); } - + + var targetSolution = GetTargetSolutionOrNull(commandLineArgs); + var launchUrl = targetSolution == null? + $"http://localhost:{_abpSuitePort}": + $"http://localhost:{_abpSuitePort}/CrudPageGenerator/Create?targetSolution={targetSolution}"; + if (IsSuiteAlreadyRunning()) { Logger.LogInformation("Opening suite..."); - CmdHelper.Open($"http://localhost:{_abpSuitePort}"); + CmdHelper.Open(launchUrl); return; } @@ -447,7 +452,28 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency return; } - CmdHelper.RunCmd("abp-suite"); + if (targetSolution == null) + { + CmdHelper.RunCmd("abp-suite"); + } + else + { + new Thread(OpenSuiteInBrowserWithLaunchUrl).Start(); + + CmdHelper.RunCmd("abp-suite --no-browser"); + + void OpenSuiteInBrowserWithLaunchUrl() + { + Thread.Sleep(2500); // needed for suite to be ready. + CmdHelper.Open(launchUrl); + } + } + } + + private object GetTargetSolutionOrNull(CommandLineArgs commandLineArgs) + { + return commandLineArgs.Options.GetOrNull(Options.Crud.Solution.Short, Options.Crud.Solution.Long) + ?? Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln", SearchOption.TopDirectoryOnly).FirstOrDefault(); } private Process StartSuite()