Skip to content

Commit

Permalink
Support custom scheme with pre/post action
Browse files Browse the repository at this point in the history
  • Loading branch information
dangthaison91 committed Feb 17, 2019
1 parent 3ee10e7 commit 953838e
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 93 deletions.
6 changes: 5 additions & 1 deletion Sources/ProjectDescription/Project.swift
Expand Up @@ -6,22 +6,26 @@ public class Project: Codable {
public let name: String
public let up: [Up]
public let targets: [Target]
public let schemes: [Scheme]
public let settings: Settings?

public enum CodingKeys: String, CodingKey {
case name
case up
case targets
case schemes
case settings
}

public init(name: String,
up: [Up] = [],
settings: Settings? = nil,
targets: [Target] = []) {
targets: [Target] = [],
schemes: [Scheme] = []) {
self.name = name
self.up = up
self.targets = targets
self.schemes = schemes
self.settings = settings
dumpIfNeeded(self)
}
Expand Down
70 changes: 68 additions & 2 deletions Sources/ProjectDescription/Scheme.swift
Expand Up @@ -8,25 +8,50 @@ public class Scheme: Codable {
public let buildAction: BuildAction?
public let testAction: TestAction?
public let runAction: RunAction?
public let archiveAction: ArchiveAction?

public enum CodingKeys: String, CodingKey {
case name
case shared
case buildAction = "build_action"
case testAction = "test_action"
case runAction = "run_action"
case archiveAction = "archive_action"
}

public init(name: String,
shared: Bool = true,
buildAction: BuildAction? = nil,
testAction: TestAction? = nil,
runAction: RunAction? = nil) {
runAction: RunAction? = nil,
archiveAction: ArchiveAction? = nil) {
self.name = name
self.shared = shared
self.buildAction = buildAction
self.testAction = testAction
self.runAction = runAction
self.archiveAction = archiveAction
}
}

// MARK: - SchemeAction

public class SchemeAction: Codable {

public let title: String
public let scriptText: String
public let target: String?

public enum CodingKeys: String, CodingKey {
case title
case scriptText
case target
}

public init(title: String = "Run Script", scriptText: String, target: String? = nil) {
self.title = title
self.scriptText = scriptText
self.target = target
}
}

Expand All @@ -51,21 +76,33 @@ public class Arguments: Codable {
// MARK: - BuildAction

public class BuildAction: Codable {

public let targets: [String]
public let preActions: [SchemeAction]
public let postActions: [SchemeAction]

public enum CodingKeys: String, CodingKey {
case targets
case preActions = "pre_actions"
case postActions = "post_actions"
}

public init(targets: [String]) {
public init(targets: [String],
preActions: [SchemeAction] = [],
postActions: [SchemeAction] = []) {
self.targets = targets
self.preActions = preActions
self.postActions = postActions
}
}

// MARK: - TestAction

public class TestAction: Codable {
public let targets: [String]
public let preActions: [SchemeAction]
public let postActions: [SchemeAction]

public let arguments: Arguments?
public let config: BuildConfiguration
public let coverage: Bool
Expand All @@ -75,16 +112,22 @@ public class TestAction: Codable {
case arguments
case config
case coverage
case preActions = "pre_actions"
case postActions = "post_actions"
}

public init(targets: [String],
arguments: Arguments? = nil,
config: BuildConfiguration = .debug,
preActions: [SchemeAction] = [],
postActions: [SchemeAction] = [],
coverage: Bool = false) {
self.targets = targets
self.arguments = arguments
self.config = config
self.coverage = coverage
self.preActions = preActions
self.postActions = postActions
}
}

Expand All @@ -109,3 +152,26 @@ public class RunAction: Codable {
self.arguments = arguments
}
}

// MARK: - ArchiveAction

public class ArchiveAction: Codable {

public let config: BuildConfiguration
public let preActions: [SchemeAction]
public let postActions: [SchemeAction]

public enum CodingKeys: String, CodingKey {
case config
case preActions = "pre_actions"
case postActions = "post_actions"
}

public init(config: BuildConfiguration = .release,
preActions: [SchemeAction] = [],
postActions: [SchemeAction] = []) {
self.config = config
self.preActions = preActions
self.postActions = postActions
}
}
2 changes: 1 addition & 1 deletion Sources/TuistKit/Generator/ProjectGenerator.swift
Expand Up @@ -146,7 +146,7 @@ final class ProjectGenerator: ProjectGenerating {
/// Schemes
let generatedProject = GeneratedProject(path: xcodeprojPath,
targets: nativeTargets)
try schemesGenerator.generateTargetSchemes(project: project,
try schemesGenerator.generateSchemes(project: project,
generatedProject: generatedProject)

return generatedProject
Expand Down

0 comments on commit 953838e

Please sign in to comment.