Browse Source

Merge pull request #18937 from abpframework/masum/cli-npm-updater

Update filterKey for prerc case during get lastest version of package
pull/18944/head
Yunus Emre Kalkan 3 years ago
committed by GitHub
parent
commit
dfecc532f1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 36
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

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

@ -3,7 +3,6 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -11,8 +10,6 @@ using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NuGet.Versioning; using NuGet.Versioning;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Commands;
using Volo.Abp.Cli.Http; using Volo.Abp.Cli.Http;
using Volo.Abp.Cli.LIbs; using Volo.Abp.Cli.LIbs;
using Volo.Abp.Cli.Utils; using Volo.Abp.Cli.Utils;
@ -84,7 +81,7 @@ public class NpmPackagesUpdater : ITransientDependency
switchToStable, switchToStable,
version, version,
includePreRc); includePreRc);
packagesUpdated.TryAdd(file, updated); packagesUpdated.TryAdd(file, updated);
} }
@ -94,14 +91,7 @@ public class NpmPackagesUpdater : ITransientDependency
{ {
var fileDirectory = Path.GetDirectoryName(file.Key).EnsureEndsWith(Path.DirectorySeparatorChar); var fileDirectory = Path.GetDirectoryName(file.Key).EnsureEndsWith(Path.DirectorySeparatorChar);
if (await NpmrcFileExistAsync(fileDirectory)) RunYarn(fileDirectory);
{
RunNpmInstall(fileDirectory);
}
else
{
RunYarn(fileDirectory);
}
if (!IsAngularProject(fileDirectory)) if (!IsAngularProject(fileDirectory))
{ {
@ -128,6 +118,7 @@ public class NpmPackagesUpdater : ITransientDependency
var fileName = Path.Combine(directoryName, ".npmrc"); var fileName = Path.Combine(directoryName, ".npmrc");
var abpRegistry = "@abp:registry=https://www.myget.org/F/abp-nightly/npm"; var abpRegistry = "@abp:registry=https://www.myget.org/F/abp-nightly/npm";
var voloRegistry = "@volo:registry=https://www.myget.org/F/abp-commercial-npm-nightly/npm"; var voloRegistry = "@volo:registry=https://www.myget.org/F/abp-commercial-npm-nightly/npm";
var volosoftRegistry = "@volosoft:registry=https://www.myget.org/F/abp-commercial-npm-nightly/npm";
if (await NpmrcFileExistAsync(directoryName)) if (await NpmrcFileExistAsync(directoryName))
{ {
@ -138,11 +129,16 @@ public class NpmPackagesUpdater : ITransientDependency
fileContent += Environment.NewLine + abpRegistry; fileContent += Environment.NewLine + abpRegistry;
} }
if(!fileContent.Contains(voloRegistry)) if (!fileContent.Contains(voloRegistry))
{ {
fileContent += Environment.NewLine + voloRegistry; fileContent += Environment.NewLine + voloRegistry;
} }
if (!fileContent.Contains(volosoftRegistry))
{
fileContent += volosoftRegistry;
}
File.WriteAllText(fileName, fileContent); File.WriteAllText(fileName, fileContent);
return; return;
@ -152,6 +148,7 @@ public class NpmPackagesUpdater : ITransientDependency
sw.WriteLine(abpRegistry); sw.WriteLine(abpRegistry);
sw.WriteLine(voloRegistry); sw.WriteLine(voloRegistry);
sw.WriteLine(volosoftRegistry);
} }
private static bool IsAngularProject(string fileDirectory) private static bool IsAngularProject(string fileDirectory)
@ -272,7 +269,7 @@ public class NpmPackagesUpdater : ITransientDependency
protected virtual async Task<string> GetLatestVersion(JProperty package, bool includeReleaseCandidates = false, bool includePreviews = false, string workingDirectory = null, bool includePreRc = false) protected virtual async Task<string> GetLatestVersion(JProperty package, bool includeReleaseCandidates = false, bool includePreviews = false, string workingDirectory = null, bool includePreRc = false)
{ {
var postfix = includePreviews ? "(preview)" : (includePreRc ? "(prerc)" : string.Empty); var postfix = includePreviews || includePreRc ? "(preview)" : string.Empty;
var key = package.Name + postfix; var key = package.Name + postfix;
if (_fileVersionStorage.ContainsKey(key)) if (_fileVersionStorage.ContainsKey(key))
@ -286,7 +283,8 @@ public class NpmPackagesUpdater : ITransientDependency
if (includePreRc) if (includePreRc)
{ {
newVersion = versionList.FirstOrDefault(v => v.Contains("-prerc")); var filterKey = $"-preview{DateTime.Now.ToString("yyyyMMdd")}";
newVersion = versionList.Where(f => f.Contains(filterKey)).OrderBy(o => o).FirstOrDefault();
} }
else if (includePreviews) else if (includePreviews)
{ {
@ -329,8 +327,12 @@ public class NpmPackagesUpdater : ITransientDependency
var properties = dependencies.Properties().ToList(); var properties = dependencies.Properties().ToList();
abpPackages abpPackages
.AddRange(properties.Where(p => p.Name.StartsWith("@abp/") || p.Name.StartsWith("@volo/")) .AddRange(
.ToList()); properties.Where(
p => p.Name.StartsWith("@abp/")
|| p.Name.StartsWith("@volo/")
|| p.Name.StartsWith("@volosoft/")).ToList()
);
} }
return abpPackages; return abpPackages;

Loading…
Cancel
Save