Browse Source

CLI: Add `switch-to-prerc` command.

pull/18608/head
Engincan VESKE 2 years ago
parent
commit
f06b1d7b6c
  1. 1
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
  2. 45
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs
  3. 33
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs
  4. 110
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

1
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs

@ -56,6 +56,7 @@ public class AbpCliCoreModule : AbpModule
options.Commands[SwitchToPreviewCommand.Name] = typeof(SwitchToPreviewCommand);
options.Commands[SwitchToStableCommand.Name] = typeof(SwitchToStableCommand);
options.Commands[SwitchToNightlyCommand.Name] = typeof(SwitchToNightlyCommand);
options.Commands[SwitchToPreRcCommand.Name] = typeof(SwitchToPreRcCommand);
options.Commands[SwitchToLocal.Name] = typeof(SwitchToLocal);
options.Commands[TranslateCommand.Name] = typeof(TranslateCommand);
options.Commands[BuildCommand.Name] = typeof(BuildCommand);

45
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs

@ -0,0 +1,45 @@
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.ProjectModification;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands;
public class SwitchToPreRcCommand : IConsoleCommand, ITransientDependency
{
public const string Name = "switch-to-prerc";
private readonly PackagePreviewSwitcher _packagePreviewSwitcher;
public SwitchToPreRcCommand(PackagePreviewSwitcher packagePreviewSwitcher)
{
_packagePreviewSwitcher = packagePreviewSwitcher;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
await _packagePreviewSwitcher.SwitchToPreRc(commandLineArgs);
}
public string GetUsageInfo()
{
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine(" abp switch-to-prerc [options]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine("-d|--directory");
sb.AppendLine("");
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI");
return sb.ToString();
}
public string GetShortDescription()
{
return "Switches npm packages to pre-rc preview ABP version.";
}
}

33
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

@ -53,7 +53,7 @@ public class NpmPackagesUpdater : ITransientDependency
public async Task Update(string rootDirectory, bool includePreviews = false,
bool includeReleaseCandidates = false,
bool switchToStable = false, string version = null)
bool switchToStable = false, string version = null, bool includePreRc = false)
{
var fileList = _packageJsonFileFinder.Find(rootDirectory);
@ -66,7 +66,7 @@ public class NpmPackagesUpdater : ITransientDependency
foreach (var file in fileList)
{
if (includePreviews)
if (includePreviews || includePreRc)
{
await CreateNpmrcFileAsync(Path.GetDirectoryName(file));
}
@ -82,7 +82,9 @@ public class NpmPackagesUpdater : ITransientDependency
{
var updated = await UpdatePackagesInFile(file, includePreviews, includeReleaseCandidates,
switchToStable,
version);
version,
includePreRc);
packagesUpdated.TryAdd(file, updated);
}
@ -162,7 +164,8 @@ public class NpmPackagesUpdater : ITransientDependency
bool includePreviews = false,
bool includeReleaseCandidates = false,
bool switchToStable = false,
string specifiedVersion = null)
string specifiedVersion = null,
bool includePreRc = false)
{
var packagesUpdated = false;
var fileContent = File.ReadAllText(filePath);
@ -177,7 +180,7 @@ public class NpmPackagesUpdater : ITransientDependency
foreach (var abpPackage in abpPackages)
{
var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates,
switchToStable, specifiedVersion);
switchToStable, specifiedVersion, includePreRc);
if (updated)
{
@ -198,7 +201,8 @@ public class NpmPackagesUpdater : ITransientDependency
bool includePreviews = false,
bool includeReleaseCandidates = false,
bool switchToStable = false,
string specifiedVersion = null)
string specifiedVersion = null,
bool includePreRc = false)
{
var currentVersion = (string)package.Value;
@ -221,7 +225,11 @@ public class NpmPackagesUpdater : ITransientDependency
}
else
{
if ((includePreviews ||
if (includePreRc && !includeReleaseCandidates)
{
version = await GetLatestVersion(package, includePreRc: true, workingDirectory: filePath.RemovePostFix("package.json"));
}
else if ((includePreviews ||
(!switchToStable && (currentVersion != null && currentVersion.Contains("-preview")))) &&
!includeReleaseCandidates)
{
@ -262,9 +270,10 @@ public class NpmPackagesUpdater : ITransientDependency
return version.Split("-", StringSplitOptions.RemoveEmptyEntries).Length > 1;
}
protected virtual async Task<string> GetLatestVersion(JProperty package, bool includeReleaseCandidates = false, bool includePreviews = false, string workingDirectory = null)
protected virtual async Task<string> GetLatestVersion(JProperty package, bool includeReleaseCandidates = false, bool includePreviews = false, string workingDirectory = null, bool includePreRc = false)
{
var key = package.Name + (includePreviews ? "(preview)" : string.Empty);
var postfix = includePreviews ? "(preview)" : (includePreRc ? "(prerc)" : string.Empty);
var key = package.Name + postfix;
if (_fileVersionStorage.ContainsKey(key))
{
@ -275,7 +284,11 @@ public class NpmPackagesUpdater : ITransientDependency
string newVersion = string.Empty;
if (includePreviews)
if (includePreRc)
{
newVersion = versionList.FirstOrDefault(v => v.Contains("-prerc"));
}
else if (includePreviews)
{
newVersion = versionList.FirstOrDefault(v => v.Contains("-preview"));
}

110
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

@ -44,6 +44,52 @@ public class PackagePreviewSwitcher : ITransientDependency
await SwitchProjectsToPreview(projectPaths);
}
}
public async Task SwitchToStable(CommandLineArgs commandLineArgs)
{
var solutionPaths = GetSolutionPaths(commandLineArgs);
if (solutionPaths.Any())
{
await SwitchSolutionsToStable(solutionPaths);
}
else
{
var projectPaths = GetProjectPaths(commandLineArgs);
await SwitchProjectsToStable(projectPaths);
}
}
public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs)
{
var solutionPaths = GetSolutionPaths(commandLineArgs);
if (solutionPaths.Any())
{
await SwitchSolutionsToNightlyPreview(solutionPaths);
}
else
{
var projectPaths = GetProjectPaths(commandLineArgs);
await SwitchProjectsToNightlyPreview(projectPaths);
}
}
public async Task SwitchToPreRc(CommandLineArgs commandLineArgs)
{
var solutionPaths = GetSolutionPaths(commandLineArgs);
if (solutionPaths.Any())
{
await SwitchNpmPackageVersionsOfSolutionsToPreRc(solutionPaths);
}
else
{
await SwitchNpmPackageVersionsOfProjectsToPreRc(GetProjectPaths(commandLineArgs));
}
}
private async Task SwitchProjectsToPreview(List<string> projects)
{
@ -88,22 +134,6 @@ public class PackagePreviewSwitcher : ITransientDependency
}
}
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)
@ -156,22 +186,6 @@ public class PackagePreviewSwitcher : ITransientDependency
}
}
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)
@ -220,6 +234,38 @@ public class PackagePreviewSwitcher : ITransientDependency
}
}
}
private async Task SwitchNpmPackageVersionsOfProjectsToPreRc(List<string> projects)
{
foreach (var project in projects)
{
var folder = Path.GetDirectoryName(project);
await _npmPackagesUpdater.Update(
folder,
includePreRc: true);
}
}
private async Task SwitchNpmPackageVersionsOfSolutionsToPreRc(List<string> solutionPaths)
{
foreach (var solutionPath in solutionPaths)
{
var solutionFolder = Path.GetDirectoryName(solutionPath);
var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder);
await _npmPackagesUpdater.Update(
solutionFolder,
includePreRc: true);
if (solutionAngularFolder != null)
{
await _npmPackagesUpdater.Update(
solutionAngularFolder,
includePreRc: true);
}
}
}
private List<string> GetSolutionPaths(CommandLineArgs commandLineArgs)
{

Loading…
Cancel
Save