Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function findFirstAvailableDevice(list) {
return ret_obj;
}

function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly) {
function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly, options = {}) {
/*
// Example result:
{
Expand All @@ -91,6 +91,9 @@ function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly)
list.devices[deviceGroup].forEach(function(device) {
var devicePropertyValue = device[deviceProperty];

if (options.lowerCase) {
devicePropertyValue = devicePropertyValue.toLowerCase();
}
if (!runtimes[devicePropertyValue]) {
runtimes[devicePropertyValue] = [];
}
Expand All @@ -108,8 +111,9 @@ function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly)
}

function findAvailableRuntime(list, device_name) {
device_name = device_name.toLowerCase();

var all_druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true);
var all_druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true, { lowerCase: true });
var druntime = all_druntimes[ filterDeviceName(device_name) ] || all_druntimes[ device_name ];
var runtime_found = druntime && druntime.length > 0;

Expand Down Expand Up @@ -199,7 +203,7 @@ function getDeviceFromDeviceTypeId(devicetypeid) {
// found the runtime, now find the actual device matching devicename
if (deviceGroup === ret_obj.runtime) {
return list.devices[deviceGroup].some(function(device) {
if (filterDeviceName(device.name) === filterDeviceName(ret_obj.name)) {
if (filterDeviceName(device.name).toLowerCase() === filterDeviceName(ret_obj.name).toLowerCase()) {
ret_obj.id = device.udid;
return true;
}
Expand Down Expand Up @@ -260,9 +264,13 @@ function withInjectedEnvironmentVariablesToProcess(process, envVariables, action
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
function filterDeviceName(deviceName) {
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
if (deviceName.indexOf('iPad Pro') === 0) {
if (/^iPad Pro/i.test(deviceName)) {
return deviceName.replace(/\-/g, ' ').trim();
}
// replace ʀ in iPhone Xʀ
if (deviceName.indexOf('ʀ') > -1) {
return deviceName.replace('ʀ', 'R');
}
return deviceName;
}

Expand Down Expand Up @@ -345,11 +353,11 @@ var lib = {
var list = simctl.list(options).json;
list = fixSimCtlList(list);

var druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true);
var druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true, { lowerCase: true });
var name_id_map = {};

list.devicetypes.forEach(function(device) {
name_id_map[ filterDeviceName(device.name) ] = device.identifier;
name_id_map[ filterDeviceName(device.name).toLowerCase() ] = device.identifier;
});

list = [];
Expand All @@ -366,7 +374,7 @@ var lib = {

for (var deviceName in druntimes) {
var runtimes = druntimes[ deviceName ];
var dname = filterDeviceName(deviceName);
var dname = filterDeviceName(deviceName).toLowerCase();

if (!(dname in name_id_map)) {
continue;
Expand Down