refactoring

This commit is contained in:
Yonas Kolb
2018-11-03 21:33:27 +11:00
parent ea2d38ecdd
commit e7ef30a241
14 changed files with 286 additions and 245 deletions
@@ -3,7 +3,7 @@ import ProjectSpec
import xcodeproj
import PathKit
public class ProjectWriter {
public class FileWriter {
let project: Project
@@ -11,8 +11,8 @@ public class ProjectWriter {
self.project = project
}
public func writeXcodeProject(_ xcodeProject: XcodeProj) throws {
let projectPath = project.projectPath
public func writeXcodeProject(_ xcodeProject: XcodeProj, to projectPath: Path? = nil) throws {
let projectPath = project.defaultProjectPath
let tempPath = Path.temporary + "XcodeGen_\(Int(NSTimeIntervalSince1970))"
try? tempPath.delete()
if projectPath.exists {
+1 -3
View File
@@ -27,9 +27,7 @@ public class PBXProjGenerator {
public init(project: Project) {
self.project = project
pbxProj = PBXProj(rootObject: nil, objectVersion: 46)
sourceGenerator = SourceGenerator(project: project) { [unowned self] object in
_ = self.addObject(object)
}
sourceGenerator = SourceGenerator(project: project, pbxProj: pbxProj)
}
func addObject<T: PBXObject>(_ object: T, context: String? = nil) -> T {
+1 -4
View File
@@ -13,10 +13,7 @@ public class ProjectGenerator {
self.project = project
}
public func generateXcodeProject(validate: Bool = true) throws -> XcodeProj {
if validate {
try project.validate()
}
public func generateXcodeProject() throws -> XcodeProj {
// generate PBXProj
let pbxProjGenerator = PBXProjGenerator(project: project)
+7 -5
View File
@@ -18,7 +18,8 @@ class SourceGenerator {
private var variantGroupsByPath: [Path: PBXVariantGroup] = [:]
private let project: Project
var addObjectClosure: (PBXObject) -> Void
let pbxProj: PBXProj
var targetSourceExcludePaths: Set<Path> = []
var defaultExcludedFiles = [
".DS_Store",
@@ -26,13 +27,14 @@ class SourceGenerator {
private(set) var knownRegions: Set<String> = []
init(project: Project, addObjectClosure: @escaping (PBXObject) -> Void) {
init(project: Project, pbxProj: PBXProj) {
self.project = project
self.addObjectClosure = addObjectClosure
self.pbxProj = pbxProj
}
func addObject<T: PBXObject>(_ object: T) -> T {
addObjectClosure(object)
func addObject<T: PBXObject>(_ object: T, context: String? = nil) -> T {
pbxProj.add(object: object)
object.context = context
return object
}