Created
January 7, 2017 21:19
-
-
Save wowbroforce/d66f4d81e924eff1b9346684f2387723 to your computer and use it in GitHub Desktop.
Example of adding 'Shell Script Build Phase' to Xcode project using Fastlane action and Xcodeptoj tool
This file contains hidden or 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
module Fastlane | |
module Actions | |
module SharedValues | |
INSERT_BUILD_PHASES_CUSTOM_VALUE = :INSERT_BUILD_PHASES_CUSTOM_VALUE | |
end | |
class InsertBuildPhasesAction < Action | |
def self.run(params) | |
require 'xcodeproj' | |
project_path = "MyProject.xcodeproj" | |
target_name = "MyProject" | |
project = Xcodeproj::Project.open(project_path) | |
target = project.native_targets.select { |target| target.name == target_name }.first | |
phase = create_or_update_build_phase(target, "Copy static pages") | |
phase.shell_script = "rm -rf ~/Documents/www/webroot\nmkdir ~/Documents/www/webroot\ncp -a StaticPages/. ~/Documents/www/webroot" | |
target.build_phases << phase | |
project.save() | |
end | |
##################################################### | |
# @!group Documentation | |
##################################################### | |
def self.description | |
"Insert custom build phases after a new pbxproj file generated." | |
end | |
def self.details | |
"You can use this action to do cool things..." | |
end | |
def self.available_options | |
end | |
def self.output | |
end | |
def self.return_value | |
end | |
def self.authors | |
["wowbroforce"] | |
end | |
def self.is_supported?(platform) | |
platform == :mac | |
end | |
class << self | |
def create_or_update_build_phase(target, phase_name, phase_class = Xcodeproj::Project::Object::PBXShellScriptBuildPhase) | |
build_phases = target.build_phases.grep(phase_class) | |
build_phases.find { |phase| phase.name && phase.name.end_with?(phase_name) }.tap { |p| p.name = phase_name if p } || | |
target.project.new(phase_class).tap do |phase| | |
UI.message("Adding Build Phase '#{phase_name}' to project.") do | |
phase.name = phase_name | |
phase.show_env_vars_in_log = '0' | |
# target.build_phases << phase | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment