Skip to content

Commit

Permalink
Merge pull request #28 from EAVFW/tst/docs-assembly-xml
Browse files Browse the repository at this point in the history
feat: Remove module location and source from unwanted places
  • Loading branch information
thygesteffensen authored Nov 30, 2023
2 parents 87122d6 + 1035e1a commit 965c101
Showing 1 changed file with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.FileSystemGlobbing;
using Newtonsoft.Json.Linq;

namespace EAVFW.Extensions.Manifest.ManifestEnricherTool
Expand All @@ -15,7 +16,7 @@ public ManifestMerger(IModuleMetadataEnricher moduleMetadataEnricher)
_moduleMetadataEnricher =
moduleMetadataEnricher ?? throw new ArgumentNullException(nameof(moduleMetadataEnricher));
}

/// <inheritdoc/>
public async Task<JToken> MergeManifests(FileInfo path)
{
Expand All @@ -41,12 +42,44 @@ public async Task<JToken> MergeManifests(FileInfo path)
{
// union array values together to avoid duplicates
MergeArrayHandling = MergeArrayHandling.Union,
PropertyNameComparison = System.StringComparison.OrdinalIgnoreCase,
PropertyNameComparison = StringComparison.OrdinalIgnoreCase,
MergeNullValueHandling = MergeNullValueHandling.Ignore
});
}

var matcher = new Matcher();
matcher.AddInclude("**/entities/*");
matcher.AddInclude("**/attributes/*");
matcher.AddInclude("**/wizards/*");

CleanModuleLocationSource(jtokenRaw, matcher, "root");

return jsonRaw;
}

private static void CleanModuleLocationSource(JToken jToken, Matcher matcher, string path)
{
switch (jToken)
{
case JObject jObject:
{
if (!matcher.Match(path).HasMatches)
{
jObject.Remove("moduleSource");
jObject.Remove("moduleLocation");
}

foreach (var (key, value) in jObject)
CleanModuleLocationSource(value, matcher, $"{path}/{key}");
break;
}
case JArray jArray:
{
foreach (var child in jArray.Children())
CleanModuleLocationSource(child, matcher, path);
break;
}
}
}
}
}

0 comments on commit 965c101

Please sign in to comment.