Browse Source

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

abp update command enhancement(--check-all).
pull/4516/head
Yunus Emre Kalkan 6 years ago
committed by GitHub
parent
commit
a78702de40
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      docs/en/CLI.md
  2. 12
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs
  3. 47
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs
  4. 49
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

1
docs/en/CLI.md

@ -115,6 +115,7 @@ abp update [options]
* `--nuget`: Only updates NuGet packages. * `--nuget`: Only updates NuGet packages.
* `--solution-path` or `-sp`: Specify the solution path. Use the current directory by default * `--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. * `--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 ### add-package

12
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs

@ -63,11 +63,13 @@ namespace Volo.Abp.Cli.Commands
solution = Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories).FirstOrDefault(); solution = Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories).FirstOrDefault();
} }
var checkAll = commandLineArgs.Options.ContainsKey(Options.CheckAll.Long);
if (solution != null) if (solution != null)
{ {
var solutionName = Path.GetFileName(solution).RemovePostFix(".sln"); 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."); Logger.LogInformation($"Volo packages are updated in {solutionName} solution.");
return; return;
@ -79,7 +81,7 @@ namespace Volo.Abp.Cli.Commands
{ {
var projectName = Path.GetFileName(project).RemovePostFix(".csproj"); 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."); Logger.LogInformation($"Volo packages are updated in {projectName} project.");
return; return;
@ -107,6 +109,7 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine("--nuget (Only updates Nuget packages)"); sb.AppendLine("--nuget (Only updates Nuget packages)");
sb.AppendLine("-sp|--solution-path (Specify the solution path)"); sb.AppendLine("-sp|--solution-path (Specify the solution path)");
sb.AppendLine("-sn|--solution-name (Specify the solution name)"); 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("");
sb.AppendLine("Some examples:"); sb.AppendLine("Some examples:");
sb.AppendLine(""); sb.AppendLine("");
@ -149,6 +152,11 @@ namespace Volo.Abp.Cli.Commands
public const string Npm = "npm"; public const string Npm = "npm";
public const string NuGet = "nuget"; public const string NuGet = "nuget";
} }
public static class CheckAll
{
public const string Long = "check-all";
}
} }
} }
} }

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

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -52,34 +53,38 @@ namespace Volo.Abp.Cli.ProjectModification
_npmGlobalPackagesChecker.Check(); _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) Task.WaitAll(fileList.Select(UpdateAsync).ToArray());
{
var fileDirectory = Path.GetDirectoryName(file).EnsureEndsWith(Path.DirectorySeparatorChar); 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.Key));
{
await CreateNpmrcFileAsync(Path.GetDirectoryName(file));
}
else if (switchToStable)
{
await DeleteNpmrcFileAsync(Path.GetDirectoryName(file));
}
} }
else if (switchToStable)
RunYarn(fileDirectory);
if (!IsAngularProject(fileDirectory))
{ {
Thread.Sleep(500); await DeleteNpmrcFileAsync(Path.GetDirectoryName(file.Key));
RunGulp(fileDirectory);
} }
} }
RunYarn(fileDirectory);
if (!IsAngularProject(fileDirectory))
{
Thread.Sleep(500);
RunGulp(fileDirectory);
}
} }
} }

49
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

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

Loading…
Cancel
Save