Browse Source

Add `--theme-style` option to CLI

pull/13306/head
Engincan VESKE 4 years ago
parent
commit
3b164f5378
  1. 57
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  2. 68
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStyleStep.cs
  3. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ThemeStyle.cs
  4. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs
  5. 19
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs
  6. 26
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ExceptionMessageHelper.cs

57
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); 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) if (theme.HasValue)
{ {
Logger.LogInformation("Theme: " + theme); 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); var publicWebSite = uiFramework != UiFramework.None && commandLineArgs.Options.ContainsKey(Options.PublicWebSite.Long);
if (publicWebSite) if (publicWebSite)
{ {
@ -200,7 +206,8 @@ public abstract class ProjectCreationCommandBase
commandLineArgs.Options, commandLineArgs.Options,
connectionString, connectionString,
pwa, pwa,
theme theme,
themeStyle
); );
} }
@ -338,7 +345,7 @@ public abstract class ProjectCreationCommandBase
return DatabaseProvider.MongoDb; return DatabaseProvider.MongoDb;
} }
throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage("Database Provider")); throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage("Database Provider"));
} }
protected virtual async Task RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs) protected virtual async Task RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs)
@ -446,7 +453,7 @@ public abstract class ProjectCreationCommandBase
case "oracle": case "oracle":
return DatabaseManagementSystem.Oracle; return DatabaseManagementSystem.Oracle;
default: 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": case "react-native":
return MobileApp.ReactNative; return MobileApp.ReactNative;
default: 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": case "blazor-server":
return UiFramework.BlazorServer; return UiFramework.BlazorServer;
default: 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); var theme = commandLineArgs.Options.GetOrNull(Options.Theme.Long)?.ToLower();
theme = theme?.ToLower();
return template switch
{
AppTemplate.TemplateName or null => GetAppTheme(),
AppProTemplate.TemplateName => GetAppProTheme(),
_ => throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage(Options.Theme.Long))
};
Theme GetAppTheme() Theme GetAppTheme()
{ {
@ -520,12 +533,23 @@ public abstract class ProjectCreationCommandBase
_ => Theme.NotSpecified _ => 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(), null => ThemeStyle.NotSpecified,
AppProTemplate.TemplateName => GetAppProTheme(), "dim" => ThemeStyle.Dim,
_ => throw new CliUsageException(ExceptionMessageHelper.GetInvalidArgExceptionMessage(Options.Theme.Long)) "light" => ThemeStyle.Light,
"dark" => ThemeStyle.Dark,
_ => throw new CliUsageException(ExceptionMessageHelper.GetInvalidOptionExceptionMessage(Options.ThemeStyle.Long))
}; };
} }
@ -550,7 +574,7 @@ public abstract class ProjectCreationCommandBase
case null: case null:
break; break;
default: 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 const string Long = "theme";
} }
public static class ThemeStyle
{
public const string Long = "theme-style";
}
} }
} }

68
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<string>
{
"/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);
}
}

8
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
}

6
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 Theme? Theme { get; set; }
public ThemeStyle? ThemeStyle { get; set; }
[NotNull] [NotNull]
public Dictionary<string, string> ExtraProperties { get; set; } public Dictionary<string, string> ExtraProperties { get; set; }
@ -63,7 +65,8 @@ public class ProjectBuildArgs
Dictionary<string, string> extraProperties = null, Dictionary<string, string> extraProperties = null,
[CanBeNull] string connectionString = null, [CanBeNull] string connectionString = null,
bool pwa = false, bool pwa = false,
Theme? theme = null) Theme? theme = null,
ThemeStyle? themeStyle = null)
{ {
SolutionName = Check.NotNull(solutionName, nameof(solutionName)); SolutionName = Check.NotNull(solutionName, nameof(solutionName));
TemplateName = templateName; TemplateName = templateName;
@ -81,5 +84,6 @@ public class ProjectBuildArgs
ConnectionString = connectionString; ConnectionString = connectionString;
Pwa = pwa; Pwa = pwa;
Theme = theme; Theme = theme;
ThemeStyle = themeStyle;
} }
} }

19
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs

@ -184,14 +184,15 @@ public abstract class AppTemplateBase : TemplateInfo
return; 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()); steps.Add(new ChangeThemeStep());
RemoveLeptonXThemePackagesFromPackageJsonFiles(steps, this.IsPro()); steps.Add(new ChangeThemeStyleStep());
RemoveLeptonXThemePackagesFromPackageJsonFiles(steps, IsPro());
} }
} }
private static void RemoveLeptonXThemePackagesFromPackageJsonFiles(List<ProjectBuildPipelineStep> steps, bool isPro) private static void RemoveLeptonXThemePackagesFromPackageJsonFiles(List<ProjectBuildPipelineStep> steps, bool isProTemplate)
{ {
var packageJsonFilePaths = new List<string>() var packageJsonFilePaths = new List<string>()
{ {
@ -218,15 +219,9 @@ public abstract class AppTemplateBase : TemplateInfo
"/angular/package.json" "/angular/package.json"
}; };
var mvcUiPackageName = "@abp/aspnetcore.mvc.ui.theme.leptonxlite"; var mvcUiPackageName = isProTemplate ? "@volo/abp.aspnetcore.mvc.ui.theme.leptonx" : "@abp/aspnetcore.mvc.ui.theme.leptonxlite";
var blazorServerUiPackageName = "@abp/aspnetcore.components.server.leptonxlitetheme"; var blazorServerUiPackageName = isProTemplate ? "@volo/aspnetcore.components.server.leptonxtheme" : "@abp/aspnetcore.components.server.leptonxlitetheme";
var ngUiPackageName = "@abp/ng.theme.lepton-x"; var ngUiPackageName = isProTemplate ? "@volosoft/abp.ng.theme.lepton-x" : "@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";
}
foreach (var packageJsonFilePath in packageJsonFilePaths) foreach (var packageJsonFilePath in packageJsonFilePaths)
{ {

26
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; namespace Volo.Abp.Cli.Utils;
public static class ExceptionMessageHelper public static class ExceptionMessageHelper
{ {
public static string GetInvalidArgExceptionMessage(string args) public static string GetInvalidOptionExceptionMessage(string optionName) => $"The option you provided for {optionName} is invalid!";
{
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();
}
} }
Loading…
Cancel
Save