Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Create switch-to-prerc command to only update npm packages to pre-rc versions. #18608

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Check warning on line 18 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs#L15-L18

Added lines #L15 - L18 were not covered by tests

public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
await _packagePreviewSwitcher.SwitchToPreRc(commandLineArgs);
}

Check warning on line 23 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs#L21-L23

Added lines #L21 - L23 were not covered by tests

public string GetUsageInfo()
{
var sb = new StringBuilder();

Check warning on line 27 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs#L26-L27

Added lines #L26 - L27 were not covered by tests

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");

Check warning on line 36 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs#L29-L36

Added lines #L29 - L36 were not covered by tests

return sb.ToString();
}

Check warning on line 39 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs#L38-L39

Added lines #L38 - L39 were not covered by tests

public string GetShortDescription()
{
return "Switches npm packages to pre-rc ABP version.";
}

Check warning on line 44 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreRcCommand.cs#L42-L44

Added lines #L42 - L44 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

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);

Expand All @@ -66,7 +66,7 @@

foreach (var file in fileList)
{
if (includePreviews)
if (includePreviews || includePreRc)
{
await CreateNpmrcFileAsync(Path.GetDirectoryName(file));
}
Expand All @@ -82,7 +82,9 @@
{
var updated = await UpdatePackagesInFile(file, includePreviews, includeReleaseCandidates,
switchToStable,
version);
version,
includePreRc);

Check warning on line 86 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs#L85-L86

Added lines #L85 - L86 were not covered by tests

packagesUpdated.TryAdd(file, updated);
}

Expand Down Expand Up @@ -162,7 +164,8 @@
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);
Expand All @@ -177,7 +180,7 @@
foreach (var abpPackage in abpPackages)
{
var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates,
switchToStable, specifiedVersion);
switchToStable, specifiedVersion, includePreRc);

Check warning on line 183 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs#L183

Added line #L183 was not covered by tests

if (updated)
{
Expand All @@ -198,7 +201,8 @@
bool includePreviews = false,
bool includeReleaseCandidates = false,
bool switchToStable = false,
string specifiedVersion = null)
string specifiedVersion = null,
bool includePreRc = false)
{
var currentVersion = (string)package.Value;

Expand All @@ -221,7 +225,11 @@
}
else
{
if ((includePreviews ||
if (includePreRc && !includeReleaseCandidates)
{
version = await GetLatestVersion(package, includePreRc: true, workingDirectory: filePath.RemovePostFix("package.json"));
}

Check warning on line 231 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs#L229-L231

Added lines #L229 - L231 were not covered by tests
else if ((includePreviews ||
(!switchToStable && (currentVersion != null && currentVersion.Contains("-preview")))) &&
!includeReleaseCandidates)
{
Expand Down Expand Up @@ -262,9 +270,10 @@
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;

Check warning on line 276 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs#L276

Added line #L276 was not covered by tests

if (_fileVersionStorage.ContainsKey(key))
{
Expand All @@ -275,7 +284,11 @@

string newVersion = string.Empty;

if (includePreviews)
if (includePreRc)
{

Check warning on line 288 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs#L288

Added line #L288 was not covered by tests
newVersion = versionList.FirstOrDefault(v => v.Contains("-prerc"));
}

Check warning on line 290 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs#L290

Added line #L290 was not covered by tests
else if (includePreviews)
{
newVersion = versionList.FirstOrDefault(v => v.Contains("-preview"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,52 @@
await SwitchProjectsToPreview(projectPaths);
}
}

public async Task SwitchToStable(CommandLineArgs commandLineArgs)
{
var solutionPaths = GetSolutionPaths(commandLineArgs);

Check warning on line 50 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L49-L50

Added lines #L49 - L50 were not covered by tests

if (solutionPaths.Any())
{
await SwitchSolutionsToStable(solutionPaths);
}

Check warning on line 55 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L53-L55

Added lines #L53 - L55 were not covered by tests
else
{
var projectPaths = GetProjectPaths(commandLineArgs);

Check warning on line 58 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L57-L58

Added lines #L57 - L58 were not covered by tests

await SwitchProjectsToStable(projectPaths);
}
}

Check warning on line 62 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L60-L62

Added lines #L60 - L62 were not covered by tests

public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs)
{
var solutionPaths = GetSolutionPaths(commandLineArgs);

Check warning on line 66 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L65-L66

Added lines #L65 - L66 were not covered by tests

if (solutionPaths.Any())
{
await SwitchSolutionsToNightlyPreview(solutionPaths);
}

Check warning on line 71 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L69-L71

Added lines #L69 - L71 were not covered by tests
else
{
var projectPaths = GetProjectPaths(commandLineArgs);

Check warning on line 74 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L73-L74

Added lines #L73 - L74 were not covered by tests

await SwitchProjectsToNightlyPreview(projectPaths);
}
}

Check warning on line 78 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L76-L78

Added lines #L76 - L78 were not covered by tests

public async Task SwitchToPreRc(CommandLineArgs commandLineArgs)
{
var solutionPaths = GetSolutionPaths(commandLineArgs);

Check warning on line 82 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L81-L82

Added lines #L81 - L82 were not covered by tests

if (solutionPaths.Any())
{
await SwitchNpmPackageVersionsOfSolutionsToPreRc(solutionPaths);
}

Check warning on line 87 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L85-L87

Added lines #L85 - L87 were not covered by tests
else
{
await SwitchNpmPackageVersionsOfProjectsToPreRc(GetProjectPaths(commandLineArgs));
}
}

Check warning on line 92 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L89-L92

Added lines #L89 - L92 were not covered by tests

private async Task SwitchProjectsToPreview(List<string> projects)
{
Expand Down Expand Up @@ -88,22 +134,6 @@
}
}

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)
Expand Down Expand Up @@ -156,22 +186,6 @@
}
}

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)
Expand Down Expand Up @@ -220,6 +234,38 @@
}
}
}

private async Task SwitchNpmPackageVersionsOfProjectsToPreRc(List<string> projects)
{

Check warning on line 239 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L239

Added line #L239 was not covered by tests
foreach (var project in projects)
{
var folder = Path.GetDirectoryName(project);

Check warning on line 242 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L241-L242

Added lines #L241 - L242 were not covered by tests

await _npmPackagesUpdater.Update(
folder,
includePreRc: true);
}
}

Check warning on line 248 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L244-L248

Added lines #L244 - L248 were not covered by tests

private async Task SwitchNpmPackageVersionsOfSolutionsToPreRc(List<string> solutionPaths)
{

Check warning on line 251 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L251

Added line #L251 was not covered by tests
foreach (var solutionPath in solutionPaths)
{
var solutionFolder = Path.GetDirectoryName(solutionPath);
var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder);

Check warning on line 255 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L253-L255

Added lines #L253 - L255 were not covered by tests

await _npmPackagesUpdater.Update(
solutionFolder,
includePreRc: true);

Check warning on line 259 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L257-L259

Added lines #L257 - L259 were not covered by tests

if (solutionAngularFolder != null)
{
await _npmPackagesUpdater.Update(
solutionAngularFolder,
includePreRc: true);
}
}
}

Check warning on line 268 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs#L262-L268

Added lines #L262 - L268 were not covered by tests

private List<string> GetSolutionPaths(CommandLineArgs commandLineArgs)
{
Expand Down