From 42690fe66926d5be3ca311eff80f77740fecefa6 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 26 Aug 2022 10:00:00 +0300 Subject: [PATCH] Run abp bundle command after Blazor WASM project creation --- .../Volo/Abp/Cli/Commands/NewCommand.cs | 8 ++++-- .../Commands/ProjectCreationCommandBase.cs | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index cc64d73ff2..183b39ea5f 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.Bundling; using Volo.Abp.Cli.Commands.Services; using Volo.Abp.Cli.LIbs; using Volo.Abp.Cli.ProjectBuilding; @@ -36,8 +37,9 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien AngularPwaSupportAdder angularPwaSupportAdder, InitialMigrationCreator initialMigrationCreator, ThemePackageAdder themePackageAdder, - ILocalEventBus eventBus) - : base(connectionStringProvider, solutionPackageVersionFinder, cmdHelper, installLibsService, angularPwaSupportAdder, initialMigrationCreator, themePackageAdder, eventBus) + ILocalEventBus eventBus, + IBundlingService bundlingService) + : base(connectionStringProvider, solutionPackageVersionFinder, cmdHelper, installLibsService, angularPwaSupportAdder, initialMigrationCreator, themePackageAdder, eventBus, bundlingService) { TemplateProjectBuilder = templateProjectBuilder; TemplateInfoProvider = templateInfoProvider; @@ -92,6 +94,8 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien await RunInstallLibsForWebTemplateAsync(projectArgs); } + await RunBundleForBlazorWasmTemplateAsync(projectArgs); + await ConfigurePwaSupportForAngular(projectArgs); OpenRelatedWebPage(projectArgs, template, isTiered, commandLineArgs); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs index 6bd8a78cc8..83c4ed1dd3 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs @@ -10,6 +10,7 @@ using NuGet.Versioning; using NUglify.Helpers; using Volo.Abp.Cli.ProjectModification; using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.Bundling; using Volo.Abp.Cli.Commands.Services; using Volo.Abp.Cli.LIbs; using Volo.Abp.Cli.ProjectBuilding; @@ -25,6 +26,7 @@ namespace Volo.Abp.Cli.Commands; public abstract class ProjectCreationCommandBase { + private readonly IBundlingService _bundlingService; public ConnectionStringProvider ConnectionStringProvider { get; } public SolutionPackageVersionFinder SolutionPackageVersionFinder { get; } public ICmdHelper CmdHelper { get; } @@ -44,8 +46,10 @@ public abstract class ProjectCreationCommandBase AngularPwaSupportAdder angularPwaSupportAdder, InitialMigrationCreator initialMigrationCreator, ThemePackageAdder themePackageAdder, - ILocalEventBus eventBus) + ILocalEventBus eventBus, + IBundlingService bundlingService) { + _bundlingService = bundlingService; ConnectionStringProvider = connectionStringProvider; SolutionPackageVersionFinder = solutionPackageVersionFinder; CmdHelper = cmdHelper; @@ -392,6 +396,25 @@ public abstract class ProjectCreationCommandBase } } + protected async Task RunBundleForBlazorWasmTemplateAsync(ProjectBuildArgs projectArgs) + { + if (AppTemplateBase.IsAppTemplate(projectArgs.TemplateName) && projectArgs.UiFramework == UiFramework.Blazor) + { + Logger.LogInformation("Generating bundles for Blazor Wasm..."); + + await EventBus.PublishAsync(new ProjectCreationProgressEvent + { + Message = "Generating bundles for Blazor Wasm" + }, false); + + var directory = Path.GetDirectoryName( + Directory.GetFiles(projectArgs.OutputFolder, "*.Blazor.csproj", SearchOption.AllDirectories).First() + ); + + await _bundlingService.BundleAsync(directory, true); + } + } + protected async Task CreateInitialMigrationsAsync(ProjectBuildArgs projectArgs) { if (projectArgs.DatabaseProvider == DatabaseProvider.MongoDb)