Browse Source

Partial implemented: CLI template build symbols.

pull/8168/head
Halil İbrahim Kalkan 6 years ago
parent
commit
73f8f03a9c
  1. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ProjectBuildContext.cs
  2. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs
  3. 53
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs

6
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<string> 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<string>();
Result = new ProjectResult();
}

2
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();
}
}

53
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<string> symbols)
{
RemoveMarkedTemplateCode(file, "<TEMPLATE-REMOVE>");
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, $"<TEMPLATE-REMOVE {conditionName}='{condition}'>");
}
//TODO: Remove this method and switch to symbol usage
private static void RemoveMarkedTemplateCode(this FileEntry file, string beginMark)
{
if (!file.Content.Contains("</TEMPLATE-REMOVE>"))
@ -94,5 +98,48 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files
file.SetLines(newLines);
}
private static void RemoveMarkedTemplateCode(this FileEntry file, List<string> symbols)
{
if (!file.Content.Contains("</TEMPLATE-REMOVE>"))
{
return;
}
file.NormalizeLineEndings();
var lines = file.GetLines();
var newLines = new List<string>();
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].Contains("<TEMPLATE-REMOVE"))
{
//TODO: PARSE symbol and condition (if available) !!!
var symbol = "UI-Angular"; //extract from IF/IF-NOT or set as null
var condition = true; //IF: true / IF-NOT: false
if (symbol != null &&
condition != symbols.Contains(symbol))
{
continue;
}
while (i < lines.Length && !lines[i].Contains("</TEMPLATE-REMOVE>"))
{
++i;
}
++i;
}
if (i < lines.Length)
{
newLines.Add(lines[i]);
}
}
file.SetLines(newLines);
}
}
}

Loading…
Cancel
Save