Files
XcodeGen/Sources/ProjectSpec/Yaml.swift
T
Maciej Piotrowski 4d6e63e880 Adds uncluttering dumped YAML manifest from nil entries. (#858)
* Adds uncluttering dumped YAML manifest from `nil` entries.

* Uses required type of a dictionary

* Update CHANGELOG.md

Co-authored-by: Maciej Piotrowski <maciej.piotrowski@allegro.pl>
2020-05-11 20:51:01 +10:00

25 lines
730 B
Swift

import Foundation
import PathKit
import Yams
public func loadYamlDictionary(path: Path) throws -> [String: Any] {
let string: String = try path.read()
if string == "" {
return [:]
}
let resolver = Resolver.default
.removing(.null) // remove rule so that empty quotes are treated as empty strings
guard let yaml = try Yams.load(yaml: string, resolver) else {
return [:]
}
return yaml as? [String: Any] ?? [:]
}
public func dumpYamlDictionary(_ dictionary: [String: Any], path: Path) throws {
let uncluttered = (dictionary as [String: Any?]).removingEmptyArraysDictionariesAndNils()
let string: String = try Yams.dump(object: uncluttered)
try path.write(string)
}