From 1035e1a4e3017dd76cf2564483854584068eb176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thyge=20Sk=C3=B8dt=20Steffensen?= <31892312+thygesteffensen@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:23:38 +0100 Subject: [PATCH] feat: Remove module location and source from unwanted places --- .../ManifestMerger.cs | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/ManifestMerger.cs b/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/ManifestMerger.cs index 48b56fd..c707653 100644 --- a/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/ManifestMerger.cs +++ b/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/ManifestMerger.cs @@ -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 @@ -15,7 +16,7 @@ public ManifestMerger(IModuleMetadataEnricher moduleMetadataEnricher) _moduleMetadataEnricher = moduleMetadataEnricher ?? throw new ArgumentNullException(nameof(moduleMetadataEnricher)); } - + /// public async Task MergeManifests(FileInfo path) { @@ -41,12 +42,44 @@ public async Task 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; + } + } + } } }