diff --git a/docs/en/cli/index.md b/docs/en/cli/index.md index 38503b73be..a9caa0b6bb 100644 --- a/docs/en/cli/index.md +++ b/docs/en/cli/index.md @@ -342,6 +342,7 @@ Note that this command can upgrade your solution from a previous version, and al * `--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`. * `--version` or `-v`: Specifies the version to use for update. If not specified, latest version is used. +* * `--leptonx-version` or `-lv`: Specifies the LeptonX version to use for update. If not specified, latest version or the version that is compatible with `--version` argument is used. ### clean diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs index ad0992af4e..8c6df3b0b9 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs @@ -38,24 +38,25 @@ public class UpdateCommand : IConsoleCommand, ITransientDependency var directory = commandLineArgs.Options.GetOrNull(Options.SolutionPath.Short, Options.SolutionPath.Long) ?? Directory.GetCurrentDirectory(); var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long); + var leptonXVersion = commandLineArgs.Options.GetOrNull(Options.LeptonXVersion.Short, Options.LeptonXVersion.Long); if (updateNuget || !updateNpm) { - await UpdateNugetPackages(commandLineArgs, directory, version); + await UpdateNugetPackages(commandLineArgs, directory, version, leptonXVersion); } if (updateNpm || !updateNuget) { - await UpdateNpmPackages(directory, version); + await UpdateNpmPackages(directory, version, leptonXVersion); } } - private async Task UpdateNpmPackages(string directory, string version) + private async Task UpdateNpmPackages(string directory, string version, string leptonXVersion) { - await _npmPackagesUpdater.Update(directory, version: version); + await _npmPackagesUpdater.Update(directory, version: version, leptonXVersion: leptonXVersion); } - private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string directory, string version) + private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string directory, string version, string leptonXVersion) { var solutions = new List(); var givenSolution = commandLineArgs.Options.GetOrNull(Options.SolutionName.Short, Options.SolutionName.Long); @@ -77,7 +78,7 @@ public class UpdateCommand : IConsoleCommand, ITransientDependency { var solutionName = Path.GetFileName(solution).RemovePostFix(".sln"); - await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, checkAll: checkAll, version: version); + await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, checkAll: checkAll, version: version, leptonXVersion: leptonXVersion); Logger.LogInformation("Volo packages are updated in {SolutionName} solution", solutionName); } @@ -90,7 +91,7 @@ public class UpdateCommand : IConsoleCommand, ITransientDependency { var projectName = Path.GetFileName(project).RemovePostFix(".csproj"); - await _nugetPackagesVersionUpdater.UpdateProjectAsync(project, checkAll: checkAll, version: version); + await _nugetPackagesVersionUpdater.UpdateProjectAsync(project, checkAll: checkAll, version: version, leptonXVersion: leptonXVersion); Logger.LogInformation("Volo packages are updated in {ProjectName} project", projectName); return; @@ -120,6 +121,7 @@ public class UpdateCommand : IConsoleCommand, ITransientDependency sb.AppendLine("-sn|--solution-name (Specify the solution name)"); sb.AppendLine("--check-all (Check the new version of each package separately)"); sb.AppendLine("-v|--version (default: latest version)"); + sb.AppendLine("-lv|--leptonx-version (default: latest LeptonX version)"); sb.AppendLine(""); sb.AppendLine("Some examples:"); sb.AppendLine(""); @@ -167,5 +169,11 @@ public class UpdateCommand : IConsoleCommand, ITransientDependency public const string Short = "v"; public const string Long = "version"; } + + public static class LeptonXVersion + { + public const string Short = "lv"; + public const string Long = "leptonx-version"; + } } } 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 2c88f1e8c5..d543b43d65 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 @@ -50,7 +50,7 @@ public class NpmPackagesUpdater : ITransientDependency public async Task Update(string rootDirectory, bool includePreviews = false, bool includeReleaseCandidates = false, - bool switchToStable = false, string version = null, bool includePreRc = false) + bool switchToStable = false, string version = null, string leptonXVersion = null, bool includePreRc = false) { var fileList = _packageJsonFileFinder.Find(rootDirectory); @@ -80,6 +80,7 @@ public class NpmPackagesUpdater : ITransientDependency var updated = await UpdatePackagesInFile(file, includePreviews, includeReleaseCandidates, switchToStable, version, + leptonXVersion, includePreRc); packagesUpdated.TryAdd(file, updated); @@ -162,6 +163,7 @@ public class NpmPackagesUpdater : ITransientDependency bool includeReleaseCandidates = false, bool switchToStable = false, string specifiedVersion = null, + string specifiedLeptonXVersion = null, bool includePreRc = false) { var packagesUpdated = false; @@ -177,7 +179,7 @@ public class NpmPackagesUpdater : ITransientDependency foreach (var abpPackage in abpPackages) { var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates, - switchToStable, specifiedVersion, includePreRc); + switchToStable, specifiedVersion, specifiedLeptonXVersion, includePreRc); if (updated) { @@ -188,7 +190,7 @@ public class NpmPackagesUpdater : ITransientDependency var updatedContent = packageJson.ToString(Formatting.Indented); File.WriteAllText(filePath, updatedContent); - + return packagesUpdated; } @@ -199,6 +201,7 @@ public class NpmPackagesUpdater : ITransientDependency bool includeReleaseCandidates = false, bool switchToStable = false, string specifiedVersion = null, + string specifiedLeptonXVersion = null, bool includePreRc = false) { var currentVersion = (string)package.Value; @@ -207,18 +210,36 @@ public class NpmPackagesUpdater : ITransientDependency if (!specifiedVersion.IsNullOrWhiteSpace()) { - if (!SpecifiedVersionExists(specifiedVersion, package)) + if (package.Name.IndexOf("leptonx", StringComparison.InvariantCultureIgnoreCase) > 0 && !specifiedLeptonXVersion.IsNullOrWhiteSpace()) { - return false; - } + if (!SpecifiedVersionExists(specifiedLeptonXVersion, package)) + { + return false; + } - if (SemanticVersion.Parse(specifiedVersion) <= - SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^"))) - { - return false; + if (SemanticVersion.Parse(specifiedLeptonXVersion) <= + SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^"))) + { + return false; + } + + version = specifiedLeptonXVersion.EnsureStartsWith('^'); } + else + { + if (!SpecifiedVersionExists(specifiedVersion, package)) + { + return false; + } - version = specifiedVersion.EnsureStartsWith('^'); + if (SemanticVersion.Parse(specifiedVersion) <= + SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^"))) + { + return false; + } + + version = specifiedVersion.EnsureStartsWith('^'); + } } else { 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 4ece393913..924d6041b1 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 @@ -27,7 +27,14 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency Logger = NullLogger.Instance; } - public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false, string version = null) + public async Task UpdateSolutionAsync( + string solutionPath, + bool includePreviews = false, + bool includeReleaseCandidates = false, + bool switchToStable = false, + bool checkAll = false, + string version = null, + string leptonXVersion = null) { var projectPaths = ProjectFinder.GetProjectFiles(solutionPath); @@ -58,6 +65,7 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency latestReleaseCandidateVersionInfo.Version, latestVersionFromMyGet, version, + leptonXVersion, latestStableVersions: latestStableVersions); fs.Seek(0, SeekOrigin.Begin); @@ -75,7 +83,14 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency } } - public async Task UpdateProjectAsync(string projectPath, bool includeNightlyPreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false, string version = null) + public async Task UpdateProjectAsync( + string projectPath, + bool includeNightlyPreviews = false, + bool includeReleaseCandidates = false, + bool switchToStable = false, + bool checkAll = false, + string version = null, + string leptonXVersion = null) { if (checkAll && version.IsNullOrWhiteSpace()) { @@ -102,6 +117,7 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency latestReleaseCandidateVersionInfo.Version, latestVersionFromMyGet, version, + leptonXVersion, latestStableVersions: latestStableVersions); fs.Seek(0, SeekOrigin.Begin); @@ -166,6 +182,7 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency SemanticVersion latestNugetReleaseCandidateVersion = null, string latestMyGetVersion = null, string specifiedVersion = null, + string specifiedLeptonXVersion = null, List latestStableVersions = null) { string packageId = null; @@ -222,21 +239,35 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency var leptonXPackageVersion = latestStableVersions? .FirstOrDefault(v => v.Version.Equals(specifiedVersion, StringComparison.InvariantCultureIgnoreCase))?.LeptonX?.Version; - if ((isLeptonXPackage && string.IsNullOrWhiteSpace(leptonXPackageVersion)) || isStudioPackage) + if ((isLeptonXPackage && string.IsNullOrWhiteSpace(leptonXPackageVersion) && specifiedLeptonXVersion.IsNullOrWhiteSpace()) || isStudioPackage) { Logger.LogWarning("Package: {PackageId} could not be updated. Please manually update the package version yourself to prevent version mismatches!", packageId); continue; } - var isLeptonXPackageWithVersion = isLeptonXPackage && !string.IsNullOrWhiteSpace(leptonXPackageVersion); - - if (isLeptonXPackageWithVersion || await SpecifiedVersionExists(specifiedVersion, packageId)) + if (isLeptonXPackage) { - TryUpdatingPackage(isLeptonXPackageWithVersion ? leptonXPackageVersion : specifiedVersion); + var isLeptonXPackageWithVersion = isLeptonXPackage && !string.IsNullOrWhiteSpace(leptonXPackageVersion); + + if (isLeptonXPackageWithVersion || await SpecifiedVersionExists(specifiedLeptonXVersion, packageId)) + { + TryUpdatingPackage(specifiedLeptonXVersion ?? leptonXPackageVersion); + } + else + { + Logger.LogWarning($"Package \"{packageId}\" specified version v{specifiedLeptonXVersion} does not exist!"); + } } else { - Logger.LogWarning("Package \"{PackageId}\" specified version v{SpecifiedVersion} does not exist!", packageId, specifiedVersion); + if (await SpecifiedVersionExists(specifiedVersion, packageId)) + { + TryUpdatingPackage(specifiedVersion); + } + else + { + Logger.LogWarning($"Package \"{packageId}\" specified version v{specifiedVersion} does not exist!"); + } } void TryUpdatingPackage(string versionToUpdate)