Last active
July 23, 2019 09:01
-
-
Save emarashliev/bb1549fcdef154ae23c941b6631c0df4 to your computer and use it in GitHub Desktop.
A swift-sh script that adds a Shell Script Build Phase to a centrist xcodeproj file.
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
#!/usr/bin/swift sh | |
import Foundation | |
import XcodeProj // @tuist | |
import PathKit | |
/// INSTRUCTIONS | |
/// install swift-sh on your mac, more info here 👉 https://github.com/mxcl/swift-sh | |
/// make this file executable $ chmod u+x AddBuildPhase.swift | |
/// then just run the file $ ./AddBuildPhase.swift | |
let path = Path("absolute-path-to-the-xcodeproj-file") // project path | |
let xcodeproj = try! XcodeProj(path: path) | |
let pbxproj = xcodeproj.pbxproj | |
let project = pbxproj.projects.first! | |
// Create a build phase | |
let buildPhase = PBXShellScriptBuildPhase() | |
buildPhase.shellScript = """ | |
if which swiftlint >/dev/null; then | |
swiftlint | |
else | |
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint" | |
fi | |
""" | |
// Add the build phase to the project | |
if let traget = project.targets.first(where: { $0.name == "App" }) { | |
traget.buildPhases.append(buildPhase) | |
pbxproj.add(object: buildPhase) | |
} | |
try! xcodeproj.write(path: path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment