filter out nulls from all yaml files including setting presets

This commit is contained in:
Yonas Kolb committed 2017-09-29 18:20:36 +02:00
1 parent dc916ae5ec
commit eef423970f
5 files changed
+51 -38

No files matched your search

+1
View File
@@ -8,6 +8,7 @@
- Fixed wrong carthage directory name reference for macOS [#74](https://github.com/yonaskolb/XcodeGen/pull/74) @toshi0383
- Removed unnecessary `carthage copy-frameworks` for macOS app target [#76](https://github.com/yonaskolb/XcodeGen/pull/76) @toshi0383
- Added some missing default settings for framework targets. `SKIP_INSTALL: YES` fixes archiving
- Filter out nulls from setting presets if specifying an empty string
[Commits](https://github.com/yonaskolb/XcodeGen/compare/1.2.2...1.2.3)
@@ -380,8 +380,11 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_TESTABILITY = YES;
INFOPLIST_FILE = MyFramework/Info.plist;
@@ -393,6 +396,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.MyFramework;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
@@ -579,8 +583,11 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_TESTABILITY = YES;
INFOPLIST_FILE = MyFramework/Info.plist;
@@ -592,6 +599,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.MyFramework;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
+1 -13
View File
@@ -110,23 +110,11 @@ extension SettingsPresetFile {
return nil
}
guard let buildSettings = try? loadSettings(path: settingsPath) else {
guard let buildSettings = try? loadYamlDictionary(path: settingsPath) else {
print("Error parsing \"\(name)\" settings")
return nil
}
buildSettingFiles[path] = buildSettings
return buildSettings
}
public func loadSettings(path: Path) throws -> BuildSettings {
let content: String = try path.read()
if content == "" {
return [:]
}
let yaml = try Yams.load(yaml: content)
guard let dictionary = yaml as? JSONDictionary else {
throw JSONUtilsError.fileNotAJSONDictionary
}
return dictionary
}
}
+2 -25
View File
@@ -16,16 +16,11 @@ public struct SpecLoader {
public static func loadSpec(path: Path) throws -> ProjectSpec {
let dictionary = try loadDictionary(path: path)
let filteredDictionary = SpecLoader.filterNull(dictionary) as! [String: Any]
return try ProjectSpec(jsonDictionary: filteredDictionary)
return try ProjectSpec(jsonDictionary: dictionary)
}
private static func loadDictionary(path: Path) throws -> JSONDictionary {
let string: String = try path.read()
let yaml = try Yams.load(yaml: string)
guard var json = yaml as? JSONDictionary else {
throw JSONUtilsError.fileNotAJSONDictionary
}
var json = try loadYamlDictionary(path: path)
var includes: [String]
if let includeString = json["include"] as? String {
@@ -65,22 +60,4 @@ public struct SpecLoader {
}
return merged
}
private static func filterNull(_ object: Any) -> Any {
var returnedValue: Any = object
if let dict = object as? [String: Any] {
var mutabledic: [String: Any] = [:]
for (key, value) in dict {
mutabledic[key] = SpecLoader.filterNull(value)
}
returnedValue = mutabledic
} else if let array = object as? [Any] {
var mutableArray: [Any] = array
for (index, value) in array.enumerated() {
mutableArray[index] = SpecLoader.filterNull(value)
}
returnedValue = mutableArray
}
return (object is NSNull) ? "" : returnedValue
}
}
+39
View File
@@ -0,0 +1,39 @@
//
// YamsExtensions.swift
// XcodeGenKit
//
// Created by Yonas Kolb on 29/9/17.
//
import Foundation
import Yams
import PathKit
func loadYamlDictionary(path: Path) throws -> [String: Any] {
let string: String = try path.read()
if string == "" {
return [:]
}
guard let yaml = try Yams.load(yaml: string) else {
return [:]
}
return filterNull(yaml) as! [String: Any]
}
fileprivate func filterNull(_ object: Any) -> Any {
var returnedValue: Any = object
if let dict = object as? [String: Any] {
var mutabledic: [String: Any] = [:]
for (key, value) in dict {
mutabledic[key] = filterNull(value)
}
returnedValue = mutabledic
} else if let array = object as? [Any] {
var mutableArray: [Any] = array
for (index, value) in array.enumerated() {
mutableArray[index] = filterNull(value)
}
returnedValue = mutableArray
}
return (object is NSNull) ? "" : returnedValue
}