-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
69 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,42 @@ | ||
import Foundation | ||
import ProjectSpec | ||
import PathKit | ||
|
||
public class InfoPlistGenerator { | ||
|
||
/** | ||
Default info plist attributes taken from: | ||
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Base/Base_DefinitionsInfoPlist.xctemplate/TemplateInfo.plist | ||
*/ | ||
var defaultInfoPlist: [String: Any] = { | ||
var dictionary: [String: Any] = [:] | ||
dictionary["CFBundleIdentifier"] = "$(PRODUCT_BUNDLE_IDENTIFIER)" | ||
dictionary["CFBundleInfoDictionaryVersion"] = "6.0" | ||
dictionary["CFBundleExecutable"] = "$(EXECUTABLE_NAME)" | ||
dictionary["CFBundleName"] = "$(PRODUCT_NAME)" | ||
dictionary["CFBundleDevelopmentRegion"] = "$(DEVELOPMENT_LANGUAGE)" | ||
dictionary["CFBundleShortVersionString"] = "1.0" | ||
dictionary["CFBundleVersion"] = "1" | ||
return dictionary | ||
}() | ||
|
||
public func generateAttributes(target: Target) -> [String: Any] { | ||
var targetInfoPlist = defaultInfoPlist | ||
switch target.type { | ||
case .uiTestBundle, | ||
.unitTestBundle: | ||
targetInfoPlist["CFBundlePackageType"] = "BNDL" | ||
case .application, | ||
.watch2App: | ||
targetInfoPlist["CFBundlePackageType"] = "APPL" | ||
case .framework: | ||
targetInfoPlist["CFBundlePackageType"] = "FMWK" | ||
case .bundle: | ||
targetInfoPlist["CFBundlePackageType"] = "BNDL" | ||
case .xpcService: | ||
targetInfoPlist["CFBundlePackageType"] = "XPC" | ||
default: break | ||
} | ||
return targetInfoPlist | ||
} | ||
} |
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,51 @@ | ||
import Foundation | ||
import ProjectSpec | ||
import xcodeproj | ||
import PathKit | ||
|
||
public class ProjectWriter { | ||
|
||
let project: Project | ||
|
||
public init(project: Project) { | ||
self.project = project | ||
} | ||
|
||
public func writeXcodeProject(_ xcodeProject: XcodeProj) throws { | ||
let projectPath = project.projectPath | ||
let tempPath = Path.temporary + "XcodeGen_\(Int(NSTimeIntervalSince1970))" | ||
try? tempPath.delete() | ||
if projectPath.exists { | ||
try projectPath.copy(tempPath) | ||
} | ||
try xcodeProject.write(path: tempPath, override: true) | ||
try? projectPath.delete() | ||
try tempPath.copy(projectPath) | ||
try? tempPath.delete() | ||
} | ||
|
||
public func writePlists() throws { | ||
|
||
let infoPlistGenerator = InfoPlistGenerator() | ||
for target in project.targets { | ||
// write Info.plist | ||
if let plist = target.info { | ||
let path = project.basePath + plist.path | ||
let attributes = infoPlistGenerator.generateAttributes(target: target).merged(plist.attributes) | ||
let data = try PropertyListSerialization.data(fromPropertyList: attributes, format: .xml, options: 0) | ||
try? path.delete() | ||
try path.parent().mkpath() | ||
try path.write(data) | ||
} | ||
|
||
// write entitlements | ||
if let plist = target.entitlements { | ||
let path = project.basePath + plist.path | ||
let data = try PropertyListSerialization.data(fromPropertyList: plist.attributes, format: .xml, options: 0) | ||
try? path.delete() | ||
try path.parent().mkpath() | ||
try path.write(data) | ||
} | ||
} | ||
} | ||
} |
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