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

ABP CLI Support for Blazor-Server #8157

Merged
merged 10 commits into from
Mar 23, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
}

var newTemplate = commandLineArgs.Options.ContainsKey(Options.NewTemplate.Long);

var template = commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long);
var newProTemplate = !string.IsNullOrEmpty(template) && template == ModuleProTemplate.TemplateName;

var withSourceCode = newTemplate || newProTemplate || commandLineArgs.Options.ContainsKey(Options.SourceCode.Long);
var addSourceCodeToSolutionFile = withSourceCode && commandLineArgs.Options.ContainsKey("add-to-solution-file");

var skipDbMigrations = newTemplate || newProTemplate || Convert.ToBoolean(
commandLineArgs.Options.GetOrNull(Options.DbMigrations.Skip) ?? "false");

var skipDbMigrations = newTemplate || newProTemplate || Convert.ToBoolean(commandLineArgs.Options.GetOrNull(Options.DbMigrations.Skip) ?? "false");
var solutionFile = GetSolutionFile(commandLineArgs);

var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ protected virtual UiFramework GetUiFramework(CommandLineArgs commandLineArgs)
return UiFramework.Angular;
case "blazor":
return UiFramework.Blazor;
case "blazor-server":
return UiFramework.BlazorServer;
default:
return UiFramework.NotSpecified;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ public override void Execute(ProjectBuildContext context)
var publicAppSettings = context.Files
.FirstOrDefault(f => f.Name.Contains("MyCompanyName.MyProjectName.Web.Public") && f.Name.EndsWith("appsettings.json"));

publicAppSettings?.SetContent(publicAppSettings.Content.Replace("localhost:44303","localhost:44305"));
if (context.BuildArgs.UiFramework == UiFramework.BlazorServer)
{
publicAppSettings?.SetContent(publicAppSettings.Content.Replace("localhost:44303","localhost:44313"));
}
else
{
publicAppSettings?.SetContent(publicAppSettings.Content.Replace("localhost:44303","localhost:44305"));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
{
public class RenameProjectInTyeStep : ProjectBuildPipelineStep
{
private readonly string _oldName;
private readonly string _newName;

public RenameProjectInTyeStep(string oldName, string newName)
{
_oldName = oldName;
_newName = newName;
}

public override void Execute(ProjectBuildContext context)
{
var tyeFile = context.Files.FirstOrDefault(f => f.Name == "/tye.yaml");

if (tyeFile == null)
{
return;
}

var lines = tyeFile.GetLines();
var oldNameLine = $"- name: {_oldName}";
var newNameLine = $"- name: {_newName}";

var newLines = lines.Select(line => line.Equals(oldNameLine) ? newNameLine : line).ToList();

tyeFile.SetContent(string.Join(Environment.NewLine, newLines));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ProjectBuildPipeline Build(ProjectBuildContext context)
pipeline.Steps.Add(new DatabaseManagementSystemChangeStep()); // todo: move to custom steps?
}

if ((context.BuildArgs.UiFramework == UiFramework.Mvc || context.BuildArgs.UiFramework == UiFramework.Blazor)
if ((context.BuildArgs.UiFramework == UiFramework.Mvc || context.BuildArgs.UiFramework == UiFramework.Blazor || context.BuildArgs.UiFramework == UiFramework.BlazorServer)
&& context.BuildArgs.MobileApp == MobileApp.None && context.Template.Name != MicroserviceProTemplate.TemplateName
&& context.Template.Name != MicroserviceServiceProTemplate.TemplateName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum UiFramework
None = 1,
Mvc = 2,
Angular = 3,
Blazor = 4
Blazor = 4,
BlazorServer = 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static string ToFrameworkName(this UiFramework uiFramework)
case UiFramework.Mvc: return "mvc";
case UiFramework.Angular: return "angular";
case UiFramework.Blazor: return "blazor";
case UiFramework.BlazorServer: return "blazor-server";
case UiFramework.NotSpecified: return "NotSpecified";
default: return "NotSpecified";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static void ConfigureTenantSchema(ProjectBuildContext context, List<Proj
if (context.BuildArgs.ExtraProperties.ContainsKey("separate-tenant-schema"))
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations"));
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.EntityFrameworkCore.SeparateDbMigrations", "MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations"));
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.EntityFrameworkCore.SeparateDbMigrations", "MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations"));
}
else
{
Expand Down Expand Up @@ -87,22 +87,31 @@ private static void DeleteUnrelatedProjects(ProjectBuildContext context, List<Pr
ConfigureWithAngularUi(context, steps);
break;


case UiFramework.Blazor:
ConfigureWithBlazorUi(context, steps);
break;

case UiFramework.BlazorServer:
ConfigureWithBlazorServerUi(context, steps);
break;

case UiFramework.Mvc:
case UiFramework.NotSpecified:
ConfigureWithMvcUi(context, steps);
break;
}

if (context.BuildArgs.UiFramework != UiFramework.Blazor)
if (context.BuildArgs.UiFramework != UiFramework.Blazor && context.BuildArgs.UiFramework != UiFramework.BlazorServer)
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor"));
}

if (context.BuildArgs.UiFramework != UiFramework.BlazorServer)
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server.Tiered"));
}

if (context.BuildArgs.UiFramework != UiFramework.Angular)
{
steps.Add(new RemoveFolderStep("/angular"));
Expand Down Expand Up @@ -147,7 +156,7 @@ private void ConfigurePublicWebSite(ProjectBuildContext context, List<ProjectBui

if (context.BuildArgs.ExtraProperties.ContainsKey(NewCommand.Options.Tiered.Long) || context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server"))
{
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.Web.Public.Host","MyCompanyName.MyProjectName.Web.Public"));
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.Web.Public.Host","MyCompanyName.MyProjectName.Web.Public"));
steps.Add(new ChangeDbMigratorPublicPortStep());
}
else if (context.BuildArgs.UiFramework != UiFramework.NotSpecified && context.BuildArgs.UiFramework != UiFramework.Mvc)
Expand Down Expand Up @@ -181,7 +190,7 @@ private static void ConfigureWithoutUi(ProjectBuildContext context, List<Project
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.IdentityServer"));
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds", "MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds", "MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new AppTemplateChangeConsoleTestClientPortSettingsStep("44305"));
}
}
Expand All @@ -202,18 +211,42 @@ private static void ConfigureWithBlazorUi(ProjectBuildContext context, List<Proj
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.IdentityServer"));
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds", "MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds", "MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new AppTemplateChangeConsoleTestClientPortSettingsStep("44305"));
}
}

private static void ConfigureWithBlazorServerUi(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web.Host"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web.Tests", projectFolderPath: "/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds"));

if (context.BuildArgs.ExtraProperties.ContainsKey("tiered"))
{
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.Blazor.Server.Tiered", "MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server"));
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
}
else
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server.Tiered"));
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.Blazor.Server", "MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.IdentityServer"));
steps.Add(new AppTemplateChangeConsoleTestClientPortSettingsStep("44313"));
}
}

private static void ConfigureWithMvcUi(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
if (context.BuildArgs.ExtraProperties.ContainsKey("tiered"))
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web.Tests", projectFolderPath: "/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests"));
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.Web.Host", "MyCompanyName.MyProjectName.Web"));
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.Web.Host", "MyCompanyName.MyProjectName.Web"));
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
}
else
Expand Down Expand Up @@ -248,7 +281,7 @@ private static void ConfigureWithAngularUi(ProjectBuildContext context, List<Pro
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.IdentityServer"));
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds", "MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds", "MyCompanyName.MyProjectName.HttpApi.Host"));
steps.Add(new AppTemplateChangeConsoleTestClientPortSettingsStep("44305"));
}
}
Expand All @@ -265,6 +298,7 @@ private static void RandomizeSslPorts(ProjectBuildContext context, List<ProjectB
return;
}

//todo: discuss blazor ports
steps.Add(new TemplateRandomSslPortStep(
new List<string>
{
Expand Down Expand Up @@ -308,7 +342,9 @@ private static void ChangeConnectionString(ProjectBuildContext context, List<Pro

private static void CleanupFolderHierarchy(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
if ((context.BuildArgs.UiFramework == UiFramework.Mvc || context.BuildArgs.UiFramework == UiFramework.Blazor) &&
if ( (context.BuildArgs.UiFramework == UiFramework.Mvc
|| context.BuildArgs.UiFramework == UiFramework.Blazor
|| context.BuildArgs.UiFramework == UiFramework.BlazorServer) &&
context.BuildArgs.MobileApp == MobileApp.None)
{
steps.Add(new MoveFolderStep("/aspnet-core/", "/"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuil

private static void DeleteUnrelatedProjects(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
//TODO: move common tasks to methods
switch (context.BuildArgs.UiFramework)
{
case UiFramework.None:
Expand All @@ -41,8 +42,11 @@ private static void DeleteUnrelatedProjects(ProjectBuildContext context, List<Pr

steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor",null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server",null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor.Server"));
steps.Add(new RemoveFolderStep("/apps/blazor"));
steps.Add(new RemoveProjectFromTyeStep("blazor"));
steps.Add(new RemoveProjectFromTyeStep("blazor-server"));

steps.Add(new RemoveFolderStep("/apps/angular"));
break;
Expand All @@ -56,8 +60,11 @@ private static void DeleteUnrelatedProjects(ProjectBuildContext context, List<Pr

steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor",null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server",null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor.Server"));
steps.Add(new RemoveFolderStep("/apps/blazor"));
steps.Add(new RemoveProjectFromTyeStep("blazor"));
steps.Add(new RemoveProjectFromTyeStep("blazor-server"));
break;

case UiFramework.Blazor:
Expand All @@ -67,14 +74,48 @@ private static void DeleteUnrelatedProjects(ProjectBuildContext context, List<Pr
steps.Add(new RemoveFolderStep("/apps/angular"));
steps.Add(new RemoveProjectFromTyeStep("web"));
steps.Add(new RemoveProjectFromPrometheusStep("web"));

steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server",
"/apps/blazor/MyCompanyName.MyProjectName.Blazor.sln",
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor.Server"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server",
null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor.Server"));
steps.Add(new RemoveProjectFromTyeStep("blazor-server"));

break;

case UiFramework.BlazorServer:
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web",null,
"/apps/web/src/MyCompanyName.MyProjectName.Web"));
steps.Add(new RemoveFolderStep("/apps/web"));
steps.Add(new RemoveFolderStep("/apps/angular"));
steps.Add(new RemoveProjectFromTyeStep("web"));
steps.Add(new RemoveProjectFromPrometheusStep("web"));

steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor",
"/apps/blazor/MyCompanyName.MyProjectName.Blazor.sln",
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor",
null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromTyeStep("blazor"));

steps.Add(new TemplateProjectRenameStep("MyCompanyName.MyProjectName.Blazor.Server",
"MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RenameProjectInTyeStep("blazor-server", "blazor"));

break;

case UiFramework.Mvc:
case UiFramework.NotSpecified:
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor",null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor.Server",null,
"/apps/blazor/src/MyCompanyName.MyProjectName.Blazor.Server"));
steps.Add(new RemoveFolderStep("/apps/blazor"));
steps.Add(new RemoveProjectFromTyeStep("blazor"));
steps.Add(new RemoveProjectFromTyeStep("blazor-server"));

steps.Add(new RemoveFolderStep("/apps/angular"));
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
using Volo.Abp.Cli.ProjectBuilding.Files;

namespace Volo.Abp.Cli.ProjectBuilding.Templates.App
namespace Volo.Abp.Cli.ProjectBuilding.Templates
{
public class AppTemplateProjectRenameStep : ProjectBuildPipelineStep
public class TemplateProjectRenameStep : ProjectBuildPipelineStep
{
private readonly string _oldProjectName;
private readonly string _newProjectName;

public AppTemplateProjectRenameStep(
public TemplateProjectRenameStep(
string oldProjectName,
string newProjectName)
{
Expand All @@ -19,10 +18,6 @@ public AppTemplateProjectRenameStep(

public override void Execute(ProjectBuildContext context)
{
context
.GetFile("/aspnet-core/MyCompanyName.MyProjectName.sln")
.ReplaceText(_oldProjectName, _newProjectName);

RenameHelper.RenameAll(context.Files, _oldProjectName, _newProjectName);
}
}
Expand Down
Loading