Add ability to define templateAttributes within a target

This allows parameterizing templates. Also change
placeholder syntax to `${placeholderName}` also for
existing placeholders `$target_name`and `$platform`
and generate warnings when using the old placeholder
syntax.
This commit is contained in:
Tom Quist
2019-03-17 14:55:15 +01:00
parent 8dd2ec89cc
commit aaae772d0e
8 changed files with 197 additions and 20 deletions
+37
View File
@@ -26,6 +26,10 @@ public class SpecLoader {
return project
}
public func validateProjectDictionaryWarnings() throws {
try projectDictionary?.validateWarnings()
}
public func generateCacheFile() throws -> CacheFile? {
guard let projectDictionary = projectDictionary,
let project = project else {
@@ -38,3 +42,36 @@ public class SpecLoader {
)
}
}
private extension Dictionary where Key == String, Value: Any {
func validateWarnings() throws {
var errors: [SpecValidationError.ValidationError] = []
if hasValueContaining("$target_name") {
errors.append(.deprecatedUsageOfPlaceholder(placeholderName: "target_name"))
}
if hasValueContaining("$platform") {
errors.append(.deprecatedUsageOfPlaceholder(placeholderName: "platform"))
}
if !errors.isEmpty {
throw SpecValidationError(errors: errors)
}
}
func hasValueContaining(_ needle: String) -> Bool {
return 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
}
}
}
}