-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReorderPlist.swift
56 lines (49 loc) · 1.77 KB
/
ReorderPlist.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env swift
import Foundation
func sort<T, E, C: Comparable>(
_ arrayPath: WritableKeyPath<T, [E]>,
by sortPath: KeyPath<E, C>,
on value: T
) -> T {
var mutableValue = value
mutableValue[keyPath: arrayPath]
.sort { $0[keyPath: sortPath] < $1[keyPath: sortPath] }
return mutableValue
}
struct Info: Codable {
var availableLibraries: [Library]
var bundlePackageType: String
var xcFrameworkFormatVersion: String
enum CodingKeys: String, CodingKey {
case availableLibraries = "AvailableLibraries"
case bundlePackageType = "CFBundlePackageType"
case xcFrameworkFormatVersion = "XCFrameworkFormatVersion"
}
struct Library: Codable {
var headersPath: String
var libraryIdentifier: String
var libraryPath: String
var supportedArchitectures: [String]
var supportedPlatform: String
var supportedPlatformVariant: String?
enum CodingKeys: String, CodingKey {
case headersPath = "HeadersPath"
case libraryIdentifier = "LibraryIdentifier"
case libraryPath = "LibraryPath"
case supportedArchitectures = "SupportedArchitectures"
case supportedPlatform = "SupportedPlatform"
case supportedPlatformVariant = "SupportedPlatformVariant"
}
}
}
let decoder = PropertyListDecoder()
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml
try CommandLine.arguments
.dropFirst()
.compactMap(URL.init(fileURLWithPath:))
.map { (try Data.init(contentsOf: $0), $0) }
.map { (try decoder.decode(Info.self, from: $0), $1) }
.map { (sort(\.availableLibraries, by: \.libraryIdentifier, on: $0), $1) }
.map { (try encoder.encode($0), $1) }
.forEach { try $0.write(to: $1) }