Browse Source

Cli: Switch-To command should work on a single project

resolves https://github.com/abpframework/abp/issues/16839
pull/16850/head
Yunus Emre Kalkan 3 years ago
parent
commit
df92757045
  1. 177
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

177
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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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";
}
}
}

Loading…
Cancel
Save