Browse Source

Merge pull request #13078 from abpframework/event-publish-on-project-creation

Cli: Publish events on project creation steps
pull/13098/head
Alper Ebiçoğlu 4 years ago
committed by GitHub
parent
commit
e1200127fc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  2. 29
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  3. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Events/ProjectCreationProgressEvent.cs
  4. 17
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/TemplateProjectBuilder.cs

12
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

@ -16,13 +16,14 @@ using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectModification; using Volo.Abp.Cli.ProjectModification;
using Volo.Abp.Cli.Utils; using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Local;
namespace Volo.Abp.Cli.Commands; namespace Volo.Abp.Cli.Commands;
public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransientDependency public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransientDependency
{ {
public const string Name = "new"; public const string Name = "new";
protected TemplateProjectBuilder TemplateProjectBuilder { get; } protected TemplateProjectBuilder TemplateProjectBuilder { get; }
public ITemplateInfoProvider TemplateInfoProvider { get; } public ITemplateInfoProvider TemplateInfoProvider { get; }
@ -34,8 +35,9 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien
IInstallLibsService installLibsService, IInstallLibsService installLibsService,
AngularPwaSupportAdder angularPwaSupportAdder, AngularPwaSupportAdder angularPwaSupportAdder,
InitialMigrationCreator initialMigrationCreator, InitialMigrationCreator initialMigrationCreator,
ThemePackageAdder themePackageAdder) ThemePackageAdder themePackageAdder,
: base(connectionStringProvider, solutionPackageVersionFinder, cmdHelper, installLibsService, angularPwaSupportAdder, initialMigrationCreator, themePackageAdder) ILocalEventBus eventBus)
: base(connectionStringProvider, solutionPackageVersionFinder, cmdHelper, installLibsService, angularPwaSupportAdder, initialMigrationCreator, themePackageAdder, eventBus)
{ {
TemplateProjectBuilder = templateProjectBuilder; TemplateProjectBuilder = templateProjectBuilder;
TemplateInfoProvider = templateInfoProvider; TemplateInfoProvider = templateInfoProvider;
@ -81,10 +83,10 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien
Logger.LogInformation($"'{projectName}' has been successfully created to '{projectArgs.OutputFolder}'"); Logger.LogInformation($"'{projectName}' has been successfully created to '{projectArgs.OutputFolder}'");
ConfigureNpmPackagesForTheme(projectArgs); ConfigureNpmPackagesForTheme(projectArgs);
RunGraphBuildForMicroserviceServiceTemplate(projectArgs); await RunGraphBuildForMicroserviceServiceTemplate(projectArgs);
await CreateInitialMigrationsAsync(projectArgs); await CreateInitialMigrationsAsync(projectArgs);
await RunInstallLibsForWebTemplateAsync(projectArgs); await RunInstallLibsForWebTemplateAsync(projectArgs);
ConfigurePwaSupportForAngular(projectArgs); await ConfigurePwaSupportForAngular(projectArgs);
OpenRelatedWebPage(projectArgs, template, isTiered, commandLineArgs); OpenRelatedWebPage(projectArgs, template, isTiered, commandLineArgs);
} }

29
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs

@ -14,10 +14,12 @@ using Volo.Abp.Cli.Commands.Services;
using Volo.Abp.Cli.LIbs; using Volo.Abp.Cli.LIbs;
using Volo.Abp.Cli.ProjectBuilding; using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.Cli.ProjectBuilding.Building; using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Events;
using Volo.Abp.Cli.ProjectBuilding.Templates.App; using Volo.Abp.Cli.ProjectBuilding.Templates.App;
using Volo.Abp.Cli.ProjectBuilding.Templates.Microservice; using Volo.Abp.Cli.ProjectBuilding.Templates.Microservice;
using Volo.Abp.Cli.ProjectBuilding.Templates.Module; using Volo.Abp.Cli.ProjectBuilding.Templates.Module;
using Volo.Abp.Cli.Utils; using Volo.Abp.Cli.Utils;
using Volo.Abp.EventBus.Local;
namespace Volo.Abp.Cli.Commands; namespace Volo.Abp.Cli.Commands;
@ -29,6 +31,7 @@ public abstract class ProjectCreationCommandBase
public IInstallLibsService InstallLibsService { get; } public IInstallLibsService InstallLibsService { get; }
public AngularPwaSupportAdder AngularPwaSupportAdder { get; } public AngularPwaSupportAdder AngularPwaSupportAdder { get; }
public InitialMigrationCreator InitialMigrationCreator { get; } public InitialMigrationCreator InitialMigrationCreator { get; }
public ILocalEventBus EventBus { get; }
public ILogger<NewCommand> Logger { get; set; } public ILogger<NewCommand> Logger { get; set; }
public ThemePackageAdder ThemePackageAdder { get; } public ThemePackageAdder ThemePackageAdder { get; }
@ -40,7 +43,8 @@ public abstract class ProjectCreationCommandBase
IInstallLibsService installLibsService, IInstallLibsService installLibsService,
AngularPwaSupportAdder angularPwaSupportAdder, AngularPwaSupportAdder angularPwaSupportAdder,
InitialMigrationCreator initialMigrationCreator, InitialMigrationCreator initialMigrationCreator,
ThemePackageAdder themePackageAdder) ThemePackageAdder themePackageAdder,
ILocalEventBus eventBus)
{ {
ConnectionStringProvider = connectionStringProvider; ConnectionStringProvider = connectionStringProvider;
SolutionPackageVersionFinder = solutionPackageVersionFinder; SolutionPackageVersionFinder = solutionPackageVersionFinder;
@ -48,6 +52,7 @@ public abstract class ProjectCreationCommandBase
InstallLibsService = installLibsService; InstallLibsService = installLibsService;
AngularPwaSupportAdder = angularPwaSupportAdder; AngularPwaSupportAdder = angularPwaSupportAdder;
InitialMigrationCreator = initialMigrationCreator; InitialMigrationCreator = initialMigrationCreator;
EventBus = eventBus;
ThemePackageAdder = themePackageAdder; ThemePackageAdder = themePackageAdder;
Logger = NullLogger<NewCommand>.Instance; Logger = NullLogger<NewCommand>.Instance;
@ -201,6 +206,10 @@ public abstract class ProjectCreationCommandBase
protected void ExtractProjectZip(ProjectBuildResult project, string outputFolder) protected void ExtractProjectZip(ProjectBuildResult project, string outputFolder)
{ {
EventBus.PublishAsync(new ProjectCreationProgressEvent {
Message = "Extracting solution to file system"
}, false);
using (var templateFileStream = new MemoryStream(project.ZipContent)) using (var templateFileStream = new MemoryStream(project.ZipContent))
{ {
using (var zipInputStream = new ZipInputStream(templateFileStream)) using (var zipInputStream = new ZipInputStream(templateFileStream))
@ -332,10 +341,14 @@ public abstract class ProjectCreationCommandBase
throw new CliUsageException("The option you provided for Database Provider is invalid!"); throw new CliUsageException("The option you provided for Database Provider is invalid!");
} }
protected virtual void RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs) protected virtual async Task RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs)
{ {
if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(projectArgs.TemplateName)) if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(projectArgs.TemplateName))
{ {
await EventBus.PublishAsync(new ProjectCreationProgressEvent {
Message = "Building the microservice solution"
}, false);
CmdHelper.RunCmd("dotnet build /graphbuild", projectArgs.OutputFolder); CmdHelper.RunCmd("dotnet build /graphbuild", projectArgs.OutputFolder);
} }
} }
@ -348,6 +361,11 @@ public abstract class ProjectCreationCommandBase
MicroserviceServiceTemplateBase.IsMicroserviceTemplate(projectArgs.TemplateName)) MicroserviceServiceTemplateBase.IsMicroserviceTemplate(projectArgs.TemplateName))
{ {
Logger.LogInformation("Installing client-side packages..."); Logger.LogInformation("Installing client-side packages...");
await EventBus.PublishAsync(new ProjectCreationProgressEvent {
Message = "Installing client-side packages"
}, false);
await InstallLibsService.InstallLibsAsync(projectArgs.OutputFolder); await InstallLibsService.InstallLibsAsync(projectArgs.OutputFolder);
} }
} }
@ -384,10 +402,14 @@ public abstract class ProjectCreationCommandBase
return; return;
} }
await EventBus.PublishAsync(new ProjectCreationProgressEvent {
Message = "Creating the initial migration"
}, false);
await InitialMigrationCreator.CreateAsync(Path.GetDirectoryName(efCoreProjectPath), isLayeredTemplate); await InitialMigrationCreator.CreateAsync(Path.GetDirectoryName(efCoreProjectPath), isLayeredTemplate);
} }
protected void ConfigurePwaSupportForAngular(ProjectBuildArgs projectArgs) protected async Task ConfigurePwaSupportForAngular(ProjectBuildArgs projectArgs)
{ {
var isAngular = projectArgs.UiFramework == UiFramework.Angular; var isAngular = projectArgs.UiFramework == UiFramework.Angular;
var isPwa = projectArgs.Pwa; var isPwa = projectArgs.Pwa;
@ -395,6 +417,7 @@ public abstract class ProjectCreationCommandBase
if (isAngular && isPwa) if (isAngular && isPwa)
{ {
Logger.LogInformation("Adding PWA Support to Angular app."); Logger.LogInformation("Adding PWA Support to Angular app.");
AngularPwaSupportAdder.AddPwaSupport(projectArgs.OutputFolder); AngularPwaSupportAdder.AddPwaSupport(projectArgs.OutputFolder);
} }
} }

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Events/ProjectCreationProgressEvent.cs

@ -0,0 +1,6 @@
namespace Volo.Abp.Cli.ProjectBuilding.Events;
public class ProjectCreationProgressEvent
{
public string Message { get; set; }
}

17
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/TemplateProjectBuilder.cs

@ -10,8 +10,10 @@ using Volo.Abp.Cli.Commands;
using Volo.Abp.Cli.Licensing; using Volo.Abp.Cli.Licensing;
using Volo.Abp.Cli.ProjectBuilding.Analyticses; using Volo.Abp.Cli.ProjectBuilding.Analyticses;
using Volo.Abp.Cli.ProjectBuilding.Building; using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Events;
using Volo.Abp.Cli.ProjectBuilding.Templates.App; using Volo.Abp.Cli.ProjectBuilding.Templates.App;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Local;
using Volo.Abp.Json; using Volo.Abp.Json;
namespace Volo.Abp.Cli.ProjectBuilding; namespace Volo.Abp.Cli.ProjectBuilding;
@ -26,6 +28,7 @@ public class TemplateProjectBuilder : IProjectBuilder, ITransientDependency
protected AbpCliOptions Options { get; } protected AbpCliOptions Options { get; }
protected IJsonSerializer JsonSerializer { get; } protected IJsonSerializer JsonSerializer { get; }
protected IApiKeyService ApiKeyService { get; } protected IApiKeyService ApiKeyService { get; }
protected ILocalEventBus EventBus { get; }
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
@ -35,7 +38,8 @@ public class TemplateProjectBuilder : IProjectBuilder, ITransientDependency
IOptions<AbpCliOptions> options, IOptions<AbpCliOptions> options,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IApiKeyService apiKeyService, IApiKeyService apiKeyService,
IConfiguration configuration) IConfiguration configuration,
ILocalEventBus eventBus)
{ {
SourceCodeStore = sourceCodeStore; SourceCodeStore = sourceCodeStore;
TemplateInfoProvider = templateInfoProvider; TemplateInfoProvider = templateInfoProvider;
@ -43,6 +47,7 @@ public class TemplateProjectBuilder : IProjectBuilder, ITransientDependency
Options = options.Value; Options = options.Value;
JsonSerializer = jsonSerializer; JsonSerializer = jsonSerializer;
ApiKeyService = apiKeyService; ApiKeyService = apiKeyService;
EventBus = eventBus;
_configuration = configuration; _configuration = configuration;
Logger = NullLogger<TemplateProjectBuilder>.Instance; Logger = NullLogger<TemplateProjectBuilder>.Instance;
@ -54,6 +59,10 @@ public class TemplateProjectBuilder : IProjectBuilder, ITransientDependency
NormalizeArgs(args, templateInfo); NormalizeArgs(args, templateInfo);
await EventBus.PublishAsync(new ProjectCreationProgressEvent {
Message = "Fetching the solution template"
}, false);
var templateFile = await SourceCodeStore.GetAsync( var templateFile = await SourceCodeStore.GetAsync(
args.TemplateName, args.TemplateName,
SourceCodeTypes.Template, SourceCodeTypes.Template,
@ -116,7 +125,11 @@ public class TemplateProjectBuilder : IProjectBuilder, ITransientDependency
{ {
appTemplateBase.HasDbMigrations = SemanticVersion.Parse(templateFile.Version) < new SemanticVersion(4, 3, 99); appTemplateBase.HasDbMigrations = SemanticVersion.Parse(templateFile.Version) < new SemanticVersion(4, 3, 99);
} }
await EventBus.PublishAsync(new ProjectCreationProgressEvent {
Message = "Preparing the solution according to preferences"
}, false);
TemplateProjectBuildPipelineBuilder.Build(context).Execute(); TemplateProjectBuildPipelineBuilder.Build(context).Execute();
if (!templateInfo.DocumentUrl.IsNullOrEmpty()) if (!templateInfo.DocumentUrl.IsNullOrEmpty())

Loading…
Cancel
Save