Skip to content

Instantly share code, notes, and snippets.

@emarashliev
Last active July 23, 2019 09:01
Show Gist options
  • Save emarashliev/bb1549fcdef154ae23c941b6631c0df4 to your computer and use it in GitHub Desktop.
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.
#!/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