Browse Source

Cli: pre-release option for update npm command

pull/4782/head
Yunus Emre Kalkan 6 years ago
parent
commit
873ffd49ad
  1. 34
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs
  2. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

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

@ -42,7 +42,7 @@ namespace Volo.Abp.Cli.ProjectModification
Logger = NullLogger<NpmPackagesUpdater>.Instance; Logger = NullLogger<NpmPackagesUpdater>.Instance;
} }
public async Task Update(string rootDirectory, bool includePreviews = false, bool switchToStable = false) public async Task Update(string rootDirectory, bool includePreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false)
{ {
var fileList = _packageJsonFileFinder.Find(rootDirectory); var fileList = _packageJsonFileFinder.Find(rootDirectory);
@ -57,7 +57,7 @@ namespace Volo.Abp.Cli.ProjectModification
async Task UpdateAsync(string file) async Task UpdateAsync(string file)
{ {
var updated = await UpdatePackagesInFile(file, includePreviews, switchToStable); var updated = await UpdatePackagesInFile(file, includePreviews,includeReleaseCandidates, switchToStable);
packagesUpdated.TryAdd(file, updated); packagesUpdated.TryAdd(file, updated);
} }
@ -176,7 +176,10 @@ namespace Volo.Abp.Cli.ProjectModification
return File.Exists(Path.Combine(fileDirectory, "angular.json")); return File.Exists(Path.Combine(fileDirectory, "angular.json"));
} }
protected virtual async Task<bool> UpdatePackagesInFile(string filePath, bool includePreviews = false, protected virtual async Task<bool> UpdatePackagesInFile(
string filePath,
bool includePreviews = false,
bool includeReleaseCandidates = false,
bool switchToStable = false) bool switchToStable = false)
{ {
var packagesUpdated = false; var packagesUpdated = false;
@ -191,7 +194,7 @@ namespace Volo.Abp.Cli.ProjectModification
foreach (var abpPackage in abpPackages) foreach (var abpPackage in abpPackages)
{ {
var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, switchToStable); var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates, switchToStable);
if (updated) if (updated)
{ {
@ -210,18 +213,26 @@ namespace Volo.Abp.Cli.ProjectModification
string filePath, string filePath,
JProperty package, JProperty package,
bool includePreviews = false, bool includePreviews = false,
bool includeReleaseCandidates = false,
bool switchToStable = false) bool switchToStable = false)
{ {
var currentVersion = (string) package.Value; var currentVersion = (string) package.Value;
var version = ""; var version = "";
if (includePreviews || (!switchToStable && currentVersion.Contains("-preview"))) if ((includePreviews || (!switchToStable && currentVersion.Contains("-preview"))) && !includeReleaseCandidates)
{ {
version = "preview"; version = "preview";
} }
else else
{ {
version = await GetLatestVersion(package); if (!switchToStable && currentVersion.Split("-").Length > 1)
{
version = await GetLatestVersion(package, true);
}
else
{
version = await GetLatestVersion(package, includeReleaseCandidates);
}
} }
if (version == currentVersion) if (version == currentVersion)
@ -237,14 +248,21 @@ namespace Volo.Abp.Cli.ProjectModification
} }
protected virtual async Task<string> GetLatestVersion( protected virtual async Task<string> GetLatestVersion(
JProperty package) JProperty package,
bool includeReleaseCandidates = false)
{ {
if (_fileVersionStorage.ContainsKey(package.Name)) if (_fileVersionStorage.ContainsKey(package.Name))
{ {
return _fileVersionStorage[package.Name]; return _fileVersionStorage[package.Name];
} }
var newVersion = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} version"); var versionListAsJson = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} versions");
var versionList = JsonConvert.DeserializeObject<string[]>(versionListAsJson);
var newVersion = includeReleaseCandidates
? versionList.Last()
: versionList.LastOrDefault(v => v.Split("-").Length < 2);
var newVersionWithPrefix = $"~{newVersion}"; var newVersionWithPrefix = $"~{newVersion}";
_fileVersionStorage[package.Name] = newVersionWithPrefix; _fileVersionStorage[package.Name] = newVersionWithPrefix;

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

@ -38,6 +38,7 @@ namespace Volo.Abp.Cli.ProjectModification
await _npmPackagesUpdater.Update( await _npmPackagesUpdater.Update(
solutionFolder, solutionFolder,
false,
true); true);
} }
@ -72,6 +73,7 @@ namespace Volo.Abp.Cli.ProjectModification
await _npmPackagesUpdater.Update( await _npmPackagesUpdater.Update(
solutionFolder, solutionFolder,
false, false,
false,
true); true);
} }

Loading…
Cancel
Save