mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
594c67fbe9
* add new option enable for include of spec * fix to see the environment variable when parsing include * add test for include with environment variable * fix how to parse boolean value * add spec about enable for include * add Change Log * fix the number of PR in changelog * fix include test to make more clear * fix test to focus enable option more * fix english error * fix to expand variable only one time * add new test case by setting environment object as NO
73 lines
2.1 KiB
Swift
73 lines
2.1 KiB
Swift
import Foundation
|
|
import JSONUtilities
|
|
import PathKit
|
|
import XcodeProj
|
|
import Yams
|
|
import Version
|
|
|
|
public class SpecLoader {
|
|
|
|
var project: Project!
|
|
public private(set) var projectDictionary: [String: Any]?
|
|
let version: Version
|
|
|
|
public init(version: Version) {
|
|
self.version = version
|
|
}
|
|
|
|
public func loadProject(path: Path, projectRoot: Path? = nil, variables: [String: String] = [:]) throws -> Project {
|
|
let spec = try SpecFile(path: path, variables: variables)
|
|
let resolvedDictionary = spec.resolvedDictionary()
|
|
let project = try Project(basePath: projectRoot ?? spec.basePath, jsonDictionary: resolvedDictionary)
|
|
|
|
self.project = project
|
|
projectDictionary = resolvedDictionary
|
|
|
|
return project
|
|
}
|
|
|
|
public func validateProjectDictionaryWarnings() throws {
|
|
try projectDictionary?.validateWarnings()
|
|
}
|
|
|
|
public func generateCacheFile() throws -> CacheFile? {
|
|
guard let projectDictionary = projectDictionary,
|
|
let project = project else {
|
|
return nil
|
|
}
|
|
return try CacheFile(
|
|
version: version,
|
|
projectDictionary: projectDictionary,
|
|
project: project
|
|
)
|
|
}
|
|
}
|
|
|
|
private extension Dictionary where Key == String, Value: Any {
|
|
|
|
func validateWarnings() throws {
|
|
let errors: [SpecValidationError.ValidationError] = []
|
|
|
|
if !errors.isEmpty {
|
|
throw SpecValidationError(errors: errors)
|
|
}
|
|
}
|
|
|
|
func hasValueContaining(_ needle: String) -> Bool {
|
|
values.contains { value in
|
|
switch value {
|
|
case let dictionary as JSONDictionary:
|
|
return dictionary.hasValueContaining(needle)
|
|
case let string as String:
|
|
return string.contains(needle)
|
|
case let array as [JSONDictionary]:
|
|
return array.contains { $0.hasValueContaining(needle) }
|
|
case let array as [String]:
|
|
return array.contains { $0.contains(needle) }
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
}
|