From 73f8f03a9cb25c9b14a9ffe8e3179f5ba26ad967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 23 Mar 2021 17:02:45 +0300 Subject: [PATCH 1/2] Partial implemented: CLI template build symbols. --- .../Building/ProjectBuildContext.cs | 6 ++- .../Building/Steps/TemplateCodeDeleteStep.cs | 2 +- .../Files/FileEntryExtensions.cs | 53 +++++++++++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ProjectBuildContext.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ProjectBuildContext.cs index 8b5522165f..e9c6135720 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ProjectBuildContext.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ProjectBuildContext.cs @@ -1,4 +1,5 @@ -using JetBrains.Annotations; +using System.Collections.Generic; +using JetBrains.Annotations; using Volo.Abp.Cli.ProjectBuilding.Files; namespace Volo.Abp.Cli.ProjectBuilding.Building @@ -19,6 +20,8 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building public ProjectResult Result { get; set; } + public List Symbols { get; } //TODO: Fill the symbols, like "UI-Angular", "CMS-KIT"! + public ProjectBuildContext( TemplateInfo template, ModuleInfo module, @@ -29,6 +32,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building Module = module; TemplateFile = Check.NotNull(templateFile, nameof(templateFile)); BuildArgs = Check.NotNull(buildArgs, nameof(buildArgs)); + Symbols = new List(); Result = new ProjectResult(); } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs index 8f17b90702..9b1183ba9a 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps { if (file.Name.EndsWith(".cs") || file.Name.EndsWith(".csproj") || file.Name.EndsWith(".cshtml") || file.Name.EndsWith(".json")) { - file.RemoveTemplateCode(); + file.RemoveTemplateCode(context.Symbols); file.RemoveTemplateCodeMarkers(); } } 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 34200d41ac..2e90d63f92 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 @@ -11,16 +11,18 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files return file; } - public static void RemoveTemplateCode(this FileEntry file) + public static void RemoveTemplateCode(this FileEntry file, List symbols) { - RemoveMarkedTemplateCode(file, ""); + 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); @@ -57,11 +59,13 @@ 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) { if (!file.Content.Contains("")) @@ -94,5 +98,48 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files file.SetLines(newLines); } + + private static void RemoveMarkedTemplateCode(this FileEntry file, List symbols) + { + if (!file.Content.Contains("")) + { + return; + } + + file.NormalizeLineEndings(); + + var lines = file.GetLines(); + var newLines = new List(); + + for (int i = 0; i < lines.Length; i++) + { + if (lines[i].Contains("")) + { + ++i; + } + + ++i; + } + + if (i < lines.Length) + { + newLines.Add(lines[i]); + } + } + + file.SetLines(newLines); + } } } From cdbe3ca9d812198eadc6146204dfb3f7274cbc2b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 23 Mar 2021 20:24:13 +0300 Subject: [PATCH 2/2] Cli template-remove logic change resolves https://github.com/volosoft/volo/issues/5928 --- .../Building/Steps/RemoveCmsKitStep.cs | 22 --- .../Steps/RemoveEfCoreRelatedCodeStep.cs | 19 --- .../Steps/RemoveGlobalFeaturesPackageStep.cs | 21 --- .../Building/Steps/RemovePublicRedisStep.cs | 20 --- .../Files/FileEntryExtensions.cs | 136 +++++++++++------- .../Templates/App/AppTemplateBase.cs | 45 ++++-- 6 files changed, 115 insertions(+), 148 deletions(-) delete mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveCmsKitStep.cs delete mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveEfCoreRelatedCodeStep.cs delete mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveGlobalFeaturesPackageStep.cs delete mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs 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());