class Terrestrial::Cli::SimulatorLauncher
Constants
- WORKING_DIR
Public Class Methods
new(args: nil, scheme: nil)
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 7 def initialize(args: nil, scheme: nil) @scheme = scheme @args = args end
Public Instance Methods
run()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 12 def run cleanup_simulator build_app launch_simulator wait_until_simulator_booted reinstall_app launch_app_with_args end
Private Instance Methods
app_name()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 78 def app_name @app_name ||= File.basename(project_path).split(".").first end
args()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 82 def args @args ||= {} end
build_app()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 31 def build_app c = "xcodebuild #{is_workspace? ? '-workspace' : '-project' } \"#{project_path}\" " + "-destination 'platform=iOS Simulator,name=iPhone 6s' " + "-scheme #{scheme} " + "-configuration Debug clean build CONFIGURATION_BUILD_DIR=#{WORKING_DIR}" `#{c}` end
bundle_identifer()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 94 def bundle_identifer # Fetch the bundle identifier from the project's Info.plist folder @bundle_identifer ||= `defaults read \"#{Dir[WORKING_DIR + '/*.app/Info.plist'].first}\" CFBundleIdentifier`.chomp end
bundle_name()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 99 def bundle_name # Fetch the bundle display name from the project's Info.plist folder @bundle_name ||= `defaults read \"#{Dir[WORKING_DIR + '/*.app/Info.plist'].first}\" CFBundleName`.chomp end
cleanup_simulator()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 24 def cleanup_simulator ensure_var_folder_exists system("killall \"Simulator\" &> /dev/null") `rm -rf #{WORKING_DIR}` end
ensure_var_folder_exists()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 90 def ensure_var_folder_exists `mkdir -p #{WORKING_DIR}` end
is_workspace?()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 86 def is_workspace? project_path.end_with?('xcworkspace') end
launch_app_with_args()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 61 def launch_app_with_args c = "xcrun simctl launch booted #{bundle_identifer} --args " + LaunchArgsBuilder.build(args) `#{c}` end
launch_simulator()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 40 def launch_simulator `open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app` end
project_path()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 67 def project_path # Try to find a workspace, fall back to project, finally fail @project_path ||= Dir["#{Config[:directory]}/*.xcworkspace"][0] || Dir["#{Config[:directory]}/*.xcodeproj"][0] || raise('Could not find workspace or project in folder') end
reinstall_app()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 56 def reinstall_app `xcrun simctl uninstall booted #{bundle_identifer}` `xcrun simctl install booted "#{Dir[WORKING_DIR + "/" + (bundle_name) + ".app"].first}"` end
scheme()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 74 def scheme @scheme || app_name end
wait_until_simulator_booted()
click to toggle source
# File lib/terrestrial/cli/simulator_launcher.rb, line 44 def wait_until_simulator_booted wait_until_booted = %{ count=`xcrun simctl list | grep Booted | wc -l | sed -e 's/ //g'` while [ $count -lt 1 ] do sleep 1 count=`xcrun simctl list | grep Booted | wc -l | sed -e 's/ //g'` done } `#{wait_until_booted}` end