Permalink
Switch branches/tags
Nothing to show
Find file Copy path
96637d5 Dec 17, 2017
1 contributor

Users who have contributed to this file

142 lines (116 sloc) 2.47 KB
//
// BuildContext.swift
// FastlaneRunner
//
// Created by matsuokah on 2017/12/16.
// Copyright © 2017 Joshua Liebowitz. All rights reserved.
//
import Foundation
enum ApplicationEnv: String {
case staging
case production
}
enum Configuration: String {
case debug
case release
var exportMethod: ExportMethod {
switch self {
case .release:
return .appStore
default:
return .development
}
}
}
enum BuildTarget: String {
case iOS
}
enum Scheme: String {
case fastlaneSwiftFile
var displayName: String {
switch self {
case .fastlaneSwiftFile:
return "Fastlane Swift Fastfile"
}
}
}
enum ExportMethod: String {
case development
case appStore
var exportMethod: String {
switch self {
case .development:
return "development"
case .appStore:
return "app-store"
}
}
}
protocol BuildContextProtocol {
// Xcode
var workspace: String { get }
var scheme: String { get }
var configuration: String { get }
// Build
var buildDir: String { get }
var ipaName: String { get }
var ipaPath: String { get }
var dsymName: String { get }
var dsymPath: String { get }
var exportMethod: String { get }
}
struct BuildContext {
static let project = "Fastlane Swift Fastfile"
var _scheme: Scheme = .fastlaneSwiftFile
var _buildTarget: BuildTarget = .iOS
var _configuration: Configuration = .debug
}
extension BuildContext: BuildContextProtocol {
// Xcode
var workspace: String {
return BuildContext.project + ".xcworkspace"
}
var scheme: String {
return _scheme.displayName
}
var configuration: String {
return _configuration.rawValue
}
// Build
var buildDir: String {
return "Build"
}
var artifactName: String {
return [BuildContext.project, _buildTarget.rawValue, configuration].joined(separator: "-")
}
var ipaName: String {
return artifactName + ".ipa"
}
var ipaPath: String {
return [buildDir, ipaName].joined(separator: "/")
}
var dsymName: String {
return artifactName + ".app.dSYM.zip"
}
var dsymPath: String {
return [buildDir, dsymName].joined(separator: "/")
}
var exportMethod: String {
return _configuration.exportMethod.exportMethod
}
}
extension BuildContext {
func build() {
FastlaneRunner.buildApp(workspace: workspace
, scheme: scheme
, clean: true
, outputDirectory: buildDir
, outputName: ipaName
, configuration: configuration
, exportMethod: exportMethod
, buildPath: buildDir
, archivePath: buildDir
, derivedDataPath: buildDir
, buildlogPath: buildDir)
}
}