Browse Source

Merge pull request #17568 from abpframework/EngincanV/cli-commercial-nightly

CLI: Allowing switch to nightly for commercial npm packages
pull/17577/head
İsmail ÇAĞDAŞ 3 years ago
committed by GitHub
parent
commit
f7ce6e4ee2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

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

@ -122,6 +122,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";
if (await NpmrcFileExistAsync(directoryName)) if (await NpmrcFileExistAsync(directoryName))
{ {
@ -132,16 +133,20 @@ public class NpmPackagesUpdater : ITransientDependency
fileContent += Environment.NewLine + abpRegistry; fileContent += Environment.NewLine + abpRegistry;
} }
if(!fileContent.Contains(voloRegistry))
{
fileContent += Environment.NewLine + voloRegistry;
}
File.WriteAllText(fileName, fileContent); File.WriteAllText(fileName, fileContent);
return; return;
} }
using var fs = File.Create(fileName); using var sw = File.CreateText(fileName);
var content = new UTF8Encoding(true) sw.WriteLine(abpRegistry);
.GetBytes(abpRegistry); sw.WriteLine(voloRegistry);
fs.Write(content, 0, content.Length);
} }
private static bool IsAngularProject(string fileDirectory) private static bool IsAngularProject(string fileDirectory)
@ -217,7 +222,7 @@ public class NpmPackagesUpdater : ITransientDependency
(!switchToStable && (currentVersion != null && currentVersion.Contains("-preview")))) && (!switchToStable && (currentVersion != null && currentVersion.Contains("-preview")))) &&
!includeReleaseCandidates) !includeReleaseCandidates)
{ {
version = "preview"; version = await GetLatestVersion(package, includePreviews: includePreviews, workingDirectory: filePath.RemovePostFix("package.json"));
} }
else else
{ {
@ -232,7 +237,6 @@ public class NpmPackagesUpdater : ITransientDependency
} }
} }
if (string.IsNullOrEmpty(version) || version == currentVersion) if (string.IsNullOrEmpty(version) || version == currentVersion)
{ {
return false; return false;
@ -255,28 +259,39 @@ public class NpmPackagesUpdater : ITransientDependency
return version.Split("-", StringSplitOptions.RemoveEmptyEntries).Length > 1; return version.Split("-", StringSplitOptions.RemoveEmptyEntries).Length > 1;
} }
protected virtual async Task<string> GetLatestVersion(JProperty package, bool includeReleaseCandidates = false) protected virtual async Task<string> GetLatestVersion(JProperty package, bool includeReleaseCandidates = false, bool includePreviews = false, string workingDirectory = null)
{ {
if (_fileVersionStorage.ContainsKey(package.Name)) var key = package.Name + (includePreviews ? "(preview)" : string.Empty);
if (_fileVersionStorage.ContainsKey(key))
{ {
return await Task.FromResult(_fileVersionStorage[package.Name]); return await Task.FromResult(_fileVersionStorage[key]);
} }
var versionList = GetPackageVersionList(package); var versionList = GetPackageVersionList(package, workingDirectory);
var newVersion = includeReleaseCandidates string newVersion = string.Empty;
? versionList.First()
: versionList.FirstOrDefault(v => !SemanticVersion.Parse(v).IsPrerelease); if (includePreviews)
{
newVersion = versionList.FirstOrDefault(v => v.Contains("-preview"));
}
else
{
newVersion = includeReleaseCandidates
? versionList.First()
: versionList.FirstOrDefault(v => !SemanticVersion.Parse(v).IsPrerelease);
}
if (string.IsNullOrEmpty(newVersion)) if (string.IsNullOrEmpty(newVersion))
{ {
_fileVersionStorage[package.Name] = newVersion; _fileVersionStorage[key] = newVersion;
return await Task.FromResult(newVersion); return await Task.FromResult(newVersion);
} }
var newVersionWithPrefix = $"~{newVersion}"; var newVersionWithPrefix = $"~{newVersion}";
_fileVersionStorage[package.Name] = newVersionWithPrefix; _fileVersionStorage[key] = newVersionWithPrefix;
return await Task.FromResult(newVersionWithPrefix); return await Task.FromResult(newVersionWithPrefix);
} }
@ -323,9 +338,9 @@ public class NpmPackagesUpdater : ITransientDependency
CmdHelper.RunCmd($"npm install", fileDirectory); CmdHelper.RunCmd($"npm install", fileDirectory);
} }
protected virtual List<string> GetPackageVersionList(JProperty package) protected virtual List<string> GetPackageVersionList(JProperty package, string workingDirectory = null)
{ {
var output = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} versions --json"); var output = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} versions --json", workingDirectory);
var versionListAsJson = ExtractVersions(output); var versionListAsJson = ExtractVersions(output);

Loading…
Cancel
Save