mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2024-08-16 16:20:51 +03:00
Merge 14e4455e2f
into f8842228c5
This commit is contained in:
commit
74d5f8aa31
@ -1,6 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import JSONUtilities
|
import JSONUtilities
|
||||||
import PathKit
|
import PathKit
|
||||||
|
import XcodeGenCore
|
||||||
import Yams
|
import Yams
|
||||||
|
|
||||||
public struct SpecFile {
|
public struct SpecFile {
|
||||||
@ -26,22 +27,50 @@ public struct SpecFile {
|
|||||||
static let defaultEnable = true
|
static let defaultEnable = true
|
||||||
|
|
||||||
init?(any: Any) {
|
init?(any: Any) {
|
||||||
if let string = any as? String {
|
if let path = any as? String {
|
||||||
path = Path(string)
|
self.init(
|
||||||
relativePaths = Include.defaultRelativePaths
|
path: Path(path),
|
||||||
enable = Include.defaultEnable
|
relativePaths: Include.defaultRelativePaths,
|
||||||
|
enable: Include.defaultEnable
|
||||||
|
)
|
||||||
} else if let dictionary = any as? JSONDictionary, let path = dictionary["path"] as? String {
|
} else if let dictionary = any as? JSONDictionary, let path = dictionary["path"] as? String {
|
||||||
self.path = Path(path)
|
self.init(
|
||||||
relativePaths = Self.resolveBoolean(dictionary, key: "relativePaths") ?? Include.defaultRelativePaths
|
path: Path(path),
|
||||||
enable = Self.resolveBoolean(dictionary, key: "enable") ?? Include.defaultEnable
|
dictionary: dictionary
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private init(path: Path, relativePaths: Bool, enable: Bool) {
|
||||||
|
self.path = path
|
||||||
|
self.relativePaths = relativePaths
|
||||||
|
self.enable = enable
|
||||||
|
}
|
||||||
|
|
||||||
|
private init?(path: Path, dictionary: JSONDictionary) {
|
||||||
|
self.path = path
|
||||||
|
relativePaths = Self.resolveBoolean(dictionary, key: "relativePaths") ?? Include.defaultRelativePaths
|
||||||
|
enable = Self.resolveBoolean(dictionary, key: "enable") ?? Include.defaultEnable
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func includes(from array: [Any], basePath: Path) -> [Include] {
|
||||||
|
array.flatMap { entry -> [Include] in
|
||||||
|
if let string = entry as? String, let include = Include(any: string) {
|
||||||
|
return [include]
|
||||||
|
} else if let dictionary = entry as? JSONDictionary, let path = dictionary["path"] as? String {
|
||||||
|
return Glob(pattern: (basePath + Path(path)).normalize().string)
|
||||||
|
.compactMap { Include(path: Path($0), dictionary: dictionary) }
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static func parse(json: Any?) -> [Include] {
|
static func parse(json: Any?, basePath: Path) -> [Include] {
|
||||||
if let array = json as? [Any] {
|
if let array = json as? [Any] {
|
||||||
return array.compactMap(Include.init)
|
return includes(from: array, basePath: basePath)
|
||||||
} else if let object = json, let include = Include(any: object) {
|
} else if let object = json, let include = Include(any: object) {
|
||||||
return [include]
|
return [include]
|
||||||
} else {
|
} else {
|
||||||
@ -92,7 +121,7 @@ public struct SpecFile {
|
|||||||
|
|
||||||
let jsonDictionary = try SpecFile.loadDictionary(path: path).expand(variables: variables)
|
let jsonDictionary = try SpecFile.loadDictionary(path: path).expand(variables: variables)
|
||||||
|
|
||||||
let includes = Include.parse(json: jsonDictionary["include"])
|
let includes = Include.parse(json: jsonDictionary["include"], basePath: basePath)
|
||||||
let subSpecs: [SpecFile] = try includes
|
let subSpecs: [SpecFile] = try includes
|
||||||
.filter(\.enable)
|
.filter(\.enable)
|
||||||
.map { include in
|
.map { include in
|
||||||
|
Loading…
Reference in New Issue
Block a user