Merge pull request #651 from kateinoigakukun/expand-any-array-template-var

Expand template variable in Array of Any
This commit is contained in:
Yonas Kolb 2019-09-11 19:51:45 +10:00 committed by GitHub
commit c2f9ff2af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 13 deletions

View File

@ -7,6 +7,10 @@
- Added `includes` to `sources` for a Target. This follows the same glob-style as `excludes` but functions as a way to only include files that match a specified pattern. Useful if you only want a certain file type, for example specifying `**/*.swift`. [#637](https://github.com/yonaskolb/XcodeGen/pull/637) @bclymer
- Support `dylib` SDK. [#650](https://github.com/yonaskolb/XcodeGen/pull/650)
#### Fixed
- Expand template variable in Array of Any [#651](https://github.com/yonaskolb/XcodeGen/pull/651) @kateinoigakukun
## 2.7.0
#### Added

View File

@ -158,18 +158,25 @@ extension Dictionary where Key == String, Value: Any {
func replaceString(_ template: String, with replacement: String) -> JSONDictionary {
var replaced: JSONDictionary = self
for (key, value) in self {
switch value {
case let dictionary as JSONDictionary:
replaced[key] = dictionary.replaceString(template, with: replacement)
case let string as String:
replaced[key] = string.replacingOccurrences(of: template, with: replacement)
case let array as [JSONDictionary]:
replaced[key] = array.map { $0.replaceString(template, with: replacement) }
case let array as [String]:
replaced[key] = array.map { $0.replacingOccurrences(of: template, with: replacement) }
default: break
}
replaced[key] = replace(value: value, template, with: replacement)
}
return replaced
}
func replace(value: Any, _ template: String, with replacement: String) -> Any {
switch value {
case let dictionary as JSONDictionary:
return dictionary.replaceString(template, with: replacement)
case let string as String:
return string.replacingOccurrences(of: template, with: replacement)
case let array as [JSONDictionary]:
return array.map { $0.replaceString(template, with: replacement) }
case let array as [String]:
return array.map { $0.replacingOccurrences(of: template, with: replacement) }
case let anyArray as [Any]:
return anyArray.map { self.replace(value: $0, template, with: replacement) }
default:
return value
}
}
}

View File

@ -463,7 +463,10 @@ class SpecLoadingTests: XCTestCase {
"targetTemplates": [
"temp": [
"platform": "iOS",
"sources": ["templateSource"],
"sources": [
"templateSource",
["path": "Sources/${target_name}"]
],
],
"temp2": [
"type": "framework",
@ -482,7 +485,7 @@ class SpecLoadingTests: XCTestCase {
try expect(target.type) == .framework // uses value
try expect(target.platform) == .iOS // uses latest value
try expect(target.deploymentTarget) == Version("1.2.0") // keeps value
try expect(target.sources) == ["replacedSource", "templateSource", "targetSource"] // merges array in order
try expect(target.sources) == ["replacedSource", "templateSource", "Sources/Framework", "targetSource"] // merges array in order and replace ${target_name}
try expect(target.configFiles["debug"]) == "Configs/Framework/debug.xcconfig" // replaces $target_name
try expect(target.configFiles["release"]) == "Configs/Framework/release.xcconfig" // replaces ${target_name}
}