Merge pull request #4387 from abpframework/maliming/cli-update-checkall

abp update command enhancement(--check-all).
pull/4453/head
Yunus Emre Kalkan 5 years ago committed by GitHub
commit a78702de40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -63,11 +63,13 @@ namespace Volo.Abp.Cli.Commands
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;
@ -79,7 +81,7 @@ namespace Volo.Abp.Cli.Commands
{
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;
@ -107,6 +109,7 @@ namespace Volo.Abp.Cli.Commands
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("");
@ -149,6 +152,11 @@ namespace Volo.Abp.Cli.Commands
public const string Npm = "npm";
public const string NuGet = "nuget";
}
public static class CheckAll
{
public const string Long = "check-all";
}
}
}
}

@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -52,34 +53,38 @@ namespace Volo.Abp.Cli.ProjectModification
_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);
}
}
}

@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using NuGet.Versioning;
using System.IO;
using System.Linq;
@ -24,19 +25,47 @@ namespace Volo.Abp.Cli.ProjectModification
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)
@ -47,7 +76,7 @@ namespace Volo.Abp.Cli.ProjectModification
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;
@ -81,7 +110,7 @@ namespace Volo.Abp.Cli.ProjectModification
if (includePreviews || (currentVersion.Contains("-preview") && !switchToStable))
{
var latestVersion = await GetLatestVersionFromMyGet(packageId);
var latestVersion = latestMyGetVersion ?? await GetLatestVersionFromMyGet(packageId);
if (currentVersion != latestVersion)
{
@ -95,7 +124,7 @@ namespace Volo.Abp.Cli.ProjectModification
}
else
{
var latestVersion = await _nuGetService.GetLatestVersionOrNullAsync(packageId);
var latestVersion = latestNugetVersion ?? await _nuGetService.GetLatestVersionOrNullAsync(packageId);
if (latestVersion != null && (currentVersion.Contains("-preview") || currentSemanticVersion < latestVersion))
{
@ -109,7 +138,7 @@ namespace Volo.Abp.Cli.ProjectModification
}
}
return await Task.FromResult(doc.OuterXml);
return doc.OuterXml;
}
}
catch (Exception ex)

Loading…
Cancel
Save