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 260f752f29..d88463d56b 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 @@ -103,12 +103,18 @@ public abstract class ProjectCreationCommandBase Logger.LogInformation("UI Framework: " + uiFramework); } - var theme = uiFramework == UiFramework.None ? (Theme?)null : GetTheme(commandLineArgs, template); + var theme = uiFramework == UiFramework.None ? (Theme?)null : GetThemeByTemplateOrNull(commandLineArgs, template); if (theme.HasValue) { Logger.LogInformation("Theme: " + theme); } + var themeStyle = theme.HasValue ? GetThemeStyleOrNull(commandLineArgs) : (ThemeStyle?)null; + if(themeStyle.HasValue) + { + Logger.LogInformation("Theme Style: " + themeStyle); + } + var publicWebSite = uiFramework != UiFramework.None && commandLineArgs.Options.ContainsKey(Options.PublicWebSite.Long); if (publicWebSite) { @@ -200,7 +206,8 @@ public abstract class ProjectCreationCommandBase commandLineArgs.Options, connectionString, pwa, - theme + theme, + themeStyle ); } @@ -338,7 +345,7 @@ public abstract class ProjectCreationCommandBase return DatabaseProvider.MongoDb; } - throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage("Database Provider")); + throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage("Database Provider")); } protected virtual async Task RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs) @@ -446,7 +453,7 @@ public abstract class ProjectCreationCommandBase case "oracle": return DatabaseManagementSystem.Oracle; default: - throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage("Database Management System")); + throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage("Database Management System")); } } @@ -462,7 +469,7 @@ public abstract class ProjectCreationCommandBase case "react-native": return MobileApp.ReactNative; default: - throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage("Mobile App")); + throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage("Mobile App")); } } @@ -490,14 +497,20 @@ public abstract class ProjectCreationCommandBase case "blazor-server": return UiFramework.BlazorServer; default: - throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage("UI Framework")); + throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage("UI Framework")); } } - protected virtual Theme GetTheme(CommandLineArgs commandLineArgs, string template = "app") + protected virtual Theme GetThemeByTemplateOrNull(CommandLineArgs commandLineArgs, string template = "app") { - var theme = commandLineArgs.Options.GetOrNull(Options.Theme.Long); - theme = theme?.ToLower(); + var theme = commandLineArgs.Options.GetOrNull(Options.Theme.Long)?.ToLower(); + + return template switch + { + AppTemplate.TemplateName or null => GetAppTheme(), + AppProTemplate.TemplateName => GetAppProTheme(), + _ => throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage(Options.Theme.Long)) + }; Theme GetAppTheme() { @@ -520,12 +533,23 @@ public abstract class ProjectCreationCommandBase _ => Theme.NotSpecified }; } + } + + protected virtual ThemeStyle? GetThemeStyleOrNull(CommandLineArgs commandLineArgs, Theme theme) + { + if(theme != Theme.LeptonX) + { + return null; + } - return template switch + var themeStyle = commandLineArgs.Options.GetOrNull(Options.ThemeStyle.Long)?.ToLower(); + return themeStyle switch { - AppTemplate.TemplateName or null => GetAppTheme(), - AppProTemplate.TemplateName => GetAppProTheme(), - _ => throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage(Options.Theme.Long)) + null => ThemeStyle.NotSpecified, + "dim" => ThemeStyle.Dim, + "light" => ThemeStyle.Light, + "dark" => ThemeStyle.Dark, + _ => throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage(Options.ThemeStyle.Long)) }; } @@ -550,7 +574,7 @@ public abstract class ProjectCreationCommandBase case null: break; default: - throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage(Options.Theme.Long)); + throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage(Options.Theme.Long)); } } @@ -687,5 +711,10 @@ public abstract class ProjectCreationCommandBase { public const string Long = "theme"; } + + public static class ThemeStyle + { + public const string Long = "theme-style"; + } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStyleStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStyleStep.cs new file mode 100644 index 0000000000..7562a34385 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStyleStep.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; + +namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps; + +//TODO: Remove this step and move it to the ChangeThemeStep.cs? +public class ChangeThemeStyleStep : ProjectBuildPipelineStep +{ + public override void Execute(ProjectBuildContext context) + { + if (!context.BuildArgs.Theme.HasValue || context.BuildArgs.Theme != Theme.LeptonX) + { + return; + } + + switch (context.BuildArgs.ThemeStyle) + { + case ThemeStyle.Light: + ChangeThemeStyle(context, themeStyleName: "Light"); + break; + case ThemeStyle.Dark: + ChangeThemeStyle(context, themeStyleName: "Dark"); + break; + } + } + + private void ChangeThemeStyle(ProjectBuildContext context, string themeStyleName) + { + var defaultThemeStyleName = "LeptonXStyleNames.Dim"; + var newThemeStyleName = $"LeptonXStyleNames.{themeStyleName}"; + + var filePaths = new List + { + "/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs", + "/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs", + "/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs", + "/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs", + "/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.Tiered/MyProjectNameBlazorModule.cs", + "/aspnet-core/src/MyCompanyName.MyProjectName.AuthServer/MyProjectNameAuthServerModule.cs" + }; + + foreach(var filePath in filePaths) + { + ReplaceThemeStyleName(context, filePath, defaultThemeStyleName, newThemeStyleName); + } + } + + protected void ReplaceThemeStyleName(ProjectBuildContext context, string filePath, string oldThemeStyleName, string newThemeStyleName) + { + var file = context.FindFile(filePath); + if (file == null) + { + return; + } + + file.NormalizeLineEndings(); + + var lines = file.GetLines(); + for (var i = 0; i < lines.Length; i++) + { + if (lines[i].Contains(oldThemeStyleName)) + { + lines[i] = lines[i].Replace(oldThemeStyleName, newThemeStyleName); + } + } + + file.SetLines(lines); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ThemeStyle.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ThemeStyle.cs new file mode 100644 index 0000000000..e9a8804f70 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ThemeStyle.cs @@ -0,0 +1,8 @@ +namespace Volo.Abp.Cli.ProjectBuilding.Building; +public enum ThemeStyle : byte +{ + NotSpecified = 0, + Dim = 1, + Light = 2, + Dark = 3 +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs index 18edb71863..b4b4429767 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs @@ -44,6 +44,8 @@ public class ProjectBuildArgs public Theme? Theme { get; set; } + public ThemeStyle? ThemeStyle { get; set; } + [NotNull] public Dictionary ExtraProperties { get; set; } @@ -63,7 +65,8 @@ public class ProjectBuildArgs Dictionary extraProperties = null, [CanBeNull] string connectionString = null, bool pwa = false, - Theme? theme = null) + Theme? theme = null, + ThemeStyle? themeStyle = null) { SolutionName = Check.NotNull(solutionName, nameof(solutionName)); TemplateName = templateName; @@ -81,5 +84,6 @@ public class ProjectBuildArgs ConnectionString = connectionString; Pwa = pwa; Theme = theme; + ThemeStyle = themeStyle; } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs index 6b77af00c8..d8a37c71fd 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs @@ -184,14 +184,15 @@ public abstract class AppTemplateBase : TemplateInfo return; } - if (context.BuildArgs.Theme != AppTemplate.DefaultTheme || context.BuildArgs.Theme != AppProTemplate.DefaultTheme) + if (context.BuildArgs.Theme is not AppTemplate.DefaultTheme or AppProTemplate.DefaultTheme) { steps.Add(new ChangeThemeStep()); - RemoveLeptonXThemePackagesFromPackageJsonFiles(steps, this.IsPro()); + steps.Add(new ChangeThemeStyleStep()); + RemoveLeptonXThemePackagesFromPackageJsonFiles(steps, IsPro()); } } - private static void RemoveLeptonXThemePackagesFromPackageJsonFiles(List steps, bool isPro) + private static void RemoveLeptonXThemePackagesFromPackageJsonFiles(List steps, bool isProTemplate) { var packageJsonFilePaths = new List() { @@ -218,15 +219,9 @@ public abstract class AppTemplateBase : TemplateInfo "/angular/package.json" }; - var mvcUiPackageName = "@abp/aspnetcore.mvc.ui.theme.leptonxlite"; - var blazorServerUiPackageName = "@abp/aspnetcore.components.server.leptonxlitetheme"; - var ngUiPackageName = "@abp/ng.theme.lepton-x"; - if (isPro) - { - mvcUiPackageName = "@volo/abp.aspnetcore.mvc.ui.theme.leptonx"; - blazorServerUiPackageName = "@volo/aspnetcore.components.server.leptonxtheme"; - ngUiPackageName = "@volosoft/abp.ng.theme.lepton-x"; - } + var mvcUiPackageName = isProTemplate ? "@volo/abp.aspnetcore.mvc.ui.theme.leptonx" : "@abp/aspnetcore.mvc.ui.theme.leptonxlite"; + var blazorServerUiPackageName = isProTemplate ? "@volo/aspnetcore.components.server.leptonxtheme" : "@abp/aspnetcore.components.server.leptonxlitetheme"; + var ngUiPackageName = isProTemplate ? "@volosoft/abp.ng.theme.lepton-x" : "@abp/ng.theme.lepton-x"; foreach (var packageJsonFilePath in packageJsonFilePaths) { diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ExceptionMessageHelper.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ExceptionMessageHelper.cs index 4274993cd1..dd78be14db 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ExceptionMessageHelper.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ExceptionMessageHelper.cs @@ -1,30 +1,6 @@ -using System; -using System.Text; - namespace Volo.Abp.Cli.Utils; public static class ExceptionMessageHelper { - public static string GetInvalidArgExceptionMessage(string args) - { - Check.NotNullOrEmpty(args, nameof(args), minLength: 2); - - var exceptionMessageBuilder = new StringBuilder(); - exceptionMessageBuilder.Append("The option you provided for "); - if (args.Contains(" ")) - { - foreach (var arg in args.Split(' ')) - { - exceptionMessageBuilder.Append(arg.ToPascalCase()); - } - } - else - { - exceptionMessageBuilder.Append(args.ToPascalCase()); - } - - exceptionMessageBuilder.Append(" is invalid!"); - - return exceptionMessageBuilder.ToString(); - } + public static string GetInvalidOptionExceptionMessage(string optionName) => $"The option you provided for {optionName} is invalid!"; } \ No newline at end of file