Last active
October 11, 2018 23:38
-
-
Save NicholasTD07/088bf129492490b2d3e59441c228c4d0 to your computer and use it in GitHub Desktop.
This script can be used to delete all your iOS simulators and recreate the ones you want.
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
require 'pp' | |
require 'fastlane' | |
require 'snapshot/reset_simulators' | |
# Run the script where you have fastlane installed with `bundle exec ruby clean_up_and_create_sims.rb` | |
def delete_all_iOS_sims | |
FastlaneCore::Simulator.delete_all | |
end | |
def all_iOS_sims | |
FastlaneCore::Simulator.all | |
end | |
def all_iOS_devices | |
Snapshot::ResetSimulators.devices | |
end | |
def all_iOS_runtimes | |
Snapshot::ResetSimulators.runtimes | |
end | |
def all_iOS_device_types | |
`xcrun simctl list devicetypes` | |
.scan(/(.*)\s\((.*)\)/) | |
.reject { |device| | |
device.join.include? "TV" or device.join.include? "Watch" | |
} | |
end | |
def all_iOS_device_type_names | |
all_iOS_device_types.map { |device| device[0] } | |
end | |
def filter_runtimes(all_runtimes, os = 'iOS', versions = []) | |
all_runtimes.select { |v, id| v[/^#{os}/] }.select { |v, id| v[/#{versions.join("|")}$/] } | |
end | |
def all_iOS_versions | |
filter_runtimes(all_iOS_runtimes, 'iOS') | |
end | |
def create(device_type, os_versions, os_name = 'iOS') | |
os_versions.each do |os_version| | |
puts "Creating #{device_type[0]} for #{os_name} version #{os_version[0]}" | |
command = "xcrun simctl create '#{device_type[0]} #{os_version[0]}' #{device_type[1]} #{os_version[1]}" | |
puts command | |
`#{command}` | |
end | |
end | |
# pp all_iOS_versions | |
# pp all_iOS_device_types | |
iOS_versions = [ | |
["iOS 12.0", "com.apple.CoreSimulator.SimRuntime.iOS-12-0"] | |
] | |
iOS_device_types = [ | |
["iPhone 4s", "com.apple.CoreSimulator.SimDeviceType.iPhone-4s"], | |
["iPhone 5", "com.apple.CoreSimulator.SimDeviceType.iPhone-5"], | |
["iPhone 5s", "com.apple.CoreSimulator.SimDeviceType.iPhone-5s"], | |
["iPhone 6", "com.apple.CoreSimulator.SimDeviceType.iPhone-6"], | |
["iPhone 6 Plus", "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus"], | |
["iPhone 6s", "com.apple.CoreSimulator.SimDeviceType.iPhone-6s"], | |
["iPhone 6s Plus", "com.apple.CoreSimulator.SimDeviceType.iPhone-6s-Plus"], | |
["iPhone 7", "com.apple.CoreSimulator.SimDeviceType.iPhone-7"], | |
["iPhone 7 Plus", "com.apple.CoreSimulator.SimDeviceType.iPhone-7-Plus"], | |
["iPhone 8", "com.apple.CoreSimulator.SimDeviceType.iPhone-8"], | |
["iPhone 8 Plus", "com.apple.CoreSimulator.SimDeviceType.iPhone-8-Plus"], | |
["iPhone SE", "com.apple.CoreSimulator.SimDeviceType.iPhone-SE"], | |
["iPhone X", "com.apple.CoreSimulator.SimDeviceType.iPhone-X"], | |
["iPhone XR", "com.apple.CoreSimulator.SimDeviceType.iPhone-XR"], | |
["iPhone XS", "com.apple.CoreSimulator.SimDeviceType.iPhone-XS"], | |
["iPhone XS Max", "com.apple.CoreSimulator.SimDeviceType.iPhone-XS-Max"], | |
["iPad 2", "com.apple.CoreSimulator.SimDeviceType.iPad-2"], | |
["iPad Retina", "com.apple.CoreSimulator.SimDeviceType.iPad-Retina"], | |
["iPad Air", "com.apple.CoreSimulator.SimDeviceType.iPad-Air"], | |
["iPad Air 2", "com.apple.CoreSimulator.SimDeviceType.iPad-Air-2"], | |
["iPad (5th generation)", | |
"com.apple.CoreSimulator.SimDeviceType.iPad--5th-generation-"], | |
["iPad Pro (9.7-inch)", | |
"com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-"], | |
["iPad Pro (12.9-inch)", "com.apple.CoreSimulator.SimDeviceType.iPad-Pro"], | |
["iPad Pro (12.9-inch) (2nd generation)", | |
"com.apple.CoreSimulator.SimDeviceType.iPad-Pro--12-9-inch---2nd-generation-"], | |
["iPad Pro (10.5-inch)", | |
"com.apple.CoreSimulator.SimDeviceType.iPad-Pro--10-5-inch-"], | |
["iPad (6th generation)", | |
"com.apple.CoreSimulator.SimDeviceType.iPad--6th-generation-"] | |
] | |
oses = [ | |
# ["iOS 10.3", "com.apple.CoreSimulator.SimRuntime.iOS-10-3"], | |
# ["iOS 11.4", "com.apple.CoreSimulator.SimRuntime.iOS-11-4"] | |
] | |
devices = [ | |
["iPhone SE", "com.apple.CoreSimulator.SimDeviceType.iPhone-SE"], | |
["iPhone 8", "com.apple.CoreSimulator.SimDeviceType.iPhone-8"], | |
["iPhone X", "com.apple.CoreSimulator.SimDeviceType.iPhone-X"], | |
["iPad Air", "com.apple.CoreSimulator.SimDeviceType.iPad-Air"], | |
] | |
os_devices_pairs = [ # [os: [device]] | |
[ | |
["iOS 11.4", "com.apple.CoreSimulator.SimRuntime.iOS-11-4"], # os | |
[ # devices | |
["iPhone 8", "com.apple.CoreSimulator.SimDeviceType.iPhone-8"], | |
["iPhone X", "com.apple.CoreSimulator.SimDeviceType.iPhone-X"], | |
] | |
], | |
[ | |
["iOS 10.3", "com.apple.CoreSimulator.SimRuntime.iOS-10-3"], # os | |
[ # devices | |
["iPhone SE", "com.apple.CoreSimulator.SimDeviceType.iPhone-SE"], | |
["iPad Air", "com.apple.CoreSimulator.SimDeviceType.iPad-Air"], | |
] | |
] | |
] | |
# Uncomment the next line to delete all iOS sims | |
# delete_all_iOS_sims | |
# Edit os_devices_pairs to create the devices you want | |
# os_devices_pairs.each do |os_devices| | |
# os = os_devices[0] | |
# devices = os_devices[1] | |
# devices.each do |device| | |
# create(device, [os], 'iOS') | |
# end | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment