Skip to content

Commit

Permalink
Shows devicetypes for new iPhones, Apple Watches released fall 2017 (#…
Browse files Browse the repository at this point in the history
…219)

* Shows devicetypes for new iPhones, Apple Watches released fall 2017

This closes #218
  • Loading branch information
shazron committed Sep 15, 2017
1 parent 4bbe6b3 commit c5445c1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/lib.js
Expand Up @@ -141,6 +141,7 @@ function getDeviceFromDeviceTypeId(devicetypeid) {

var options = { 'silent': true };
var list = simctl.list(options).json;
list = fixSimCtlList(list);

var arr = [];
if (devicetypeid) {
Expand Down Expand Up @@ -265,6 +266,44 @@ function filterDeviceName(deviceName) {
return deviceName;
}

function fixNameKey(array, mapping) {
if (!array || !mapping) {
return array;
}

return array.map(function(elem) {
var name = mapping[elem.name];
if (name) {
elem.name = name;
}
return elem;
});
}

function fixSimCtlList(list) {
// Xcode 9 `xcrun simctl list devicetypes` have obfuscated names for 2017 iPhones and Apple Watches.
var deviceTypeNameMap = {
'iPhone2017-A': 'iPhone 8',
'iPhone2017-B': 'iPhone 8 Plus',
'iPhone2017-C': 'iPhone X',
'Watch2017 - 38mm': 'Apple Watch Series 3 - 38mm',
'Watch2017 - 42mm': 'Apple Watch Series 3 - 42mm'
};
list.devicetypes = fixNameKey(list.devicetypes, deviceTypeNameMap);

// `iPad Pro` in iOS 9.3 has mapped to `iPad Pro (9.7 inch)`
// `Apple TV 1080p` has mapped to `Apple TV`
var deviceNameMap = {
'Apple TV 1080p': 'Apple TV',
'iPad Pro': 'iPad Pro (9.7-inch)'
};
Object.keys(list.devices).forEach(function(key) {
list.devices[key] = fixNameKey(list.devices[key], deviceNameMap);
});

return list;
}

var lib = {

init: function() {
Expand All @@ -287,6 +326,7 @@ var lib = {
showsdks: function(args) {
var options = { silent: true, runtimes: true };
var list = simctl.list(options).json;
list = fixSimCtlList(list);

console.log('Simulator SDK Roots:');
list.runtimes.forEach(function(runtime) {
Expand All @@ -302,6 +342,7 @@ var lib = {
getdevicetypes: function(args) {
var options = { silent: true };
var list = simctl.list(options).json;
list = fixSimCtlList(list);

var druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true);
var name_id_map = {};
Expand All @@ -327,6 +368,9 @@ var lib = {
var dname = filterDeviceName(deviceName);

if (!(dname in name_id_map)) {

console.log('----> DNAME', dname);
console.log('----> RUNTIMES', runtimes);
continue;
}

Expand Down

0 comments on commit c5445c1

Please sign in to comment.