From df92757045f2a0ca6798f9ad93c90c137a33b024 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 15 Jun 2023 10:12:19 +0300 Subject: [PATCH 1/2] Cli: Switch-To command should work on a single project resolves https://github.com/abpframework/abp/issues/16839 --- .../PackagePreviewSwitcher.cs | 177 +++++++++++++++--- 1 file changed, 150 insertions(+), 27 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs index 03fcf65036..9e65595182 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; @@ -32,6 +33,37 @@ public class PackagePreviewSwitcher : ITransientDependency { var solutionPaths = GetSolutionPaths(commandLineArgs); + if (solutionPaths.Any()) + { + await SwitchSolutionsToPreview(solutionPaths); + } + else + { + var projectPaths = GetProjectPaths(commandLineArgs); + + await SwitchProjectsToPreview(projectPaths); + } + } + + private async Task SwitchProjectsToPreview(List projects) + { + foreach (var project in projects) + { + var folder = Path.GetDirectoryName(project); + + await _nugetPackagesVersionUpdater.UpdateProjectAsync( + project, + includeReleaseCandidates: true); + + await _npmPackagesUpdater.Update( + folder, + false, + true); + } + } + + private async Task SwitchSolutionsToPreview(List solutionPaths) + { foreach (var solutionPath in solutionPaths) { var solutionFolder = Path.GetDirectoryName(solutionPath); @@ -56,69 +88,134 @@ public class PackagePreviewSwitcher : ITransientDependency } } - public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs) + public async Task SwitchToStable(CommandLineArgs commandLineArgs) { var solutionPaths = GetSolutionPaths(commandLineArgs); + if (solutionPaths.Any()) + { + await SwitchSolutionsToStable(solutionPaths); + } + else + { + var projectPaths = GetProjectPaths(commandLineArgs); + + await SwitchProjectsToStable(projectPaths); + } + } + + private async Task SwitchProjectsToStable(List projects) + { + foreach (var project in projects) + { + var folder = Path.GetDirectoryName(project); + + await _nugetPackagesVersionUpdater.UpdateProjectAsync( + project, + false, + false, + true); + + await _npmPackagesUpdater.Update( + folder, + false, + false, + true); + } + } + + private async Task SwitchSolutionsToStable(List solutionPaths) + { foreach (var solutionPath in solutionPaths) { var solutionFolder = Path.GetDirectoryName(solutionPath); var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder); - _packageSourceManager.Add(solutionFolder, "ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json"); + _packageSourceManager.Remove(solutionFolder, "ABP Nightly"); - if (solutionPath != null) - { - await _nugetPackagesVersionUpdater.UpdateSolutionAsync( - solutionPath, - true); - } + await _nugetPackagesVersionUpdater.UpdateSolutionAsync( + solutionPath, + false, + false, + true); await _npmPackagesUpdater.Update( solutionFolder, + false, + false, true); if (solutionAngularFolder != null) { await _npmPackagesUpdater.Update( solutionAngularFolder, + false, + false, true); } } } - public async Task SwitchToStable(CommandLineArgs commandLineArgs) + public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs) { var solutionPaths = GetSolutionPaths(commandLineArgs); + if (solutionPaths.Any()) + { + await SwitchSolutionsToNightlyPreview(solutionPaths); + } + else + { + var projectPaths = GetProjectPaths(commandLineArgs); + + await SwitchProjectsToNightlyPreview(projectPaths); + } + } + + private async Task SwitchProjectsToNightlyPreview(List projects) + { + foreach (var project in projects) + { + var folder = Path.GetDirectoryName(project); + + _packageSourceManager.Add(FindSolutionFolder(project) ?? folder, "ABP Nightly", + "https://www.myget.org/F/abp-nightly/api/v3/index.json"); + + await _nugetPackagesVersionUpdater.UpdateSolutionAsync( + project, + true); + + await _npmPackagesUpdater.Update( + folder, + true); + } + } + + private async Task SwitchSolutionsToNightlyPreview(List solutionPaths) + { foreach (var solutionPath in solutionPaths) { var solutionFolder = Path.GetDirectoryName(solutionPath); var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder); - _packageSourceManager.Remove(solutionFolder, "ABP Nightly"); + _packageSourceManager.Add(solutionFolder, "ABP Nightly", + "https://www.myget.org/F/abp-nightly/api/v3/index.json"); if (solutionPath != null) { await _nugetPackagesVersionUpdater.UpdateSolutionAsync( solutionPath, - false, - false, true); } await _npmPackagesUpdater.Update( solutionFolder, - false, - false, true); if (solutionAngularFolder != null) { await _npmPackagesUpdater.Update( solutionAngularFolder, - false, - false, true); } } @@ -126,22 +223,18 @@ public class PackagePreviewSwitcher : ITransientDependency private List GetSolutionPaths(CommandLineArgs commandLineArgs) { - var directory = commandLineArgs.Options.GetOrNull(Options.SolutionDirectory.Short, Options.SolutionDirectory.Long) - ?? Directory.GetCurrentDirectory(); - - var solutionPaths = Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories); - - if (!solutionPaths.Any()) - { - Logger.LogWarning("No solution (.sln) found to change version."); - } + return Directory.GetFiles(GetDirectory(commandLineArgs), "*.sln", SearchOption.AllDirectories).ToList(); + } - return solutionPaths.ToList(); + private List GetProjectPaths(CommandLineArgs commandLineArgs) + { + return Directory.GetFiles(GetDirectory(commandLineArgs), "*.csproj", SearchOption.AllDirectories).ToList(); } - private string GetSolutionFolder(CommandLineArgs commandLineArgs) + private string GetDirectory(CommandLineArgs commandLineArgs) { return commandLineArgs.Options.GetOrNull(Options.SolutionDirectory.Short, Options.SolutionDirectory.Long) + ?? commandLineArgs.Options.GetOrNull(Options.Directory.Short, Options.Directory.Long) ?? Directory.GetCurrentDirectory(); } @@ -160,6 +253,31 @@ public class PackagePreviewSwitcher : ITransientDependency } return null; + } + + [CanBeNull] + private string FindSolutionFolder(string projectFile) + { + var targetFolder = Path.GetDirectoryName(projectFile); + + do + { + if (Directory.GetParent(targetFolder) != null) + { + targetFolder = Directory.GetParent(targetFolder).FullName; + } + else + { + return Path.GetDirectoryName(projectFile); + } + + if (Directory.GetFiles(targetFolder, "*.sln", SearchOption.TopDirectoryOnly).Any()) + { + break; + } + } while (targetFolder != null); + + return targetFolder; } public static class Options @@ -169,5 +287,10 @@ public class PackagePreviewSwitcher : ITransientDependency public const string Short = "sd"; public const string Long = "solution-directory"; } + public static class Directory + { + public const string Short = "d"; + public const string Long = "directory"; + } } } From d01cd33810b5fd9011e84113c3dbe044ff0daf5b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 15 Jun 2023 11:00:14 +0300 Subject: [PATCH 2/2] Update documentation --- docs/en/CLI.md | 10 +++++----- .../Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/SwitchToStableCommand.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index a65f29a324..48858edc74 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -419,7 +419,7 @@ abp remove-proxy -t csharp --folder MyProxies/InnerFolder ### switch-to-preview -You can use this command to switch your project to latest preview version of the ABP framework. +You can use this command to switch your solution or project to latest preview version of the ABP framework. Usage: @@ -429,12 +429,12 @@ abp switch-to-preview [options] #### Options -* `--solution-directory` or `-sd`: Specifies the directory. The solution should be in that directory or in any of its sub directories. If not specified, default is the current directory. +* `--directory` or `-d`: Specifies the directory. The solution or project should be in that directory or in any of its sub directories. If not specified, default is the current directory. ### switch-to-nightly -You can use this command to switch your project to latest [nightly](Nightly-Builds.md) preview version of the ABP framework packages. +You can use this command to switch your solution or project to latest [nightly](Nightly-Builds.md) preview version of the ABP framework packages. Usage: @@ -444,7 +444,7 @@ abp switch-to-nightly [options] #### Options -* `--solution-directory` or `-sd`: Specifies the directory. The solution should be in that directory or in any of its sub directories. If not specified, default is the current directory. +* `--directory` or `-d`: Specifies the directory. The solution or project should be in that directory or in any of its sub directories. If not specified, default is the current directory. ### switch-to-stable @@ -457,7 +457,7 @@ abp switch-to-stable [options] ```` #### Options -* `--solution-directory` or `-sd`: Specifies the directory. The solution should be in that directory or in any of its sub directories. If not specified, default is the current directory. +* `--directory` or `-d`: Specifies the directory. The solution or project should be in that directory or in any of its sub directories. If not specified, default is the current directory. ### switch-to-local diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs index 4893680004..fd1fdbab89 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs @@ -31,7 +31,7 @@ public class SwitchToNightlyCommand : IConsoleCommand, ITransientDependency sb.AppendLine(" abp switch-to-nightly [options]"); sb.AppendLine(""); sb.AppendLine("Options:"); - sb.AppendLine("-sd|--solution-directory"); + sb.AppendLine("-d|--directory"); sb.AppendLine(""); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs index 84b58d6b8b..695330267e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs @@ -31,7 +31,7 @@ public class SwitchToPreviewCommand : IConsoleCommand, ITransientDependency sb.AppendLine(" abp switch-to-preview [options]"); sb.AppendLine(""); sb.AppendLine("Options:"); - sb.AppendLine("-sd|--solution-directory"); + sb.AppendLine("-d|--directory"); sb.AppendLine(""); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToStableCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToStableCommand.cs index cc0fa9ff75..c5976e2b75 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToStableCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToStableCommand.cs @@ -31,7 +31,7 @@ public class SwitchToStableCommand : IConsoleCommand, ITransientDependency sb.AppendLine(" abp switch-to-stable [options]"); sb.AppendLine(""); sb.AppendLine("Options:"); - sb.AppendLine("-sd|--solution-directory"); + sb.AppendLine("-d|--directory"); sb.AppendLine(""); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI");