Skip to content

Commit 67c5abb

Browse files
committed
implementation of lepton-x version argument of update command
1 parent c814676 commit 67c5abb

File tree

3 files changed

+79
-27
lines changed

3 files changed

+79
-27
lines changed

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
4242

4343
if (updateNuget || !updateNpm)
4444
{
45-
await UpdateNugetPackages(commandLineArgs, directory, version);
45+
await UpdateNugetPackages(commandLineArgs, directory, version, leptonXVersion);
4646
}
4747

4848
if (updateNpm || !updateNuget)
4949
{
50-
await UpdateNpmPackages(directory, version);
50+
await UpdateNpmPackages(directory, version, leptonXVersion);
5151
}
5252
}
5353

54-
private async Task UpdateNpmPackages(string directory, string version)
54+
private async Task UpdateNpmPackages(string directory, string version, string leptonXVersion)
5555
{
56-
await _npmPackagesUpdater.Update(directory, version: version);
56+
await _npmPackagesUpdater.Update(directory, version: version, leptonXVersion: leptonXVersion);
5757
}
5858

59-
private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string directory, string version)
59+
private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string directory, string version, string leptonXVersion)
6060
{
6161
var solutions = new List<string>();
6262
var givenSolution = commandLineArgs.Options.GetOrNull(Options.SolutionName.Short, Options.SolutionName.Long);
@@ -78,7 +78,7 @@ private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string d
7878
{
7979
var solutionName = Path.GetFileName(solution).RemovePostFix(".sln");
8080

81-
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, checkAll: checkAll, version: version);
81+
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, checkAll: checkAll, version: version, leptonXVersion: leptonXVersion);
8282

8383
Logger.LogInformation("Volo packages are updated in {SolutionName} solution", solutionName);
8484
}
@@ -91,7 +91,7 @@ private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string d
9191
{
9292
var projectName = Path.GetFileName(project).RemovePostFix(".csproj");
9393

94-
await _nugetPackagesVersionUpdater.UpdateProjectAsync(project, checkAll: checkAll, version: version);
94+
await _nugetPackagesVersionUpdater.UpdateProjectAsync(project, checkAll: checkAll, version: version, leptonXVersion: leptonXVersion);
9595

9696
Logger.LogInformation("Volo packages are updated in {ProjectName} project", projectName);
9797
return;

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public NpmPackagesUpdater(
5050

5151
public async Task Update(string rootDirectory, bool includePreviews = false,
5252
bool includeReleaseCandidates = false,
53-
bool switchToStable = false, string version = null, bool includePreRc = false)
53+
bool switchToStable = false, string version = null, string leptonXVersion = null, bool includePreRc = false)
5454
{
5555
var fileList = _packageJsonFileFinder.Find(rootDirectory);
5656

@@ -80,6 +80,7 @@ async Task UpdateAsync(string file)
8080
var updated = await UpdatePackagesInFile(file, includePreviews, includeReleaseCandidates,
8181
switchToStable,
8282
version,
83+
leptonXVersion,
8384
includePreRc);
8485

8586
packagesUpdated.TryAdd(file, updated);
@@ -162,10 +163,11 @@ protected virtual async Task<bool> UpdatePackagesInFile(
162163
bool includeReleaseCandidates = false,
163164
bool switchToStable = false,
164165
string specifiedVersion = null,
166+
string specifiedLeptonXVersion = null,
165167
bool includePreRc = false)
166168
{
167169
var packagesUpdated = false;
168-
var fileContent = File.ReadAllText(filePath);
170+
var fileContent = await File.ReadAllTextAsync(filePath);
169171
var packageJson = JObject.Parse(fileContent);
170172
var abpPackages = GetAbpPackagesFromPackageJson(packageJson);
171173

@@ -177,7 +179,7 @@ protected virtual async Task<bool> UpdatePackagesInFile(
177179
foreach (var abpPackage in abpPackages)
178180
{
179181
var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, includeReleaseCandidates,
180-
switchToStable, specifiedVersion, includePreRc);
182+
switchToStable, specifiedVersion, specifiedLeptonXVersion, includePreRc);
181183

182184
if (updated)
183185
{
@@ -187,7 +189,7 @@ protected virtual async Task<bool> UpdatePackagesInFile(
187189

188190
var updatedContent = packageJson.ToString(Formatting.Indented);
189191

190-
File.WriteAllText(filePath, updatedContent);
192+
await File.WriteAllTextAsync(filePath, updatedContent);
191193

192194
return packagesUpdated;
193195
}
@@ -199,6 +201,7 @@ protected virtual async Task<bool> TryUpdatingPackage(
199201
bool includeReleaseCandidates = false,
200202
bool switchToStable = false,
201203
string specifiedVersion = null,
204+
string specifiedLeptonXVersion = null,
202205
bool includePreRc = false)
203206
{
204207
var currentVersion = (string)package.Value;
@@ -207,18 +210,36 @@ protected virtual async Task<bool> TryUpdatingPackage(
207210

208211
if (!specifiedVersion.IsNullOrWhiteSpace())
209212
{
210-
if (!SpecifiedVersionExists(specifiedVersion, package))
213+
if (package.Name.Contains("leptonx", StringComparison.InvariantCultureIgnoreCase) && !specifiedLeptonXVersion.IsNullOrWhiteSpace())
211214
{
212-
return false;
213-
}
215+
if (!SpecifiedVersionExists(specifiedLeptonXVersion, package))
216+
{
217+
return false;
218+
}
214219

215-
if (SemanticVersion.Parse(specifiedVersion) <=
216-
SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^")))
217-
{
218-
return false;
220+
if (SemanticVersion.Parse(specifiedLeptonXVersion) <=
221+
SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^")))
222+
{
223+
return false;
224+
}
225+
226+
version = specifiedLeptonXVersion.EnsureStartsWith('^');
219227
}
228+
else
229+
{
230+
if (!SpecifiedVersionExists(specifiedVersion, package))
231+
{
232+
return false;
233+
}
220234

221-
version = specifiedVersion.EnsureStartsWith('^');
235+
if (SemanticVersion.Parse(specifiedVersion) <=
236+
SemanticVersion.Parse(currentVersion.RemovePreFix("~", "^")))
237+
{
238+
return false;
239+
}
240+
241+
version = specifiedVersion.EnsureStartsWith('^');
242+
}
222243
}
223244
else
224245
{

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ public VoloNugetPackagesVersionUpdater(PackageVersionCheckerService packageVersi
2727
Logger = NullLogger<VoloNugetPackagesVersionUpdater>.Instance;
2828
}
2929

30-
public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false, string version = null)
30+
public async Task UpdateSolutionAsync(
31+
string solutionPath,
32+
bool includePreviews = false,
33+
bool includeReleaseCandidates = false,
34+
bool switchToStable = false,
35+
bool checkAll = false,
36+
string version = null,
37+
string leptonXVersion = null)
3138
{
3239
var projectPaths = ProjectFinder.GetProjectFiles(solutionPath);
3340

@@ -58,6 +65,7 @@ async Task UpdateAsync(string filePath)
5865
latestReleaseCandidateVersionInfo.Version,
5966
latestVersionFromMyGet,
6067
version,
68+
leptonXVersion,
6169
latestStableVersions: latestStableVersions);
6270

6371
fs.Seek(0, SeekOrigin.Begin);
@@ -75,7 +83,14 @@ async Task UpdateAsync(string filePath)
7583
}
7684
}
7785

78-
public async Task UpdateProjectAsync(string projectPath, bool includeNightlyPreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false, string version = null)
86+
public async Task UpdateProjectAsync(
87+
string projectPath,
88+
bool includeNightlyPreviews = false,
89+
bool includeReleaseCandidates = false,
90+
bool switchToStable = false,
91+
bool checkAll = false,
92+
string version = null,
93+
string leptonXVersion = null)
7994
{
8095
if (checkAll && version.IsNullOrWhiteSpace())
8196
{
@@ -102,6 +117,7 @@ public async Task UpdateProjectAsync(string projectPath, bool includeNightlyPrev
102117
latestReleaseCandidateVersionInfo.Version,
103118
latestVersionFromMyGet,
104119
version,
120+
leptonXVersion,
105121
latestStableVersions: latestStableVersions);
106122

107123
fs.Seek(0, SeekOrigin.Begin);
@@ -166,6 +182,7 @@ private async Task<string> UpdateVoloPackagesAsync(string content,
166182
SemanticVersion latestNugetReleaseCandidateVersion = null,
167183
string latestMyGetVersion = null,
168184
string specifiedVersion = null,
185+
string specifiedLeptonXVersion = null,
169186
List<PackageVersionCheckerService.LatestStableVersionResult> latestStableVersions = null)
170187
{
171188
string packageId = null;
@@ -222,21 +239,35 @@ private async Task<string> UpdateVoloPackagesAsync(string content,
222239
var leptonXPackageVersion = latestStableVersions?
223240
.FirstOrDefault(v => v.Version.Equals(specifiedVersion, StringComparison.InvariantCultureIgnoreCase))?.LeptonX?.Version;
224241

225-
if ((isLeptonXPackage && string.IsNullOrWhiteSpace(leptonXPackageVersion)) || isStudioPackage)
242+
if ((isLeptonXPackage && string.IsNullOrWhiteSpace(leptonXPackageVersion) && specifiedLeptonXVersion.IsNullOrWhiteSpace()) || isStudioPackage)
226243
{
227244
Logger.LogWarning("Package: {PackageId} could not be updated. Please manually update the package version yourself to prevent version mismatches!", packageId);
228245
continue;
229246
}
230247

231-
var isLeptonXPackageWithVersion = isLeptonXPackage && !string.IsNullOrWhiteSpace(leptonXPackageVersion);
232-
233-
if (isLeptonXPackageWithVersion || await SpecifiedVersionExists(specifiedVersion, packageId))
248+
if (isLeptonXPackage)
234249
{
235-
TryUpdatingPackage(isLeptonXPackageWithVersion ? leptonXPackageVersion : specifiedVersion);
250+
var isLeptonXPackageWithVersion = isLeptonXPackage && !string.IsNullOrWhiteSpace(leptonXPackageVersion);
251+
252+
if (isLeptonXPackageWithVersion || await SpecifiedVersionExists(specifiedLeptonXVersion, packageId))
253+
{
254+
TryUpdatingPackage(specifiedLeptonXVersion ?? leptonXPackageVersion);
255+
}
256+
else
257+
{
258+
Logger.LogWarning($"Package \"{packageId}\" specified version v{specifiedLeptonXVersion} does not exist!");
259+
}
236260
}
237261
else
238262
{
239-
Logger.LogWarning("Package \"{PackageId}\" specified version v{SpecifiedVersion} does not exist!", packageId, specifiedVersion);
263+
if (await SpecifiedVersionExists(specifiedVersion, packageId))
264+
{
265+
TryUpdatingPackage(specifiedVersion);
266+
}
267+
else
268+
{
269+
Logger.LogWarning($"Package \"{packageId}\" specified version v{specifiedVersion} does not exist!");
270+
}
240271
}
241272

242273
void TryUpdatingPackage(string versionToUpdate)

0 commit comments

Comments
 (0)