Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Custom File Name for
.xcodeproj
at Model Level (#462)
* using custom file name * swiftformat * use file name from model * changelog * fix test * enum suffix, prefix, test, and new fixture * acceptance test * swiftformat * new api * docs and clean ups * swiftformat and clean up * expose less at generator level, tuist config tests for code coverage * more code coverage? * clean ups * clean ups * pr suggestions * swift format * fixes tests from changes in master
- Loading branch information
Showing
16 changed files
with
330 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Foundation | ||
|
||
public struct TemplateString: Encodable, Decodable, Equatable { | ||
/// Contains a string that can be interpolated with options. | ||
let rawString: String | ||
} | ||
|
||
extension TemplateString: ExpressibleByStringLiteral { | ||
public init(stringLiteral: String) { | ||
rawString = stringLiteral | ||
} | ||
} | ||
|
||
extension TemplateString: CustomStringConvertible { | ||
public var description: String { | ||
return rawString | ||
} | ||
} | ||
|
||
extension TemplateString: ExpressibleByStringInterpolation { | ||
public init(stringInterpolation: StringInterpolation) { | ||
rawString = stringInterpolation.string | ||
} | ||
|
||
public struct StringInterpolation: StringInterpolationProtocol { | ||
var string: String | ||
|
||
public init(literalCapacity _: Int, interpolationCount _: Int) { | ||
string = String() | ||
} | ||
|
||
public mutating func appendLiteral(_ literal: String) { | ||
string.append(literal) | ||
} | ||
|
||
public mutating func appendInterpolation(_ token: TemplateString.Token) { | ||
string.append(token.rawValue) | ||
} | ||
} | ||
} | ||
|
||
extension TemplateString { | ||
/// Provides a template for existing project properties. | ||
/// | ||
/// - projectName: The name of the project. | ||
public enum Token: String { | ||
case projectName = "${project_name}" | ||
} | ||
} | ||
|
||
public func == (lhs: TemplateString.Token, rhs: TemplateString.Token) -> Bool { | ||
switch (lhs, rhs) { | ||
case (.projectName, .projectName): | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,74 @@ | ||
import Foundation | ||
|
||
/// This model allows to configure Tuist. | ||
public class TuistConfig: Codable { | ||
public class TuistConfig: Encodable, Decodable, Equatable { | ||
/// Contains options related to the project generation. | ||
/// | ||
/// - generateManifestElement: When passed, Tuist generates the projects, targets and schemes to compile the project manifest. | ||
public enum GenerationOption: String, Codable { | ||
/// - xcodeProjectName(TemplateString): When passed, Tuist generates the project with the specific name on disk instead of using the project name. | ||
public enum GenerationOptions: Encodable, Decodable, Equatable { | ||
case generateManifest | ||
case xcodeProjectName(TemplateString) | ||
} | ||
|
||
/// Generation options. | ||
public let generationOptions: [GenerationOption] | ||
public let generationOptions: [GenerationOptions] | ||
|
||
/// Initializes the tuist cofiguration. | ||
/// | ||
/// - Parameter generationOptions: Generation options. | ||
public init(generationOptions: [GenerationOption]) { | ||
public init(generationOptions: [GenerationOptions]) { | ||
self.generationOptions = generationOptions | ||
dumpIfNeeded(self) | ||
} | ||
} | ||
|
||
extension TuistConfig.GenerationOptions { | ||
enum CodingKeys: String, CodingKey { | ||
case generateManifest | ||
case xcodeProjectName | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
if container.allKeys.contains(.generateManifest), try container.decodeNil(forKey: .generateManifest) == false { | ||
self = .generateManifest | ||
return | ||
} | ||
if container.allKeys.contains(.xcodeProjectName), try container.decodeNil(forKey: .xcodeProjectName) == false { | ||
var associatedValues = try container.nestedUnkeyedContainer(forKey: .xcodeProjectName) | ||
let templateProjectName = try associatedValues.decode(TemplateString.self) | ||
self = .xcodeProjectName(templateProjectName) | ||
return | ||
} | ||
throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Unknown enum case")) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
switch self { | ||
case .generateManifest: | ||
_ = container.nestedContainer(keyedBy: CodingKeys.self, forKey: .generateManifest) | ||
case let .xcodeProjectName(templateProjectName): | ||
var associatedValues = container.nestedUnkeyedContainer(forKey: .xcodeProjectName) | ||
try associatedValues.encode(templateProjectName) | ||
} | ||
} | ||
} | ||
|
||
public func == (lhs: TuistConfig, rhs: TuistConfig) -> Bool { | ||
guard lhs.generationOptions == rhs.generationOptions else { return false } | ||
return true | ||
} | ||
|
||
public func == (lhs: TuistConfig.GenerationOptions, rhs: TuistConfig.GenerationOptions) -> Bool { | ||
switch (lhs, rhs) { | ||
case (.generateManifest, .generateManifest): | ||
return true | ||
case let (.xcodeProjectName(lhs), .xcodeProjectName(rhs)): | ||
return lhs.rawString == rhs.rawString | ||
default: return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import ProjectDescription | ||
|
||
final class TuistConfigTests: XCTestCase { | ||
func test_tuistconfig_toJSON() throws { | ||
let tuistConfig = TuistConfig(generationOptions: | ||
[.generateManifest, | ||
.xcodeProjectName("someprefix-\(.projectName)")]) | ||
|
||
XCTAssertCodable(tuistConfig) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.