From a86e58bdead9e996999e49d81c91460e3b909c48 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 14 Jul 2020 12:15:52 +0300 Subject: [PATCH 01/18] cli: rename nightly preview commands --- docs/en/CLI.md | 8 ++++---- .../Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs | 4 ++-- ...eCommand.cs => SwitchFromNightlyToStableCommand.cs} | 8 ++++---- ...htlyPreviewCommand.cs => SwitchToNightlyCommand.cs} | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) rename framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/{SwitchStableCommand.cs => SwitchFromNightlyToStableCommand.cs} (81%) rename framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/{SwitchNightlyPreviewCommand.cs => SwitchToNightlyCommand.cs} (80%) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index 8551d64505..df31e91d71 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -196,12 +196,12 @@ abp generate-proxy --apiUrl https://localhost:44305 --ui angular --module all ### switch-to-preview -You can use this command to switch your project to latest preview version of the ABP framework packages. +You can use this command to switch your project to latest **nightly** preview version of the ABP framework packages. Usage: ````bash -abp switch-to-preview [options] +abp switch-to-nightly [options] ```` #### Options @@ -210,12 +210,12 @@ abp switch-to-preview [options] ### switch-to-stable -If you're using the ABP Framework preview packages, you can switch back to stable version using this command. +If you're using the ABP Framework **nightly** preview packages, you can switch back to stable version using this command. Usage: ````bash -abp switch-to-stable [options] +abp switch-from-nightly-to-stable [options] ```` #### Options diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs index dbffa820c8..4e883ef4bb 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs @@ -31,8 +31,8 @@ namespace Volo.Abp.Cli options.Commands["logout"] = typeof(LogoutCommand); options.Commands["generate-proxy"] = typeof(GenerateProxyCommand); options.Commands["suite"] = typeof(SuiteCommand); - options.Commands["switch-to-preview"] = typeof(SwitchNightlyPreviewCommand); - options.Commands["switch-to-stable"] = typeof(SwitchStableCommand); + options.Commands["switch-to-nightly"] = typeof(SwitchToNightlyCommand); + options.Commands["switch-from-nightly-to-stable"] = typeof(SwitchFromNightlyToStableCommand); options.Commands["translate"] = typeof(TranslateCommand); }); } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchStableCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchFromNightlyToStableCommand.cs similarity index 81% rename from framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchStableCommand.cs rename to framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchFromNightlyToStableCommand.cs index 54db7bc082..a4acf871d8 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchStableCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchFromNightlyToStableCommand.cs @@ -6,11 +6,11 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.Commands { - public class SwitchStableCommand : IConsoleCommand, ITransientDependency + public class SwitchFromNightlyToStableCommand : IConsoleCommand, ITransientDependency { private readonly PackageSourceSwitcher _packageSourceSwitcher; - public SwitchStableCommand(PackageSourceSwitcher packageSourceSwitcher) + public SwitchFromNightlyToStableCommand(PackageSourceSwitcher packageSourceSwitcher) { _packageSourceSwitcher = packageSourceSwitcher; } @@ -26,7 +26,7 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine("Usage:"); - sb.AppendLine(" abp switch-to-stable [options]"); + sb.AppendLine(" abp switch-from-nightly-to-stable [options]"); sb.AppendLine(""); sb.AppendLine("Options:"); sb.AppendLine("-sd|--solution-directory"); @@ -41,4 +41,4 @@ namespace Volo.Abp.Cli.Commands return "Switches packages to stable ABP version from preview version."; } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchNightlyPreviewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs similarity index 80% rename from framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchNightlyPreviewCommand.cs rename to framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs index 883ac4db2f..3a22e004c3 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchNightlyPreviewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs @@ -6,11 +6,11 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.Commands { - public class SwitchNightlyPreviewCommand : IConsoleCommand, ITransientDependency + public class SwitchToNightlyCommand : IConsoleCommand, ITransientDependency { private readonly PackageSourceSwitcher _packageSourceSwitcher; - public SwitchNightlyPreviewCommand(PackageSourceSwitcher packageSourceSwitcher) + public SwitchToNightlyCommand(PackageSourceSwitcher packageSourceSwitcher) { _packageSourceSwitcher = packageSourceSwitcher; } @@ -26,8 +26,8 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine("Usage:"); - sb.AppendLine(" abp switch-to-preview [options]"); - sb.AppendLine(""); + sb.AppendLine(" abp switch-to-nightly [options]"); + sb.AppendLine(""); sb.AppendLine("Options:"); sb.AppendLine("-sd|--solution-directory"); sb.AppendLine(""); @@ -41,4 +41,4 @@ namespace Volo.Abp.Cli.Commands return "Switches packages to nightly preview ABP version."; } } -} \ No newline at end of file +} From 31c992fe1749320f1a945e75c2063e3c7b13c83b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 14 Jul 2020 14:02:14 +0300 Subject: [PATCH 02/18] Cli: update option for rc previews --- docs/en/CLI.md | 4 +- .../Volo/Abp/Cli/AbpCliCoreModule.cs | 6 +- .../Cli/Commands/SwitchToNightlyCommand.cs | 8 +-- .../Cli/Commands/SwitchToPreviewCommand.cs | 44 +++++++++++++++ ...bleCommand.cs => SwitchToStableCommand.cs} | 10 ++-- .../Volo/Abp/Cli/NuGet/NuGetService.cs | 4 +- ...eSwitcher.cs => PackagePreviewSwitcher.cs} | 24 ++++++-- .../VoloNugetPackagesVersionUpdater.cs | 55 ++++++++++++++----- 8 files changed, 122 insertions(+), 33 deletions(-) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs rename framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/{SwitchFromNightlyToStableCommand.cs => SwitchToStableCommand.cs} (72%) rename framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/{PackageSourceSwitcher.cs => PackagePreviewSwitcher.cs} (80%) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index df31e91d71..0b26806fd8 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -210,12 +210,12 @@ abp switch-to-nightly [options] ### switch-to-stable -If you're using the ABP Framework **nightly** preview packages, you can switch back to stable version using this command. +If you're using the ABP Framework preview packages, you can switch back to latest stable version using this command. Usage: ````bash -abp switch-from-nightly-to-stable [options] +abp switch-to-stable [options] ```` #### Options diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs index 4e883ef4bb..0244d46c47 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs @@ -1,5 +1,4 @@ -using System; -using System.Text; +using System.Text; using Volo.Abp.Cli.Commands; using Volo.Abp.Domain; using Volo.Abp.IdentityModel; @@ -31,8 +30,9 @@ namespace Volo.Abp.Cli options.Commands["logout"] = typeof(LogoutCommand); options.Commands["generate-proxy"] = typeof(GenerateProxyCommand); options.Commands["suite"] = typeof(SuiteCommand); + options.Commands["switch-to-preview"] = typeof(SwitchToPreviewCommand); + options.Commands["switch-to-stable"] = typeof(SwitchToStableCommand); options.Commands["switch-to-nightly"] = typeof(SwitchToNightlyCommand); - options.Commands["switch-from-nightly-to-stable"] = typeof(SwitchFromNightlyToStableCommand); options.Commands["translate"] = typeof(TranslateCommand); }); } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs index 3a22e004c3..473489990f 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToNightlyCommand.cs @@ -8,16 +8,16 @@ namespace Volo.Abp.Cli.Commands { public class SwitchToNightlyCommand : IConsoleCommand, ITransientDependency { - private readonly PackageSourceSwitcher _packageSourceSwitcher; + private readonly PackagePreviewSwitcher _packagePreviewSwitcher; - public SwitchToNightlyCommand(PackageSourceSwitcher packageSourceSwitcher) + public SwitchToNightlyCommand(PackagePreviewSwitcher packagePreviewSwitcher) { - _packageSourceSwitcher = packageSourceSwitcher; + _packagePreviewSwitcher = packagePreviewSwitcher; } public async Task ExecuteAsync(CommandLineArgs commandLineArgs) { - await _packageSourceSwitcher.SwitchToPreview(commandLineArgs); + await _packagePreviewSwitcher.SwitchToNightlyPreview(commandLineArgs); } public string GetUsageInfo() diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs new file mode 100644 index 0000000000..e6c401a8b5 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToPreviewCommand.cs @@ -0,0 +1,44 @@ +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.ProjectModification; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Cli.Commands +{ + public class SwitchToPreviewCommand : IConsoleCommand, ITransientDependency + { + private readonly PackagePreviewSwitcher _packagePreviewSwitcher; + + public SwitchToPreviewCommand(PackagePreviewSwitcher packagePreviewSwitcher) + { + _packagePreviewSwitcher = packagePreviewSwitcher; + } + + public async Task ExecuteAsync(CommandLineArgs commandLineArgs) + { + await _packagePreviewSwitcher.SwitchToPreview(commandLineArgs); + } + + public string GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp switch-to-preview [options]"); + sb.AppendLine(""); + sb.AppendLine("Options:"); + sb.AppendLine("-sd|--solution-directory"); + sb.AppendLine(""); + sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); + + return sb.ToString(); + } + + public string GetShortDescription() + { + return "Switches packages to preview ABP version."; + } + } +} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchFromNightlyToStableCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToStableCommand.cs similarity index 72% rename from framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchFromNightlyToStableCommand.cs rename to framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToStableCommand.cs index a4acf871d8..d425aed4e5 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchFromNightlyToStableCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToStableCommand.cs @@ -6,18 +6,18 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.Commands { - public class SwitchFromNightlyToStableCommand : IConsoleCommand, ITransientDependency + public class SwitchToStableCommand : IConsoleCommand, ITransientDependency { - private readonly PackageSourceSwitcher _packageSourceSwitcher; + private readonly PackagePreviewSwitcher _packagePreviewSwitcher; - public SwitchFromNightlyToStableCommand(PackageSourceSwitcher packageSourceSwitcher) + public SwitchToStableCommand(PackagePreviewSwitcher packagePreviewSwitcher) { - _packageSourceSwitcher = packageSourceSwitcher; + _packagePreviewSwitcher = packagePreviewSwitcher; } public async Task ExecuteAsync(CommandLineArgs commandLineArgs) { - await _packageSourceSwitcher.SwitchToStable(commandLineArgs); + await _packagePreviewSwitcher.SwitchToStable(commandLineArgs); } public string GetUsageInfo() diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs index 0fd35582bf..8b58ad2d9a 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs @@ -39,7 +39,7 @@ namespace Volo.Abp.Cli.NuGet Logger = NullLogger.Instance; } - public async Task GetLatestVersionOrNullAsync(string packageId, bool includePreviews = false, bool includeNightly = false) + public async Task GetLatestVersionOrNullAsync(string packageId, bool includePreviews = false, bool includeNightly = false, bool includeReleaseCandidates = false) { if (AuthService.IsLoggedIn()) { @@ -80,7 +80,7 @@ namespace Volo.Abp.Cli.NuGet .Versions .Select(SemanticVersion.Parse); - if (!includePreviews && !includeNightly) + if (!includePreviews && !includeNightly && !includeReleaseCandidates) { versions = versions.Where(x => !x.IsPrerelease); } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceSwitcher.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs similarity index 80% rename from framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceSwitcher.cs rename to framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs index f6c89be039..cccd468a25 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceSwitcher.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs @@ -9,26 +9,41 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.ProjectModification { - public class PackageSourceSwitcher : ITransientDependency + public class PackagePreviewSwitcher : ITransientDependency { private readonly PackageSourceAdder _packageSourceAdder; private readonly NpmPackagesUpdater _npmPackagesUpdater; private readonly VoloNugetPackagesVersionUpdater _nugetPackagesVersionUpdater; - public ILogger Logger { get; set; } + public ILogger Logger { get; set; } - public PackageSourceSwitcher(PackageSourceAdder packageSourceAdder, + public PackagePreviewSwitcher(PackageSourceAdder packageSourceAdder, NpmPackagesUpdater npmPackagesUpdater, VoloNugetPackagesVersionUpdater nugetPackagesVersionUpdater) { _packageSourceAdder = packageSourceAdder; _npmPackagesUpdater = npmPackagesUpdater; _nugetPackagesVersionUpdater = nugetPackagesVersionUpdater; - Logger = NullLogger.Instance; + Logger = NullLogger.Instance; } public async Task SwitchToPreview(CommandLineArgs commandLineArgs) { + var solutionPath = GetSolutionPath(commandLineArgs); + var solutionFolder = GetSolutionFolder(commandLineArgs); + + await _nugetPackagesVersionUpdater.UpdateSolutionAsync( + solutionPath, + includeReleaseCandidates: true); + + await _npmPackagesUpdater.Update( + solutionFolder, + true); + } + + public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs) + { + // TODO: Remove this when switched to stable _packageSourceAdder.Add("ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json"); var solutionPath = GetSolutionPath(commandLineArgs); @@ -51,6 +66,7 @@ namespace Volo.Abp.Cli.ProjectModification await _nugetPackagesVersionUpdater.UpdateSolutionAsync( solutionPath, false, + false, true); await _npmPackagesUpdater.Update( diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs index 9661dceddd..21e02faac4 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs @@ -25,23 +25,30 @@ namespace Volo.Abp.Cli.ProjectModification Logger = NullLogger.Instance; } - public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool switchToStable = false, bool checkAll = false) + public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false) { var projectPaths = ProjectFinder.GetProjectFiles(solutionPath); if (checkAll) { - Task.WaitAll(projectPaths.Select(projectPath => UpdateInternalAsync(projectPath, includePreviews, switchToStable)).ToArray()); + Task.WaitAll(projectPaths.Select(projectPath => UpdateInternalAsync(projectPath, includePreviews, includeReleaseCandidates, switchToStable)).ToArray()); } else { - var latestVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core"); + var latestVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates : includeReleaseCandidates); + var latestReleaseCandidateVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates : true); 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); + var updatedContent = await UpdateVoloPackagesAsync(fileContent, + includePreviews, + includeReleaseCandidates, + switchToStable, + latestVersionFromNuget, + latestReleaseCandidateVersionFromNuget, + latestVersionFromMyGet); File.WriteAllText(filePath, updatedContent); } @@ -50,33 +57,47 @@ namespace Volo.Abp.Cli.ProjectModification } } - public async Task UpdateProjectAsync(string projectPath, bool includePreviews = false, bool switchToStable = false, bool checkAll = false) + public async Task UpdateProjectAsync(string projectPath, bool includeNightlyPreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false) { if (checkAll) { - await UpdateInternalAsync(projectPath, includePreviews, switchToStable); + await UpdateInternalAsync(projectPath, includeNightlyPreviews, includeReleaseCandidates, switchToStable); } else { var latestVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core"); + var latestReleaseCandidateVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates : true); var latestVersionFromMyGet = await GetLatestVersionFromMyGet("Volo.Abp.Core"); var fileContent = File.ReadAllText(projectPath); - var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable, latestVersionFromNuget, latestVersionFromMyGet); + + var updatedContent = await UpdateVoloPackagesAsync(fileContent, + includeNightlyPreviews, + includeReleaseCandidates, + switchToStable, + latestVersionFromNuget, + latestReleaseCandidateVersionFromNuget, + 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 includeNightlyPreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false) { var fileContent = File.ReadAllText(projectPath); - var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable); + var updatedContent = await UpdateVoloPackagesAsync(fileContent, includeNightlyPreviews, includeReleaseCandidates, switchToStable); File.WriteAllText(projectPath, updatedContent); } - private async Task UpdateVoloPackagesAsync(string content, bool includePreviews = false, bool switchToStable = false, SemanticVersion latestNugetVersion = null, string latestMyGetVersion = null) + private async Task UpdateVoloPackagesAsync(string content, + bool includeNightlyPreviews = false, + bool includeReleaseCandidates = false, + bool switchToStable = false, + SemanticVersion latestNugetVersion = null, + SemanticVersion latestNugetReleaseCandidateVersion = null, + string latestMyGetVersion = null) { string packageId = null; @@ -108,7 +129,7 @@ namespace Volo.Abp.Cli.ProjectModification Logger.LogDebug("Checking package: \"{0}\" - Current version: {1}", packageId, currentSemanticVersion); - if (includePreviews || (currentVersion.Contains("-preview") && !switchToStable)) + if ((includeNightlyPreviews || (currentVersion.Contains("-preview") && !switchToStable)) && !includeReleaseCandidates) { var latestVersion = latestMyGetVersion ?? await GetLatestVersionFromMyGet(packageId); @@ -124,9 +145,17 @@ namespace Volo.Abp.Cli.ProjectModification } else { - var latestVersion = latestNugetVersion ?? await _nuGetService.GetLatestVersionOrNullAsync(packageId); + SemanticVersion latestVersion; + if (currentSemanticVersion.IsPrerelease && !switchToStable) + { + latestVersion = latestNugetReleaseCandidateVersion ?? await _nuGetService.GetLatestVersionOrNullAsync(packageId, true); + } + else + { + latestVersion = latestNugetVersion ?? await _nuGetService.GetLatestVersionOrNullAsync(packageId, includeReleaseCandidates: includeReleaseCandidates); + } - if (latestVersion != null && (currentVersion.Contains("-preview") || currentSemanticVersion < latestVersion)) + if (latestVersion != null && (currentSemanticVersion.IsPrerelease || currentSemanticVersion < latestVersion)) { Logger.LogInformation("Updating package \"{0}\" from v{1} to v{2}.", packageId, currentSemanticVersion.ToString(), latestVersion.ToString()); versionAttribute.Value = latestVersion.ToString(); From a04a07a55d51c4c78f734312b162cf5159cf2058 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 14 Jul 2020 16:46:11 +0300 Subject: [PATCH 03/18] Cli: GetSourceCommand & NewCommand --preview option --- docs/en/CLI.md | 1 + .../Volo/Abp/Cli/CliService.cs | 2 +- .../Volo/Abp/Cli/Commands/GetSourceCommand.cs | 8 +++++++- .../Volo/Abp/Cli/Commands/NewCommand.cs | 12 +++++++++++ .../ProjectBuilding/AbpIoSourceCodeStore.cs | 20 +++++++++++++------ .../Cli/ProjectBuilding/ISourceCodeStore.cs | 5 +++-- .../ProjectBuilding/ModuleProjectBuilder.cs | 4 +++- .../ProjectBuilding/TemplateProjectBuilder.cs | 4 +++- 8 files changed, 44 insertions(+), 12 deletions(-) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index 0b26806fd8..f7b5ab88aa 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -90,6 +90,7 @@ abp new Acme.BookStore * **`console`**: [Console template](Startup-Templates/Console.md). * `--output-folder` or `-o`: Specifies the output folder. Default value is the current directory. * `--version` or `-v`: Specifies the ABP & template version. It can be a [release tag](https://github.com/abpframework/abp/releases) or a [branch name](https://github.com/abpframework/abp/branches). Uses the latest release if not specified. Most of the times, you will want to use the latest version. +* `--preview`: Use latest pre-release version (Only if `--version ` is not specified and there is at least one pre-release after latest stable version). * `--template-source` or `-ts`: Specifies a custom template source to use to build the project. Local and network sources can be used(Like `D:\local-template` or `https://.../my-template-file.zip`). * `--create-solution-folder` or `-csf`: Specifies if the project will be in a new folder in the output folder or directly the output folder. * `--connection-string` or `-cs`: Overwrites the default connection strings in all `appsettings.json` files. The default connection string is `Server=localhost;Database=MyProjectName;Trusted_Connection=True;MultipleActiveResultSets=true` for EF Core and it is configured to use the SQL Server. If you want to use the EF Core, but need to change the DBMS, you can change it as [described here](Entity-Framework-Core-Other-DBMS.md) (after creating the solution). diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs index 436e169aad..ef6eb79042 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs @@ -158,7 +158,7 @@ namespace Volo.Abp.Cli return await NuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Cli"); case UpdateChannel.Prerelease: - return await NuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Cli", includePreviews: true); + return await NuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Cli", includeReleaseCandidates: true); case UpdateChannel.Nightly: return await NuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Cli", includeNightly: true); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs index 0a6155fa67..7cda59b999 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs @@ -61,7 +61,7 @@ namespace Volo.Abp.Cli.Commands } commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command); - + await _sourceCodeDownloadService.DownloadAsync( commandLineArgs.Target, outputFolder, version, gitHubAbpLocalRepositoryPath, gitHubVoloLocalRepositoryPath, commandLineArgs.Options); } @@ -99,6 +99,7 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine("-o|--output-folder (default: current folder)"); sb.AppendLine("-v|--version (default: latest version)"); + sb.AppendLine("--preview (Use latest pre-release version if there is at least one pre-release after latest stable version)"); sb.AppendLine(""); sb.AppendLine("Examples:"); sb.AppendLine(""); @@ -138,6 +139,11 @@ namespace Volo.Abp.Cli.Commands public const string Short = "v"; public const string Long = "version"; } + + public static class Preview + { + public const string Long = "preview"; + } } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index 8a6d944226..4a713ceb9e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs @@ -62,6 +62,12 @@ namespace Volo.Abp.Cli.Commands Logger.LogInformation("Tiered: yes"); } + var preview = commandLineArgs.Options.ContainsKey(Options.Preview.Long); + if (preview) + { + Logger.LogInformation("Preview: yes if any exist for next version."); + } + var databaseProvider = GetDatabaseProvider(commandLineArgs); if (databaseProvider != DatabaseProvider.NotSpecified) { @@ -218,6 +224,7 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine("-d|--database-provider (if supported by the template)"); sb.AppendLine("-o|--output-folder (default: current folder)"); sb.AppendLine("-v|--version (default: latest version)"); + sb.AppendLine("--preview (Use latest pre-release version if there is at least one pre-release after latest stable version)"); sb.AppendLine("-ts|--template-source (your local or network abp template source)"); sb.AppendLine("-csf|--create-solution-folder (default: true)"); sb.AppendLine("-cs|--connection-string (your database connection string)"); @@ -369,6 +376,11 @@ namespace Volo.Abp.Cli.Commands { public const string Long = "tiered"; } + + public static class Preview + { + public const string Long = "preview"; + } } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs index f221186636..106d7b5bcc 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs @@ -52,10 +52,11 @@ namespace Volo.Abp.Cli.ProjectBuilding string name, string type, string version = null, - string templateSource = null) + string templateSource = null, + bool includePreReleases = false) { DirectoryHelper.CreateIfNotExists(CliPaths.TemplateCache); - var latestVersion = version ?? await GetLatestSourceCodeVersionAsync(name, type); + var latestVersion = version ?? await GetLatestSourceCodeVersionAsync(name, type, null, includePreReleases); if (version == null) { @@ -110,7 +111,8 @@ namespace Volo.Abp.Cli.ProjectBuilding Name = name, Type = type, TemplateSource = templateSource, - Version = version + Version = version, + IncludePreReleases = includePreReleases } ); @@ -122,7 +124,7 @@ namespace Volo.Abp.Cli.ProjectBuilding return new TemplateFile(fileContent, version, latestVersion, nugetVersion); } - private async Task GetLatestSourceCodeVersionAsync(string name, string type, string url = null) + private async Task GetLatestSourceCodeVersionAsync(string name, string type, string url = null, bool includePreReleases = false) { if (url == null) { @@ -137,7 +139,7 @@ namespace Volo.Abp.Cli.ProjectBuilding url, new StringContent( JsonSerializer.Serialize( - new GetLatestSourceCodeVersionDto { Name = name } + new GetLatestSourceCodeVersionDto { Name = name, IncludePreReleases = includePreReleases } ), Encoding.UTF8, MimeTypes.Application.Json @@ -171,7 +173,7 @@ namespace Volo.Abp.Cli.ProjectBuilding url, new StringContent( JsonSerializer.Serialize( - new GetTemplateNugetVersionDto { Name = name, Version = version } + new GetTemplateNugetVersionDto { Name = name, Version = version} ), Encoding.UTF8, MimeTypes.Application.Json @@ -260,11 +262,15 @@ namespace Volo.Abp.Cli.ProjectBuilding public string Type { get; set; } public string TemplateSource { get; set; } + + public bool IncludePreReleases { get; set; } } public class GetLatestSourceCodeVersionDto { public string Name { get; set; } + + public bool IncludePreReleases { get; set; } } public class GetTemplateNugetVersionDto @@ -272,6 +278,8 @@ namespace Volo.Abp.Cli.ProjectBuilding public string Name { get; set; } public string Version { get; set; } + + public bool IncludePreReleases { get; set; } } public class GetVersionResultDto diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ISourceCodeStore.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ISourceCodeStore.cs index de082d4bcf..af03a6095b 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ISourceCodeStore.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ISourceCodeStore.cs @@ -9,7 +9,8 @@ namespace Volo.Abp.Cli.ProjectBuilding string name, string type, [CanBeNull] string version = null, - [CanBeNull] string templateSource = null + [CanBeNull] string templateSource = null, + bool includePreReleases = false ); } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ModuleProjectBuilder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ModuleProjectBuilder.cs index 6a7132769a..17b9585f16 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ModuleProjectBuilder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ModuleProjectBuilder.cs @@ -48,7 +48,9 @@ namespace Volo.Abp.Cli.ProjectBuilding var templateFile = await SourceCodeStore.GetAsync( args.TemplateName, SourceCodeTypes.Module, - args.Version + args.Version, + null, + args.ExtraProperties.ContainsKey(GetSourceCommand.Options.Preview.Long) ); var apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync(); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/TemplateProjectBuilder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/TemplateProjectBuilder.cs index e8ddc804c2..02b26eba39 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/TemplateProjectBuilder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/TemplateProjectBuilder.cs @@ -57,7 +57,8 @@ namespace Volo.Abp.Cli.ProjectBuilding args.TemplateName, SourceCodeTypes.Template, args.Version, - args.TemplateSource + args.TemplateSource, + args.ExtraProperties.ContainsKey(NewCommand.Options.Preview.Long) ); DeveloperApiKeyResult apiKeyResult = null; @@ -119,6 +120,7 @@ namespace Volo.Abp.Cli.ProjectBuilding var options = args.ExtraProperties .Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase)) .Where(x => !x.Key.Equals(NewCommand.Options.Tiered.Long, StringComparison.InvariantCultureIgnoreCase)) + .Where(x => !x.Key.Equals(NewCommand.Options.Preview.Long, StringComparison.InvariantCultureIgnoreCase)) .Where(x => !x.Key.Equals(NewCommand.Options.DatabaseProvider.Long, StringComparison.InvariantCultureIgnoreCase) && !x.Key.Equals(NewCommand.Options.DatabaseProvider.Short, StringComparison.InvariantCultureIgnoreCase)) .Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) && From df11564ac1e5b659407734c8c061b00cfed5217a Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 16 Jul 2020 11:18:35 +0300 Subject: [PATCH 04/18] cli: add-package version option --- .../Volo/Abp/Cli/Commands/AddModuleCommand.cs | 3 +- .../Abp/Cli/Commands/AddPackageCommand.cs | 14 ++++++- .../ProjectNugetPackageAdder.cs | 40 ++++++++++++++----- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs index b37f67fd1a..5e690d8bb0 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs @@ -75,6 +75,7 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(" -s|--solution Specify the solution file explicitly."); sb.AppendLine(" --skip-db-migrations Specify if a new migration will be added or not."); sb.AppendLine(" -sp|--startup-project Relative path to the project folder of the startup project. Default value is the current folder."); + sb.AppendLine(" -v|--version Specify the version of the module. Default is your project's ABP version."); sb.AppendLine(""); sb.AppendLine("Examples:"); sb.AppendLine(""); @@ -152,7 +153,7 @@ namespace Volo.Abp.Cli.Commands public const string Skip = "skip-db-migrations"; } - public static class StartupProject + public static class StartupProject { public const string Short = "sp"; public const string Long = "startup-project"; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs index 03e228f255..7ea20eccf4 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs @@ -34,9 +34,12 @@ namespace Volo.Abp.Cli.Commands ); } + var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long); + await ProjectNugetPackageAdder.AddAsync( GetProjectFile(commandLineArgs), - commandLineArgs.Target + commandLineArgs.Target, + version ); } @@ -55,6 +58,7 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine("Options:"); sb.AppendLine(""); sb.AppendLine(" -p|--project Specify the project file explicitly."); + sb.AppendLine(" -v|--version Specify the version of the package. Default is your project's ABP version or latest ABP version."); sb.AppendLine(""); sb.AppendLine("Examples:"); sb.AppendLine(""); @@ -119,6 +123,12 @@ namespace Volo.Abp.Cli.Commands public const string Short = "p"; public const string Long = "project"; } + + public static class Version + { + public const string Short = "v"; + public const string Long = "version"; + } } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs index a69957a497..5f1e18efbd 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; +using System.Xml; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Http; @@ -40,26 +41,36 @@ namespace Volo.Abp.Cli.ProjectModification Logger = NullLogger.Instance; } - public async Task AddAsync(string projectFile, string packageName) + public async Task AddAsync(string projectFile, string packageName, string version = null) { await AddAsync( projectFile, - await FindNugetPackageInfoAsync(packageName) + await FindNugetPackageInfoAsync(packageName), + version ); } - public Task AddAsync(string projectFile, NugetPackageInfo package) + public Task AddAsync(string projectFile, NugetPackageInfo package, string version = null) { - if (File.ReadAllText(projectFile).Contains($"\"{package.Name}\"")) + var projectFileContent = File.ReadAllText(projectFile); + + if (projectFileContent.Contains($"\"{package.Name}\"")) { return Task.CompletedTask; } + if (version == null) + { + version = GetAbpVersionOrNull(projectFileContent); + } + using (DirectoryHelper.ChangeCurrentDirectory(Path.GetDirectoryName(projectFile))) { Logger.LogInformation($"Installing '{package.Name}' package to the project '{Path.GetFileNameWithoutExtension(projectFile)}'..."); - CmdHelper.Run("dotnet", "add package " + package.Name); + var versionOption = version == null ? "" : $" -v {version}"; + + CmdHelper.Run("dotnet", $"add package {package.Name}{versionOption}"); var moduleFiles = ModuleClassFinder.Find(projectFile, "AbpModule"); if (moduleFiles.Count == 0) @@ -80,11 +91,22 @@ namespace Volo.Abp.Cli.ProjectModification return Task.CompletedTask; } - protected virtual async Task FindNugetPackageInfoAsync(string moduleName) + private string GetAbpVersionOrNull(string projectFileContent) + { + var doc = new XmlDocument() { PreserveWhitespace = true }; + + doc.Load(StreamHelper.GenerateStreamFromString(projectFileContent)); + + var nodes = doc.SelectNodes("/Project/ItemGroup/PackageReference[starts-with(@Include, 'Volo.')]"); + + return nodes?[0]?.Attributes?["Version"]?.Value; + } + + protected virtual async Task FindNugetPackageInfoAsync(string packageName) { using (var client = new CliHttpClient()) { - var url = $"{CliUrls.WwwAbpIo}api/app/nugetPackage/byName/?name=" + moduleName; + var url = $"{CliUrls.WwwAbpIo}api/app/nugetPackage/byName/?name=" + packageName; var response = await client.GetAsync(url); @@ -92,7 +114,7 @@ namespace Volo.Abp.Cli.ProjectModification { if (response.StatusCode == HttpStatusCode.NotFound) { - throw new CliUsageException($"'{moduleName}' nuget package could not be found!"); + throw new CliUsageException($"'{packageName}' nuget package could not be found!"); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response); @@ -103,4 +125,4 @@ namespace Volo.Abp.Cli.ProjectModification } } } -} \ No newline at end of file +} From 873ffd49adb7b63152d6a78d6fd3a99e6832b372 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 16 Jul 2020 11:19:07 +0300 Subject: [PATCH 05/18] Cli: pre-release option for update npm command --- .../ProjectModification/NpmPackagesUpdater.cs | 34 ++++++++++++++----- .../PackagePreviewSwitcher.cs | 2 ++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs index 4730fed899..235f39a34e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs @@ -42,7 +42,7 @@ namespace Volo.Abp.Cli.ProjectModification Logger = NullLogger.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); @@ -57,7 +57,7 @@ namespace Volo.Abp.Cli.ProjectModification async Task UpdateAsync(string file) { - var updated = await UpdatePackagesInFile(file, includePreviews, switchToStable); + var updated = await UpdatePackagesInFile(file, includePreviews,includeReleaseCandidates, switchToStable); packagesUpdated.TryAdd(file, updated); } @@ -176,7 +176,10 @@ namespace Volo.Abp.Cli.ProjectModification return File.Exists(Path.Combine(fileDirectory, "angular.json")); } - protected virtual async Task UpdatePackagesInFile(string filePath, bool includePreviews = false, + protected virtual async Task UpdatePackagesInFile( + string filePath, + bool includePreviews = false, + bool includeReleaseCandidates = false, bool switchToStable = false) { var packagesUpdated = false; @@ -191,7 +194,7 @@ namespace Volo.Abp.Cli.ProjectModification foreach (var abpPackage in abpPackages) { - var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, switchToStable); + var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates, switchToStable); if (updated) { @@ -210,18 +213,26 @@ namespace Volo.Abp.Cli.ProjectModification string filePath, JProperty package, bool includePreviews = false, + bool includeReleaseCandidates = false, bool switchToStable = false) { var currentVersion = (string) package.Value; var version = ""; - if (includePreviews || (!switchToStable && currentVersion.Contains("-preview"))) + if ((includePreviews || (!switchToStable && currentVersion.Contains("-preview"))) && !includeReleaseCandidates) { version = "preview"; } 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) @@ -237,14 +248,21 @@ namespace Volo.Abp.Cli.ProjectModification } protected virtual async Task GetLatestVersion( - JProperty package) + JProperty package, + bool includeReleaseCandidates = false) { if (_fileVersionStorage.ContainsKey(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(versionListAsJson); + + var newVersion = includeReleaseCandidates + ? versionList.Last() + : versionList.LastOrDefault(v => v.Split("-").Length < 2); + var newVersionWithPrefix = $"~{newVersion}"; _fileVersionStorage[package.Name] = newVersionWithPrefix; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs index cccd468a25..f80f9a3c0d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs @@ -38,6 +38,7 @@ namespace Volo.Abp.Cli.ProjectModification await _npmPackagesUpdater.Update( solutionFolder, + false, true); } @@ -72,6 +73,7 @@ namespace Volo.Abp.Cli.ProjectModification await _npmPackagesUpdater.Update( solutionFolder, false, + false, true); } From 2c9f32b3bb88c07bd58fb8000da576cc163a43ea Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 16 Jul 2020 12:18:13 +0300 Subject: [PATCH 06/18] cli: remove abp nightly source when switched to stable --- .../PackagePreviewSwitcher.cs | 11 ++-- ...SourceAdder.cs => PackageSourceManager.cs} | 56 +++++++++++++++++-- 2 files changed, 56 insertions(+), 11 deletions(-) rename framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/{PackageSourceAdder.cs => PackageSourceManager.cs} (55%) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs index f80f9a3c0d..ee76496e32 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs @@ -11,17 +11,17 @@ namespace Volo.Abp.Cli.ProjectModification { public class PackagePreviewSwitcher : ITransientDependency { - private readonly PackageSourceAdder _packageSourceAdder; + private readonly PackageSourceManager _packageSourceManager; private readonly NpmPackagesUpdater _npmPackagesUpdater; private readonly VoloNugetPackagesVersionUpdater _nugetPackagesVersionUpdater; public ILogger Logger { get; set; } - public PackagePreviewSwitcher(PackageSourceAdder packageSourceAdder, + public PackagePreviewSwitcher(PackageSourceManager packageSourceManager, NpmPackagesUpdater npmPackagesUpdater, VoloNugetPackagesVersionUpdater nugetPackagesVersionUpdater) { - _packageSourceAdder = packageSourceAdder; + _packageSourceManager = packageSourceManager; _npmPackagesUpdater = npmPackagesUpdater; _nugetPackagesVersionUpdater = nugetPackagesVersionUpdater; Logger = NullLogger.Instance; @@ -44,8 +44,7 @@ namespace Volo.Abp.Cli.ProjectModification public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs) { - // TODO: Remove this when switched to stable - _packageSourceAdder.Add("ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json"); + _packageSourceManager.Add("ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json"); var solutionPath = GetSolutionPath(commandLineArgs); var solutionFolder = GetSolutionFolder(commandLineArgs); @@ -61,6 +60,8 @@ namespace Volo.Abp.Cli.ProjectModification public async Task SwitchToStable(CommandLineArgs commandLineArgs) { + _packageSourceManager.Remove("ABP Nightly"); + var solutionPath = GetSolutionPath(commandLineArgs); var solutionFolder = GetSolutionFolder(commandLineArgs); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceAdder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs similarity index 55% rename from framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceAdder.cs rename to framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs index 3e651b3bf1..7272a41506 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceAdder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs @@ -7,19 +7,18 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.ProjectModification { - public class PackageSourceAdder: ITransientDependency + public class PackageSourceManager: ITransientDependency { - public ILogger Logger { get; set; } + public ILogger Logger { get; set; } - public PackageSourceAdder() + public PackageSourceManager() { - Logger = NullLogger.Instance; + Logger = NullLogger.Instance; } public void Add(string sourceKey, string sourceValue) { - var nugetConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "NuGet", "NuGet.Config"); + var nugetConfigPath = GetNugetConfigPath(); if (!File.Exists(nugetConfigPath)) { @@ -63,6 +62,51 @@ namespace Volo.Abp.Cli.ProjectModification } } + public void Remove(string sourceKey) + { + var nugetConfigPath = GetNugetConfigPath(); + + if (!File.Exists(nugetConfigPath)) + { + return; + } + + var fileContent = File.ReadAllText(nugetConfigPath); + + if (!fileContent.Contains($"\"{sourceKey}\"")) + { + return; + } + + Logger.LogInformation($"Removing \"{sourceKey}\" from nuget sources..."); + + try + { + var doc = new XmlDocument() { PreserveWhitespace = true }; + + doc.Load(GenerateStreamFromString(fileContent)); + + var nodes = doc.SelectNodes($"/configuration/packageSources[@key='{sourceKey}']"); + + if (nodes != null && nodes.Count > 0) + { + nodes[0].ParentNode.RemoveChild(nodes[0]); + } + + File.WriteAllText(nugetConfigPath, doc.OuterXml); + } + catch + { + Logger.LogWarning($"Removing \"{sourceKey}\" from nuget sources FAILED."); + } + } + + private static string GetNugetConfigPath() + { + return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "NuGet", "NuGet.Config"); + } + private static Stream GenerateStreamFromString(string s) { var stream = new MemoryStream(); From 3747b2b57983d0a250d625981c7a594919a93b48 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 16 Jul 2020 14:36:43 +0300 Subject: [PATCH 07/18] docs module: set latest stable version as latest when there is a prerelease --- .../Pages/Documents/Project/Index.cshtml | 10 +++--- .../Pages/Documents/Project/Index.cshtml.cs | 32 ++++++++++--------- .../Pages/Documents/Search.cshtml.cs | 3 +- .../src/Volo.Docs.Web/Utils/VersionHelper.cs | 11 +++++++ 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 modules/docs/src/Volo.Docs.Web/Utils/VersionHelper.cs diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml index 90a754b1a9..71c7d4790c 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml @@ -53,7 +53,7 @@