Skip to content

Commit

Permalink
Merge pull request #4387 from abpframework/maliming/cli-update-checkall
Browse files Browse the repository at this point in the history
abp update command enhancement(--check-all).
  • Loading branch information
yekalkan authored Jun 22, 2020
2 parents 099f898 + 4401221 commit a78702d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/en/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ abp update [options]
* `--nuget`: Only updates NuGet packages.
* `--solution-path` or `-sp`: Specify the solution path. Use the current directory by default
* `--solution-name` or `-sn`: Specify the solution name. Search `*.sln` files in the directory by default.
* `--check-all`: Check the new version of each package separately. Default is `false`.

### add-package

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string d
solution = Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories).FirstOrDefault();
}

var checkAll = commandLineArgs.Options.ContainsKey(Options.CheckAll.Long);

if (solution != null)
{
var solutionName = Path.GetFileName(solution).RemovePostFix(".sln");

await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, includePreviews);
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, includePreviews, checkAll: checkAll);

Logger.LogInformation($"Volo packages are updated in {solutionName} solution.");
return;
Expand All @@ -79,7 +81,7 @@ private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string d
{
var projectName = Path.GetFileName(project).RemovePostFix(".csproj");

await _nugetPackagesVersionUpdater.UpdateProjectAsync(project, includePreviews);
await _nugetPackagesVersionUpdater.UpdateProjectAsync(project, includePreviews, checkAll: checkAll);

Logger.LogInformation($"Volo packages are updated in {projectName} project.");
return;
Expand Down Expand Up @@ -107,6 +109,7 @@ public string GetUsageInfo()
sb.AppendLine("--nuget (Only updates Nuget packages)");
sb.AppendLine("-sp|--solution-path (Specify the solution path)");
sb.AppendLine("-sn|--solution-name (Specify the solution name)");
sb.AppendLine("--check-all (Check the new version of each package separately)");
sb.AppendLine("");
sb.AppendLine("Some examples:");
sb.AppendLine("");
Expand Down Expand Up @@ -149,6 +152,11 @@ public static class Packages
public const string Npm = "npm";
public const string NuGet = "nuget";
}

public static class CheckAll
{
public const string Long = "check-all";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -52,34 +53,38 @@ public async Task Update(string rootDirectory, bool includePreviews = false, boo

_npmGlobalPackagesChecker.Check();

foreach (var file in fileList)
var packagesUpdated = new ConcurrentDictionary<string, bool>();
async Task UpdateAsync(string file)
{
var packagesUpdated = await UpdatePackagesInFile(file, includePreviews, switchToStable);
var updated = await UpdatePackagesInFile(file, includePreviews, switchToStable);
packagesUpdated.TryAdd(file, updated);
};

if (packagesUpdated)
{
var fileDirectory = Path.GetDirectoryName(file).EnsureEndsWith(Path.DirectorySeparatorChar);
Task.WaitAll(fileList.Select(UpdateAsync).ToArray());

foreach (var file in packagesUpdated.Where(x => x.Value))
{
var fileDirectory = Path.GetDirectoryName(file.Key).EnsureEndsWith(Path.DirectorySeparatorChar);

if (IsAngularProject(fileDirectory))
if (IsAngularProject(fileDirectory))
{
if (includePreviews)
{
if (includePreviews)
{
await CreateNpmrcFileAsync(Path.GetDirectoryName(file));
}
else if (switchToStable)
{
await DeleteNpmrcFileAsync(Path.GetDirectoryName(file));
}
await CreateNpmrcFileAsync(Path.GetDirectoryName(file.Key));
}

RunYarn(fileDirectory);

if (!IsAngularProject(fileDirectory))
else if (switchToStable)
{
Thread.Sleep(500);
RunGulp(fileDirectory);
await DeleteNpmrcFileAsync(Path.GetDirectoryName(file.Key));
}
}

RunYarn(fileDirectory);

if (!IsAngularProject(fileDirectory))
{
Thread.Sleep(500);
RunGulp(fileDirectory);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using NuGet.Versioning;
using System.IO;
using System.Linq;
Expand All @@ -24,19 +25,47 @@ public VoloNugetPackagesVersionUpdater(NuGetService nuGetService, MyGetPackageLi
Logger = NullLogger<VoloNugetPackagesVersionUpdater>.Instance;
}

public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool switchToStable = false)
public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool switchToStable = false, bool checkAll = false)
{
var projectPaths = ProjectFinder.GetProjectFiles(solutionPath);

foreach (var filePath in projectPaths)
if (checkAll)
{
await UpdateInternalAsync(filePath, includePreviews, switchToStable);
Task.WaitAll(projectPaths.Select(projectPath => UpdateInternalAsync(projectPath, includePreviews, switchToStable)).ToArray());
}
else
{
var latestVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core");
var latestVersionFromMyGet = await GetLatestVersionFromMyGet("Volo.Abp.Core");

async Task UpdateAsync(string filePath)
{
var fileContent = File.ReadAllText(filePath);
var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable, latestVersionFromNuget, latestVersionFromMyGet);

File.WriteAllText(filePath, updatedContent);
}

Task.WaitAll(projectPaths.Select(UpdateAsync).ToArray());
}
}

public async Task UpdateProjectAsync(string projectPath, bool includePreviews = false, bool switchToStable = false)
public async Task UpdateProjectAsync(string projectPath, bool includePreviews = false, bool switchToStable = false, bool checkAll = false)
{
await UpdateInternalAsync(projectPath, includePreviews, switchToStable);
if (checkAll)
{
await UpdateInternalAsync(projectPath, includePreviews, switchToStable);
}
else
{
var latestVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core");
var latestVersionFromMyGet = await GetLatestVersionFromMyGet("Volo.Abp.Core");

var fileContent = File.ReadAllText(projectPath);
var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable, latestVersionFromNuget, latestVersionFromMyGet);

File.WriteAllText(projectPath, updatedContent);
}
}

protected virtual async Task UpdateInternalAsync(string projectPath, bool includePreviews = false, bool switchToStable = false)
Expand All @@ -47,7 +76,7 @@ protected virtual async Task UpdateInternalAsync(string projectPath, bool includ
File.WriteAllText(projectPath, updatedContent);
}

private async Task<string> UpdateVoloPackagesAsync(string content, bool includePreviews = false, bool switchToStable = false)
private async Task<string> UpdateVoloPackagesAsync(string content, bool includePreviews = false, bool switchToStable = false, SemanticVersion latestNugetVersion = null, string latestMyGetVersion = null)
{
string packageId = null;

Expand Down Expand Up @@ -81,7 +110,7 @@ private async Task<string> UpdateVoloPackagesAsync(string content, bool includeP

if (includePreviews || (currentVersion.Contains("-preview") && !switchToStable))
{
var latestVersion = await GetLatestVersionFromMyGet(packageId);
var latestVersion = latestMyGetVersion ?? await GetLatestVersionFromMyGet(packageId);

if (currentVersion != latestVersion)
{
Expand All @@ -95,7 +124,7 @@ private async Task<string> UpdateVoloPackagesAsync(string content, bool includeP
}
else
{
var latestVersion = await _nuGetService.GetLatestVersionOrNullAsync(packageId);
var latestVersion = latestNugetVersion ?? await _nuGetService.GetLatestVersionOrNullAsync(packageId);

if (latestVersion != null && (currentVersion.Contains("-preview") || currentSemanticVersion < latestVersion))
{
Expand All @@ -109,7 +138,7 @@ private async Task<string> UpdateVoloPackagesAsync(string content, bool includeP
}
}

return await Task.FromResult(doc.OuterXml);
return doc.OuterXml;
}
}
catch (Exception ex)
Expand Down

0 comments on commit a78702d

Please sign in to comment.