diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveCmsKitStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveCmsKitStep.cs deleted file mode 100644 index a0778d5a4d..0000000000 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveCmsKitStep.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Linq; -using Volo.Abp.Cli.ProjectBuilding.Files; - -namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps -{ - public class RemoveCmsKitStep : ProjectBuildPipelineStep - { - public override void Execute(ProjectBuildContext context) - { - var commonFiles = context.Files.Where(f => - f.Name.EndsWith(".csproj") || - f.Name.EndsWith(".cs") || - f.Name.EndsWith(".json") || - f.Name.EndsWith(".cshtml")); - - foreach (var file in commonFiles) - { - file.RemoveTemplateCodeIfNot("CMS-KIT"); - } - } - } -} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveEfCoreRelatedCodeStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveEfCoreRelatedCodeStep.cs deleted file mode 100644 index df8f18128e..0000000000 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveEfCoreRelatedCodeStep.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Linq; -using Volo.Abp.Cli.ProjectBuilding.Files; - -namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps -{ - public class RemoveEfCoreRelatedCodeStep : ProjectBuildPipelineStep - { - public override void Execute(ProjectBuildContext context) - { - foreach (var file in context.Files) - { - if (file.Name.EndsWith(".cs") || file.Name.EndsWith(".csproj") || file.Name.EndsWith(".json")) - { - file.RemoveTemplateCodeIfNot("EFCORE"); - } - } - } - } -} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveGlobalFeaturesPackageStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveGlobalFeaturesPackageStep.cs deleted file mode 100644 index 15a84576c6..0000000000 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveGlobalFeaturesPackageStep.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Linq; -using Volo.Abp.Cli.ProjectBuilding.Files; - -namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps -{ - public class RemoveGlobalFeaturesPackageStep : ProjectBuildPipelineStep - { - public override void Execute(ProjectBuildContext context) - { - var commonFiles = context.Files.Where(f => - f.Name.EndsWith(".csproj") || - f.Name.EndsWith(".cs") || - f.Name.EndsWith(".cshtml")); - - foreach (var file in commonFiles) - { - file.RemoveTemplateCodeIf("CMS-KIT"); - } - } - } -} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs deleted file mode 100644 index eced4fd3e5..0000000000 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Linq; -using Volo.Abp.Cli.ProjectBuilding.Files; - -namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps -{ - public class RemovePublicRedisStep : ProjectBuildPipelineStep - { - public override void Execute(ProjectBuildContext context) - { - foreach (var file in context.Files) - { - if (file.Name.EndsWith(".cs") || file.Name.EndsWith(".csproj") || file.Name.EndsWith(".json")) - { - file.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); - } - } - } - } -} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs index 2e90d63f92..bfc3d93ad1 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Linq; namespace Volo.Abp.Cli.ProjectBuilding.Files { @@ -15,18 +17,6 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files { RemoveMarkedTemplateCode(file, symbols); } - - //TODO: Remove this method and switch to symbol usage - public static void RemoveTemplateCodeIf(this FileEntry file, string condition) - { - RemoveByCondition(file, "IF", condition); - } - - //TODO: Remove this method and switch to symbol usage - public static void RemoveTemplateCodeIfNot(this FileEntry file, string condition) - { - RemoveByCondition(file, "IF-NOT", condition); - } public static void RemoveTemplateCodeMarkers(this FileEntry file) { @@ -59,14 +49,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files file.SetLines(newLines); } - //TODO: Remove this method and switch to symbol usage - private static void RemoveByCondition(this FileEntry file, string conditionName, string condition) - { - RemoveMarkedTemplateCode(file, $""); - } - - //TODO: Remove this method and switch to symbol usage - private static void RemoveMarkedTemplateCode(this FileEntry file, string beginMark) + private static void RemoveMarkedTemplateCode(this FileEntry file, List symbols) { if (!file.Content.Contains("")) { @@ -80,8 +63,40 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files for (int i = 0; i < lines.Length; i++) { - if (lines[i].Contains(beginMark)) + if (lines[i].Contains(" !parsedMarker.IsNegativeCondition + ? symbols.Contains(s, StringComparer.InvariantCultureIgnoreCase) + : !symbols.Contains(s, StringComparer.InvariantCultureIgnoreCase)); + } + else if (parsedMarker.Operator == Operator.Or) + { + sectionShouldBeRemoved = !parsedMarker.Symbols.All(s => !parsedMarker.IsNegativeCondition + ? symbols.Contains(s, StringComparer.InvariantCultureIgnoreCase) + : !symbols.Contains(s, StringComparer.InvariantCultureIgnoreCase) == false); + } + + if (!sectionShouldBeRemoved) + { + continue; + } + while (i < lines.Length && !lines[i].Contains("")) { ++i; @@ -98,48 +113,65 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files file.SetLines(newLines); } - - private static void RemoveMarkedTemplateCode(this FileEntry file, List symbols) + + private static TemplateRemoveMarkerParseResult ParseTemplateRemoveMarker(string marker) { - if (!file.Content.Contains("")) + var result = new TemplateRemoveMarkerParseResult(); + + var condition = marker.Trim() + .RemovePreFix("//").Trim() + .RemovePreFix("@*").Trim() + .RemovePreFix("").Trim() + .RemovePostFix(">").Trim(); + + if (string.IsNullOrWhiteSpace(condition)) { - return; + return result; } - file.NormalizeLineEndings(); + var conditionSplitted = condition.Split("="); - var lines = file.GetLines(); - var newLines = new List(); + result.IsNegativeCondition = conditionSplitted[0] == "IF-NOT"; - for (int i = 0; i < lines.Length; i++) + var conditionContent = string.Join("=", conditionSplitted.Skip(1)) + .RemovePostFix("\"").RemovePreFix("\"") + .RemovePostFix("'").RemovePreFix("'"); + + if (conditionContent.Contains("&&")) { - if (lines[i].Contains("")) - { - ++i; - } + return result; + } - ++i; - } + private class TemplateRemoveMarkerParseResult + { + public List Symbols { get; set; } = new List(); - if (i < lines.Length) - { - newLines.Add(lines[i]); - } - } + public Operator Operator { get; set; } = Operator.None; - file.SetLines(newLines); + public bool IsNegativeCondition { get; set; } + } + + private enum Operator + { + None, + And, + Or } } } 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 b0526a27d2..5e0436d91a 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 @@ -28,6 +28,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App SwitchDatabaseProvider(context, steps); DeleteUnrelatedProjects(context, steps); RemoveMigrations(context, steps); + ConfigureTieredArchitecture(context, steps); ConfigurePublicWebSite(context, steps); RemoveUnnecessaryPorts(context, steps); RandomizeSslPorts(context, steps); @@ -64,7 +65,10 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore.Tests", projectFolderPath: "/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests")); - steps.Add(new RemoveEfCoreRelatedCodeStep()); + } + else + { + context.Symbols.Add("EFCORE"); } if (context.BuildArgs.DatabaseProvider != DatabaseProvider.MongoDb) @@ -144,14 +148,15 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App { if (!context.BuildArgs.PublicWebSite) { - if (!context.BuildArgs.ExtraProperties.ContainsKey(NewCommand.Options.Tiered.Long) && - !context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server")) + if (context.BuildArgs.ExtraProperties.ContainsKey(NewCommand.Options.Tiered.Long) || + context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server")) { - steps.Add(new RemovePublicRedisStep()); + context.Symbols.Add("PUBLIC-REDIS"); } - - steps.Add(new RemoveCmsKitStep()); - return; + } + else + { + context.Symbols.Add("public-website"); } if (context.BuildArgs.ExtraProperties.ContainsKey(NewCommand.Options.Tiered.Long) || context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server")) @@ -164,14 +169,9 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App steps.Add(new ChangePublicAuthPortStep()); } - // We disabled cms-kit for v4.2 release. - if (true || context.BuildArgs.ExtraProperties.ContainsKey("without-cms-kit")) - { - steps.Add(new RemoveCmsKitStep()); - } - else + if (!context.BuildArgs.ExtraProperties.ContainsKey("without-cms-kit")) { - steps.Add(new RemoveGlobalFeaturesPackageStep()); + context.Symbols.Add("CMS-KIT"); } } @@ -197,6 +197,8 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App private static void ConfigureWithBlazorUi(ProjectBuildContext context, List steps) { + context.Symbols.Add("ui: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")); @@ -218,6 +220,8 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App private static void ConfigureWithBlazorServerUi(ProjectBuildContext context, List steps) { + context.Symbols.Add("ui:blazor-server"); + steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web.Host")); @@ -242,6 +246,8 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App private static void ConfigureWithMvcUi(ProjectBuildContext context, List steps) { + context.Symbols.Add("ui:mvc"); + if (context.BuildArgs.ExtraProperties.ContainsKey("tiered")) { steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web")); @@ -262,6 +268,8 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App private static void ConfigureWithAngularUi(ProjectBuildContext context, List steps) { + context.Symbols.Add("ui:angular"); + 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")); @@ -312,6 +320,15 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App ); } + private void ConfigureTieredArchitecture(ProjectBuildContext context, List steps) + { + if (context.BuildArgs.ExtraProperties.ContainsKey(NewCommand.Options.Tiered.Long) || + context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server")) + { + context.Symbols.Add("tiered"); + } + } + private static void RandomizeStringEncryption(ProjectBuildContext context, List steps) { steps.Add(new RandomizeStringEncryptionStep());