Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Make related configurations for theme selection (Angular UI) #14533

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public NewCommand(
ILocalEventBus eventBus,
IBundlingService bundlingService,
ITemplateInfoProvider templateInfoProvider,
TemplateProjectBuilder templateProjectBuilder) :
TemplateProjectBuilder templateProjectBuilder,
AngularThemeConfigurer angularThemeConfigurer) :
base(connectionStringProvider,
solutionPackageVersionFinder,
cmdHelper,
Expand All @@ -50,7 +51,8 @@ public NewCommand(
initialMigrationCreator,
themePackageAdder,
eventBus,
bundlingService)
bundlingService,
angularThemeConfigurer)
{
TemplateInfoProvider = templateInfoProvider;
TemplateProjectBuilder = templateProjectBuilder;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,6 +39,8 @@ public abstract class ProjectCreationCommandBase
public ILogger<NewCommand> Logger { get; set; }

public ThemePackageAdder ThemePackageAdder { get; }

public AngularThemeConfigurer AngularThemeConfigurer { get; }

public ProjectCreationCommandBase(
ConnectionStringProvider connectionStringProvider,
Expand All @@ -49,7 +52,8 @@ public ProjectCreationCommandBase(
InitialMigrationCreator initialMigrationCreator,
ThemePackageAdder themePackageAdder,
ILocalEventBus eventBus,
IBundlingService bundlingService)
IBundlingService bundlingService,
AngularThemeConfigurer angularThemeConfigurer)
{
_bundlingService = bundlingService;
ConnectionStringProvider = connectionStringProvider;
Expand All @@ -61,6 +65,7 @@ public ProjectCreationCommandBase(
InitialMigrationCreator = initialMigrationCreator;
EventBus = eventBus;
ThemePackageAdder = themePackageAdder;
AngularThemeConfigurer = angularThemeConfigurer;

Logger = NullLogger<NewCommand>.Instance;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}