|
|
|
@ -17,8 +17,10 @@ using Volo.Abp.Cli.Http; |
|
|
|
using Volo.Abp.Cli.ProjectBuilding; |
|
|
|
using Volo.Abp.Cli.ProjectBuilding.Files; |
|
|
|
using Volo.Abp.Cli.ProjectBuilding.Templates.MvcModule; |
|
|
|
using Volo.Abp.Cli.ProjectModification.Events; |
|
|
|
using Volo.Abp.Cli.Utils; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.EventBus.Local; |
|
|
|
using Volo.Abp.Json; |
|
|
|
|
|
|
|
namespace Volo.Abp.Cli.ProjectModification; |
|
|
|
@ -33,6 +35,7 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
public NewCommand NewCommand { get; } |
|
|
|
public BundleCommand BundleCommand { get; } |
|
|
|
public ICmdHelper CmdHelper { get; } |
|
|
|
public ILocalEventBus LocalEventBus { get; } |
|
|
|
|
|
|
|
protected IJsonSerializer JsonSerializer { get; } |
|
|
|
protected ProjectNugetPackageAdder ProjectNugetPackageAdder { get; } |
|
|
|
@ -62,7 +65,8 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
NewCommand newCommand, |
|
|
|
BundleCommand bundleCommand, |
|
|
|
CliHttpClientFactory cliHttpClientFactory, |
|
|
|
ICmdHelper cmdHelper) |
|
|
|
ICmdHelper cmdHelper, |
|
|
|
ILocalEventBus localEventBus) |
|
|
|
{ |
|
|
|
JsonSerializer = jsonSerializer; |
|
|
|
ProjectNugetPackageAdder = projectNugetPackageAdder; |
|
|
|
@ -79,6 +83,7 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
NewCommand = newCommand; |
|
|
|
BundleCommand = bundleCommand; |
|
|
|
CmdHelper = cmdHelper; |
|
|
|
LocalEventBus = localEventBus; |
|
|
|
_cliHttpClientFactory = cliHttpClientFactory; |
|
|
|
Logger = NullLogger<SolutionModuleAdder>.Instance; |
|
|
|
} |
|
|
|
@ -95,7 +100,11 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
Check.NotNull(solutionFile, nameof(solutionFile)); |
|
|
|
Check.NotNull(moduleName, nameof(moduleName)); |
|
|
|
|
|
|
|
await PublishEventAsync(1, "Retriving module info..."); |
|
|
|
var module = await GetModuleInfoAsync(moduleName, newTemplate, newProTemplate); |
|
|
|
|
|
|
|
|
|
|
|
await PublishEventAsync(2, "Removing incompatible packages from module..."); |
|
|
|
module = RemoveIncompatiblePackages(module, version); |
|
|
|
|
|
|
|
Logger.LogInformation($"Installing module '{module.Name}' to the solution '{Path.GetFileNameWithoutExtension(solutionFile)}'"); |
|
|
|
@ -107,14 +116,20 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
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); |
|
|
|
|
|
|
|
await PublishEventAsync(6, $"Deleting incompatible projects from the module source code"); |
|
|
|
await RemoveUnnecessaryProjectsAsync(Path.GetDirectoryName(solutionFile), module, projectFiles); |
|
|
|
|
|
|
|
if (addSourceCodeToSolutionFile) |
|
|
|
{ |
|
|
|
await PublishEventAsync(7, $"Adding module to solution file"); |
|
|
|
await SolutionFileModifier.AddModuleToSolutionFileAsync(module, solutionFile); |
|
|
|
} |
|
|
|
|
|
|
|
await PublishEventAsync(8, $"Changing nuget references to local references"); |
|
|
|
if (newTemplate || newProTemplate) |
|
|
|
{ |
|
|
|
await NugetPackageToLocalReferenceConverter.Convert(module, solutionFile, $"{module.Name}."); |
|
|
|
@ -133,7 +148,7 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
|
|
|
|
await RunBundleForBlazorAsync(projectFiles, module); |
|
|
|
|
|
|
|
ModifyDbContext(projectFiles, module, skipDbMigrations); |
|
|
|
await ModifyDbContext(projectFiles, module, skipDbMigrations); |
|
|
|
|
|
|
|
var documentationLink = module.GetFirstDocumentationLinkOrNull(); |
|
|
|
if (documentationLink != null) |
|
|
|
@ -144,6 +159,14 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
return module; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task PublishEventAsync(int currentStep, string message) |
|
|
|
{ |
|
|
|
await LocalEventBus.PublishAsync(new ModuleInstallingProgressEvent { |
|
|
|
CurrentStep = currentStep, |
|
|
|
Message = message |
|
|
|
}, false); |
|
|
|
} |
|
|
|
|
|
|
|
private ModuleWithMastersInfo RemoveIncompatiblePackages(ModuleWithMastersInfo module, string version) |
|
|
|
{ |
|
|
|
module.NugetPackages.RemoveAll(np => IsPackageInCompatible(np.MinVersion, np.MaxVersion, version)); |
|
|
|
@ -195,6 +218,8 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await PublishEventAsync(10, $"Running bundle command for Blazor"); |
|
|
|
|
|
|
|
var args = new CommandLineArgs("bundle"); |
|
|
|
|
|
|
|
args.Options.Add(BundleCommand.Options.WorkingDirectory.Short, Path.GetDirectoryName(blazorProject)); |
|
|
|
@ -381,6 +406,8 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
|
|
|
|
if (!angularPackages.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
await PublishEventAsync(5, $"Adding angular package reference"); |
|
|
|
|
|
|
|
foreach (var npmPackage in angularPackages) |
|
|
|
{ |
|
|
|
await ProjectNpmPackageAdder.AddAngularPackageAsync(angularPath, npmPackage); |
|
|
|
@ -398,6 +425,8 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await PublishEventAsync(9, $"Adding angular source code"); |
|
|
|
|
|
|
|
if (newTemplate) |
|
|
|
{ |
|
|
|
MoveAngularFolderInNewTemplate(modulesFolderInSolution, moduleName); |
|
|
|
@ -517,6 +546,7 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
{ |
|
|
|
var webPackagesWillBeAddedToBlazorServerProject = SouldWebPackagesBeAddedToBlazorServerProject(module, projectFiles); |
|
|
|
|
|
|
|
await PublishEventAsync(3, "Adding nuget package references"); |
|
|
|
foreach (var nugetPackage in module.NugetPackages) |
|
|
|
{ |
|
|
|
var isProjectTiered = await IsProjectTiered(projectFiles); |
|
|
|
@ -553,9 +583,12 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
|
|
|
|
if (!mvcNpmPackages.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
|
|
|
|
var targetProjects = ProjectFinder.FindNpmTargetProjectFile(projectFiles); |
|
|
|
if (targetProjects.Any()) |
|
|
|
{ |
|
|
|
await PublishEventAsync(4, "Adding npm package references for MVC"); |
|
|
|
|
|
|
|
NpmGlobalPackagesChecker.Check(); |
|
|
|
|
|
|
|
foreach (var targetProject in targetProjects) |
|
|
|
@ -586,7 +619,7 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
return isBlazorServerProject && module.NugetPackages.All(np => np.Target != NuGetPackageTarget.BlazorServer && np.TieredTarget != NuGetPackageTarget.BlazorServer); |
|
|
|
} |
|
|
|
|
|
|
|
protected void ModifyDbContext(string[] projectFiles, ModuleInfo module, bool skipDbMigrations = false) |
|
|
|
protected async Task ModifyDbContext(string[] projectFiles, ModuleInfo module, bool skipDbMigrations = false) |
|
|
|
{ |
|
|
|
if (string.IsNullOrWhiteSpace(module.EfCoreConfigureMethodName)) |
|
|
|
{ |
|
|
|
@ -622,6 +655,8 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await PublishEventAsync(10, $"Adding Configuration to EfCore DbContext"); |
|
|
|
|
|
|
|
var addedNewBuilder = |
|
|
|
DbContextFileBuilderConfigureAdder.Add(dbContextFile, module.EfCoreConfigureMethodName); |
|
|
|
|
|
|
|
@ -629,9 +664,11 @@ public class SolutionModuleAdder : ITransientDependency |
|
|
|
{ |
|
|
|
if (addedNewBuilder) |
|
|
|
{ |
|
|
|
await PublishEventAsync(11, $"Creating a new migration"); |
|
|
|
EfCoreMigrationManager.AddMigration(dbMigrationsProject, module.Name); |
|
|
|
} |
|
|
|
|
|
|
|
await PublishEventAsync(12, $"Running migrator"); |
|
|
|
RunMigrator(projectFiles); |
|
|
|
} |
|
|
|
} |
|
|
|
|