Merge pull request #16975 from abpframework/volo/issues/14537

Allow LeptonX modules to be added with `add-module` command
pull/16980/head
Yunus Emre Kalkan 2 years ago committed by GitHub
commit 606d72cfc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,9 +63,6 @@ public class AbpCliCoreModule : AbpModule
options.Commands[InstallLibsCommand.Name] = typeof(InstallLibsCommand);
options.Commands[CleanCommand.Name] = typeof(CleanCommand);
options.Commands[CliCommand.Name] = typeof(CliCommand);
options.DisabledModulesToAddToSolution.Add("Volo.Abp.LeptonXTheme.Pro");
options.DisabledModulesToAddToSolution.Add("Volo.Abp.LeptonXTheme.Lite");
});
Configure<AbpCliServiceProxyOptions>(options =>

@ -75,7 +75,19 @@ public class AddModuleCommand : IConsoleCommand, ITransientDependency
var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);
if (version == null)
{
version = SolutionPackageVersionFinder.Find(solutionFile);
if (commandLineArgs.Target.Contains("LeptonX"))
{
version = SolutionPackageVersionFinder.FindByCsprojVersion(solutionFile, excludedKeywords: null, includedKeyword: "LeptonX");
if (version.Contains("*"))
{
version = SolutionPackageVersionFinder.FindByDllVersion(solutionFile, "Volo.Abp.*LeptonX*");
}
}
else
{
version = SolutionPackageVersionFinder.FindByCsprojVersion(solutionFile);
}
}
var moduleInfo = await SolutionModuleAdder.AddAsync(

@ -195,7 +195,7 @@ public abstract class ProjectCreationCommandBase
var microserviceSolutionName = Path.GetFileName(slnPath).RemovePostFix(".sln");
version ??= SolutionPackageVersionFinder.Find(slnPath);
version ??= SolutionPackageVersionFinder.FindByCsprojVersion(slnPath);
solutionName = SolutionName.Parse(microserviceSolutionName, projectName);
outputFolder = MicroserviceServiceTemplateBase.CalculateTargetFolder(outputFolderRoot, solutionName.ProjectName);
uiFramework = uiFramework == UiFramework.NotSpecified ? FindMicroserviceSolutionUiFramework(outputFolderRoot) : uiFramework;

@ -36,6 +36,7 @@ public class SolutionModuleAdder : ITransientDependency
public BundleCommand BundleCommand { get; }
public ICmdHelper CmdHelper { get; }
public ILocalEventBus LocalEventBus { get; }
public SolutionPackageVersionFinder SolutionPackageVersionFinder { get; }
protected IJsonSerializer JsonSerializer { get; }
protected ProjectNugetPackageAdder ProjectNugetPackageAdder { get; }
@ -66,7 +67,8 @@ public class SolutionModuleAdder : ITransientDependency
BundleCommand bundleCommand,
CliHttpClientFactory cliHttpClientFactory,
ICmdHelper cmdHelper,
ILocalEventBus localEventBus)
ILocalEventBus localEventBus,
SolutionPackageVersionFinder solutionPackageVersionFinder)
{
JsonSerializer = jsonSerializer;
ProjectNugetPackageAdder = projectNugetPackageAdder;
@ -84,6 +86,7 @@ public class SolutionModuleAdder : ITransientDependency
BundleCommand = bundleCommand;
CmdHelper = cmdHelper;
LocalEventBus = localEventBus;
SolutionPackageVersionFinder = solutionPackageVersionFinder;
_cliHttpClientFactory = cliHttpClientFactory;
Logger = NullLogger<SolutionModuleAdder>.Instance;
}
@ -103,7 +106,6 @@ public class SolutionModuleAdder : ITransientDependency
await PublishEventAsync(1, "Retrieving module info...");
var module = await GetModuleInfoAsync(moduleName, newTemplate, newProTemplate);
await PublishEventAsync(2, "Removing incompatible packages from module...");
module = RemoveIncompatiblePackages(module, version);
@ -112,10 +114,11 @@ public class SolutionModuleAdder : ITransientDependency
var projectFiles = ProjectFinder.GetProjectFiles(solutionFile);
await AddNugetAndNpmReferences(module, projectFiles, !(newTemplate || newProTemplate));
var modulesFolderInSolution = Path.Combine(Path.GetDirectoryName(solutionFile), "modules");
if (withSourceCode || newTemplate || newProTemplate)
{
var modulesFolderInSolution = Path.Combine(Path.GetDirectoryName(solutionFile), "modules");
await PublishEventAsync(5, $"Downloading source code of {moduleName}");
await DownloadSourceCodesToSolutionFolder(module, modulesFolderInSolution, version, newTemplate, newProTemplate);
@ -150,6 +153,11 @@ public class SolutionModuleAdder : ITransientDependency
await ModifyDbContext(projectFiles, module, skipDbMigrations);
if (module.Name.Contains("LeptonX"))
{
await SetLeptonXAbpVersionsAsync(solutionFile, Path.Combine(modulesFolderInSolution, module.Name));
}
var documentationLink = module.GetFirstDocumentationLinkOrNull();
if (documentationLink != null)
{
@ -159,6 +167,20 @@ public class SolutionModuleAdder : ITransientDependency
return module;
}
private async Task SetLeptonXAbpVersionsAsync(string solutionFile, string combine)
{
var abpVersion = SolutionPackageVersionFinder.FindByCsprojVersion(solutionFile);
var projects = Directory.GetFiles(Path.GetDirectoryName(solutionFile)!, "*.csproj", SearchOption.AllDirectories);
foreach (var project in projects)
{
File.WriteAllText(project,
File.ReadAllText(project).Replace("\"$(AbpVersion)\"", $"\"{abpVersion}\"")
);
}
}
private async Task PublishEventAsync(int currentStep, string message)
{
await LocalEventBus.PublishAsync(new ModuleInstallingProgressEvent {
@ -261,6 +283,11 @@ public class SolutionModuleAdder : ITransientDependency
}
}
if (!projectFiles.Any(p => p.EndsWith(".MauiBlazor.csproj")))
{
projectsToRemove.AddRange(await FindProjectsToRemoveByTarget(module, NuGetPackageTarget.MauiBlazor, isProjectTiered));
}
if (!projectFiles.Any(p => p.EndsWith(".Web.csproj")) && !webPackagesWillBeAddedToBlazorServerProject)
{
projectsToRemove.AddRange(await FindProjectsToRemoveByTarget(module, NuGetPackageTarget.Web, isProjectTiered));

@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml;
using NuGet.Versioning;
using NUglify.Helpers;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
@ -10,13 +12,31 @@ namespace Volo.Abp.Cli.ProjectModification;
public class SolutionPackageVersionFinder : ITransientDependency
{
public string Find(string solutionFile, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX")
public string FindByDllVersion(string solutionFile, string dllName = "Volo.Abp*")
{
var projectFilesUnderSrc = GetProjectFilesOfSolution(solutionFile);
foreach (var projectFile in projectFilesUnderSrc)
{
var dllFiles = Directory.GetFiles(Path.GetDirectoryName(projectFile)!, $"{dllName}.dll", SearchOption.AllDirectories);
if (dllFiles.Any())
{
var version = FileVersionInfo.GetVersionInfo(dllFiles.First());
return $"{version.FileMajorPart}.{version.FileMinorPart}.{version.FileBuildPart}";
}
}
return null;
}
public string FindByCsprojVersion(string solutionFile, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX", string includedKeyword = null)
{
var projectFilesUnderSrc = GetProjectFilesOfSolution(solutionFile);
foreach (var projectFile in projectFilesUnderSrc)
{
var content = File.ReadAllText(projectFile);
if (TryParseVersionFromCsprojViaXmlDocument(content, out var s, packagePrefix, excludedKeywords))
if (TryParseVersionFromCsprojViaXmlDocument(content, out var s, packagePrefix, excludedKeywords, includedKeyword))
{
return s;
}
@ -25,7 +45,7 @@ public class SolutionPackageVersionFinder : ITransientDependency
return null;
}
private static bool TryParseVersionFromCsprojViaXmlDocument(string content, out string version, string packagePrefix, string excludedKeywords)
private static bool TryParseVersionFromCsprojViaXmlDocument(string content, out string version, string packagePrefix, string excludedKeywords, string includedKeyword)
{
var doc = new XmlDocument() { PreserveWhitespace = true };
using (var stream = StreamHelper.GenerateStreamFromString(content))
@ -39,7 +59,12 @@ public class SolutionPackageVersionFinder : ITransientDependency
{
var packageId = node!.Attributes["Include"]?.Value;
if (excludedKeywords.Split(',').Any(ek => packageId!.Contains(ek)))
if (!excludedKeywords.IsNullOrWhiteSpace() && excludedKeywords.Split(',').Any(ek => packageId!.Contains(ek)))
{
continue;
}
if (!includedKeyword.IsNullOrWhiteSpace() && !packageId!.Contains(includedKeyword))
{
continue;
}
@ -65,17 +90,17 @@ public class SolutionPackageVersionFinder : ITransientDependency
}
}
public static bool TryParseVersionFromCsprojFile(string csprojContent, out string version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX")
public static bool TryParseVersionFromCsprojFile(string csprojContent, out string version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX", string includedKeywords = null)
{
return TryParseVersionFromCsprojViaXmlDocument(csprojContent, out version, packagePrefix, excludedKeywords);
return TryParseVersionFromCsprojViaXmlDocument(csprojContent, out version, packagePrefix, excludedKeywords, includedKeywords);
}
public static bool TryParseSemanticVersionFromCsprojFile(string csprojContent, out SemanticVersion version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX")
public static bool TryParseSemanticVersionFromCsprojFile(string csprojContent, out SemanticVersion version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX", string includedKeywords = null)
{
try
{
if (TryParseVersionFromCsprojViaXmlDocument(csprojContent, out var versionText, packagePrefix, excludedKeywords))
if (TryParseVersionFromCsprojViaXmlDocument(csprojContent, out var versionText, packagePrefix, excludedKeywords, includedKeywords))
{
return SemanticVersion.TryParse(versionText, out version);
}

Loading…
Cancel
Save