mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2024-12-11 07:16:40 +03:00
Merge pull request #651 from kateinoigakukun/expand-any-array-template-var
Expand template variable in Array of Any
This commit is contained in:
commit
c2f9ff2af8
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user