Skip to content

Commit

Permalink
Re-sort module properties after merging
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 15, 2023
1 parent 46a97d3 commit 86fa6cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Netkan/Model/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using CKAN.Versioning;
using CKAN.NetKAN.Extensions;
using CKAN.NetKAN.Transformers;

namespace CKAN.NetKAN.Model
{
Expand Down Expand Up @@ -124,8 +125,9 @@ public Metadata(YamlMappingNode yaml) : this(yaml?.ToJObject())

public static Metadata Merge(Metadata[] modules)
=> modules.Length == 1 ? modules[0]
: new Metadata(MergeJson(modules.Select(m => m._json)
.ToArray()));
: PropertySortTransformer.SortProperties(
new Metadata(MergeJson(modules.Select(m => m._json)
.ToArray())));

private static JObject MergeJson(JObject[] jsons)
{
Expand Down
3 changes: 1 addition & 2 deletions Netkan/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public static int Main(string[] args)
);
inf.ValidateCkan(ckan);
Console.WriteLine(QueueHandler.serializeCkan(
new PropertySortTransformer().Transform(ckan, null).First()
));
PropertySortTransformer.SortProperties(ckan)));
return ExitOk;
}

Expand Down
4 changes: 4 additions & 0 deletions Netkan/Transformers/PropertySortTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
yield return new Metadata(sortedJson);
}

public static Metadata SortProperties(Metadata metadata)
=> new PropertySortTransformer().Transform(metadata, null)
.First();

private static double GetPropertySortOrder(string propertyName)
=> PropertySortOrder.TryGetValue(propertyName, out int sortOrder)
? sortOrder
Expand Down

0 comments on commit 86fa6cd

Please sign in to comment.