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..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 @@ -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; @@ -38,6 +39,8 @@ public abstract class ProjectCreationCommandBase public ILogger Logger { get; set; } public ThemePackageAdder ThemePackageAdder { get; } + + public AngularThemeConfigurer AngularThemeConfigurer { get; } public ProjectCreationCommandBase( ConnectionStringProvider connectionStringProvider, @@ -49,7 +52,8 @@ public ProjectCreationCommandBase( InitialMigrationCreator initialMigrationCreator, ThemePackageAdder themePackageAdder, ILocalEventBus eventBus, - IBundlingService bundlingService) + IBundlingService bundlingService, + AngularThemeConfigurer angularThemeConfigurer) { _bundlingService = bundlingService; ConnectionStringProvider = connectionStringProvider; @@ -61,6 +65,7 @@ public ProjectCreationCommandBase( InitialMigrationCreator = initialMigrationCreator; EventBus = eventBus; ThemePackageAdder = themePackageAdder; + AngularThemeConfigurer = angularThemeConfigurer; Logger = NullLogger.Instance; } @@ -667,6 +672,32 @@ private void ConfigureNpmPackagesForLeptonTheme(ProjectBuildArgs projectArgs) } } + protected void ConfigureAngularJsonForThemeSelection(ProjectBuildArgs projectArgs) + { + 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); + + if (isDefaultTheme || projectArgs.TemplateName == ModuleTemplate.TemplateName) + { + return; + } + + 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: angularFolderPath + )); + } + } + 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