From 88fb380944345f58fcb8053e8a5622432822c7e6 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Thu, 3 Nov 2022 18:08:40 +0300 Subject: [PATCH 1/3] CLI: Make related configurations for theme selection (Angular UI) --- .../Cli/Args/AngularThemeConfigurationArgs.cs | 19 ++++++++++++ .../Volo/Abp/Cli/Commands/NewCommand.cs | 7 +++-- .../Commands/ProjectCreationCommandBase.cs | 18 ++++++++++- .../AngularThemeConfigurer.cs | 30 +++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/AngularThemeConfigurationArgs.cs create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularThemeConfigurer.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/AngularThemeConfigurationArgs.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/AngularThemeConfigurationArgs.cs new file mode 100644 index 00000000000..3422697dba8 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/AngularThemeConfigurationArgs.cs @@ -0,0 +1,19 @@ +using Volo.Abp.Cli.ProjectBuilding.Building; + +namespace Volo.Abp.Cli.Args; + +public class AngularThemeConfigurationArgs +{ + public Theme Theme { get; } + + public string ProjectName { get; } + + public string AngularFolderPath { get; } + + public AngularThemeConfigurationArgs(Theme theme, string projectName, string angularFolderPath) + { + Theme = theme; + ProjectName = projectName; + AngularFolderPath = angularFolderPath; + } +} \ No newline at end of file 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 d104c313eda..8421eb656b8 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 @@ -40,7 +40,8 @@ public NewCommand( ILocalEventBus eventBus, IBundlingService bundlingService, ITemplateInfoProvider templateInfoProvider, - TemplateProjectBuilder templateProjectBuilder) : + TemplateProjectBuilder templateProjectBuilder, + AngularThemeConfigurer angularThemeConfigurer) : base(connectionStringProvider, solutionPackageVersionFinder, cmdHelper, @@ -50,7 +51,8 @@ public NewCommand( initialMigrationCreator, themePackageAdder, eventBus, - bundlingService) + bundlingService, + angularThemeConfigurer) { TemplateInfoProvider = templateInfoProvider; TemplateProjectBuilder = templateProjectBuilder; @@ -95,6 +97,7 @@ public async Task ExecuteAsync(CommandLineArgs commandLineArgs) Logger.LogInformation($"'{projectName}' has been successfully created to '{projectArgs.OutputFolder}'"); + ConfigureAngularJsonForThemeSelection(projectArgs); ConfigureNpmPackagesForTheme(projectArgs); await RunGraphBuildForMicroserviceServiceTemplate(projectArgs); await CreateInitialMigrationsAsync(projectArgs); 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 88e6c7b74fd..70ea71cab8c 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 @@ -38,6 +38,8 @@ public abstract class ProjectCreationCommandBase public ILogger Logger { get; set; } public ThemePackageAdder ThemePackageAdder { get; } + + public AngularThemeConfigurer AngularThemeConfigurer { get; } public ProjectCreationCommandBase( ConnectionStringProvider connectionStringProvider, @@ -49,7 +51,8 @@ public ProjectCreationCommandBase( InitialMigrationCreator initialMigrationCreator, ThemePackageAdder themePackageAdder, ILocalEventBus eventBus, - IBundlingService bundlingService) + IBundlingService bundlingService, + AngularThemeConfigurer angularThemeConfigurer) { _bundlingService = bundlingService; ConnectionStringProvider = connectionStringProvider; @@ -61,6 +64,7 @@ public ProjectCreationCommandBase( InitialMigrationCreator = initialMigrationCreator; EventBus = eventBus; ThemePackageAdder = themePackageAdder; + AngularThemeConfigurer = angularThemeConfigurer; Logger = NullLogger.Instance; } @@ -667,6 +671,18 @@ private void ConfigureNpmPackagesForLeptonTheme(ProjectBuildArgs projectArgs) } } + protected void ConfigureAngularJsonForThemeSelection(ProjectBuildArgs projectArgs) + { + //TODO: do not run if the theme is default + if (projectArgs.Theme.HasValue && projectArgs.UiFramework == UiFramework.Angular) + { + AngularThemeConfigurer.Configure(new AngularThemeConfigurationArgs( + theme: projectArgs.Theme.Value, + projectName: projectArgs.SolutionName.FullName, + angularFolderPath: projectArgs.OutputFolder + Path.DirectorySeparatorChar + "angular")); + } + } + public static class Options { public static class Template diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularThemeConfigurer.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularThemeConfigurer.cs new file mode 100644 index 00000000000..4df9e31d47a --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularThemeConfigurer.cs @@ -0,0 +1,30 @@ +using System; +using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.Utils; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Cli.ProjectModification; + +public class AngularThemeConfigurer : ITransientDependency +{ + private readonly ICmdHelper _cmdHelper; + + public AngularThemeConfigurer(ICmdHelper cmdHelper) + { + _cmdHelper = cmdHelper; + } + + public void Configure(AngularThemeConfigurationArgs args) + { + if (args.ProjectName.IsNullOrEmpty() || args.AngularFolderPath.IsNullOrEmpty()) + { + return; + } + + var command = "npx ng g @abp/ng.schematics:change-theme " + + $"--name {(int)args.Theme} " + + $"--target-project {args.ProjectName}"; + + _cmdHelper.RunCmd(command, workingDirectory: args.AngularFolderPath); + } +} \ No newline at end of file From e2bf648d99ac5d67597fff29261138d03ce95b3e Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 4 Nov 2022 09:17:33 +0300 Subject: [PATCH 2/3] Update ProjectCreationCommandBase.cs --- .../Cli/Commands/ProjectCreationCommandBase.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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 70ea71cab8c..b1aab6c7ca4 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 @@ -19,6 +19,7 @@ using Volo.Abp.Cli.ProjectBuilding.Templates.App; using Volo.Abp.Cli.ProjectBuilding.Templates.Microservice; using Volo.Abp.Cli.ProjectBuilding.Templates.Module; +using Volo.Abp.Cli.ProjectBuilding.Templates.MvcModule; using Volo.Abp.Cli.Utils; using Volo.Abp.EventBus.Local; @@ -673,11 +674,21 @@ private void ConfigureNpmPackagesForLeptonTheme(ProjectBuildArgs projectArgs) protected void ConfigureAngularJsonForThemeSelection(ProjectBuildArgs projectArgs) { - //TODO: do not run if the theme is default - if (projectArgs.Theme.HasValue && projectArgs.UiFramework == UiFramework.Angular) + var isProTemplate = !projectArgs.TemplateName.IsNullOrEmpty() && projectArgs.TemplateName.EndsWith("-pro", StringComparison.OrdinalIgnoreCase); + var theme = projectArgs.Theme; + + var isDefaultTheme = (isProTemplate && theme == AppProTemplate.DefaultTheme) || + (!isProTemplate && theme == AppTemplate.DefaultTheme); + + if (isDefaultTheme || projectArgs.TemplateName == ModuleTemplate.TemplateName) + { + return; + } + + if (theme.HasValue && projectArgs.UiFramework == UiFramework.Angular) { AngularThemeConfigurer.Configure(new AngularThemeConfigurationArgs( - theme: projectArgs.Theme.Value, + theme: theme.Value, projectName: projectArgs.SolutionName.FullName, angularFolderPath: projectArgs.OutputFolder + Path.DirectorySeparatorChar + "angular")); } From c44806af63f31a80e650931b153c2abaa966c585 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 4 Nov 2022 10:59:13 +0300 Subject: [PATCH 3/3] Update ProjectCreationCommandBase.cs --- .../Abp/Cli/Commands/ProjectCreationCommandBase.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 b1aab6c7ca4..0b822f99403 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 @@ -674,9 +674,8 @@ private void ConfigureNpmPackagesForLeptonTheme(ProjectBuildArgs projectArgs) protected void ConfigureAngularJsonForThemeSelection(ProjectBuildArgs projectArgs) { - var isProTemplate = !projectArgs.TemplateName.IsNullOrEmpty() && projectArgs.TemplateName.EndsWith("-pro", StringComparison.OrdinalIgnoreCase); var theme = projectArgs.Theme; - + var isProTemplate = !projectArgs.TemplateName.IsNullOrEmpty() && projectArgs.TemplateName.EndsWith("-pro", StringComparison.OrdinalIgnoreCase); var isDefaultTheme = (isProTemplate && theme == AppProTemplate.DefaultTheme) || (!isProTemplate && theme == AppTemplate.DefaultTheme); @@ -687,10 +686,15 @@ protected void ConfigureAngularJsonForThemeSelection(ProjectBuildArgs projectArg if (theme.HasValue && projectArgs.UiFramework == UiFramework.Angular) { + var angularFolderPath = projectArgs.TemplateName == MicroserviceProTemplate.TemplateName + ? projectArgs.OutputFolder.EnsureEndsWith(Path.DirectorySeparatorChar) + "apps" + Path.DirectorySeparatorChar + "angular" + : projectArgs.OutputFolder.EnsureEndsWith(Path.DirectorySeparatorChar) + "angular"; + AngularThemeConfigurer.Configure(new AngularThemeConfigurationArgs( theme: theme.Value, - projectName: projectArgs.SolutionName.FullName, - angularFolderPath: projectArgs.OutputFolder + Path.DirectorySeparatorChar + "angular")); + projectName: projectArgs.SolutionName.FullName, + angularFolderPath: angularFolderPath + )); } }