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

feat: Remove module location and source from unwanted places #28

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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 @@ -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;
}
}
}
}
}
Loading