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

Add MauiChangePortStep #14248

Merged
merged 1 commit into from
Oct 7, 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
Expand Up @@ -163,6 +163,7 @@ protected void DeleteUnrelatedProjects(ProjectBuildContext context, List<Project
if (context.BuildArgs.MobileApp == MobileApp.Maui)
{
steps.Add(new MauiChangeApplicationIdGuidStep());
steps.Add(new MauiChangePortStep());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Linq;
using Volo.Abp.Cli.ProjectBuilding.Building;

namespace Volo.Abp.Cli.ProjectBuilding.Templates.Maui;

public class MauiChangePortStep : ProjectBuildPipelineStep
{
public override void Execute(ProjectBuildContext context)
{
var appsettingsFile = context.Files.FirstOrDefault(x =>
!x.IsDirectory &&
x.Name.EndsWith("aspnet-core/src/MyCompanyName.MyProjectName.Maui/appsettings.json",
StringComparison.InvariantCultureIgnoreCase)
);

if (appsettingsFile == null)
{
return;
}

var ports = GetPorts(context);

appsettingsFile.NormalizeLineEndings();
var lines = appsettingsFile.GetLines();

for (var i = 1; i < lines.Length; i++)
{
var line = lines[i];
var previousLine = lines[i-1];

if (line.Contains("Authority") && line.Contains("localhost"))
{
line = line.Replace("44305", ports.AuthServerPort);
}
else if (previousLine.Contains("Default") && line.Contains("BaseUrl") && line.Contains("localhost"))
{
line = line.Replace("44305", ports.ApiHostPort);
}

lines[i] = line;
}

appsettingsFile.SetLines(lines);
}

private (string AuthServerPort, string ApiHostPort) GetPorts(ProjectBuildContext context)
{
var authServerPort = string.Empty;
var apiHostPort = string.Empty;

switch (context.BuildArgs.UiFramework)
{
case UiFramework.Angular:
case UiFramework.Blazor:
authServerPort = "44305";
apiHostPort = "44305";
break;
case UiFramework.BlazorServer:
authServerPort = "44308";
apiHostPort = "44308";
break;
case UiFramework.Mvc:
case UiFramework.NotSpecified:
authServerPort = "44303";
apiHostPort = "44303";
break;
}

if (context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server") ||
context.BuildArgs.ExtraProperties.ContainsKey("separate-auth-server") ||
context.BuildArgs.ExtraProperties.ContainsKey("tiered"))
{
authServerPort = "44301";
apiHostPort = "44300";
}

return (authServerPort, apiHostPort);
}
}