Skip to content

Commit c5445c1

Browse files
authored
Shows devicetypes for new iPhones, Apple Watches released fall 2017 (#219)
* Shows devicetypes for new iPhones, Apple Watches released fall 2017 This closes #218
1 parent 4bbe6b3 commit c5445c1

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/lib.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function getDeviceFromDeviceTypeId(devicetypeid) {
141141

142142
var options = { 'silent': true };
143143
var list = simctl.list(options).json;
144+
list = fixSimCtlList(list);
144145

145146
var arr = [];
146147
if (devicetypeid) {
@@ -265,6 +266,44 @@ function filterDeviceName(deviceName) {
265266
return deviceName;
266267
}
267268

269+
function fixNameKey(array, mapping) {
270+
if (!array || !mapping) {
271+
return array;
272+
}
273+
274+
return array.map(function(elem) {
275+
var name = mapping[elem.name];
276+
if (name) {
277+
elem.name = name;
278+
}
279+
return elem;
280+
});
281+
}
282+
283+
function fixSimCtlList(list) {
284+
// Xcode 9 `xcrun simctl list devicetypes` have obfuscated names for 2017 iPhones and Apple Watches.
285+
var deviceTypeNameMap = {
286+
'iPhone2017-A': 'iPhone 8',
287+
'iPhone2017-B': 'iPhone 8 Plus',
288+
'iPhone2017-C': 'iPhone X',
289+
'Watch2017 - 38mm': 'Apple Watch Series 3 - 38mm',
290+
'Watch2017 - 42mm': 'Apple Watch Series 3 - 42mm'
291+
};
292+
list.devicetypes = fixNameKey(list.devicetypes, deviceTypeNameMap);
293+
294+
// `iPad Pro` in iOS 9.3 has mapped to `iPad Pro (9.7 inch)`
295+
// `Apple TV 1080p` has mapped to `Apple TV`
296+
var deviceNameMap = {
297+
'Apple TV 1080p': 'Apple TV',
298+
'iPad Pro': 'iPad Pro (9.7-inch)'
299+
};
300+
Object.keys(list.devices).forEach(function(key) {
301+
list.devices[key] = fixNameKey(list.devices[key], deviceNameMap);
302+
});
303+
304+
return list;
305+
}
306+
268307
var lib = {
269308

270309
init: function() {
@@ -287,6 +326,7 @@ var lib = {
287326
showsdks: function(args) {
288327
var options = { silent: true, runtimes: true };
289328
var list = simctl.list(options).json;
329+
list = fixSimCtlList(list);
290330

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

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

329370
if (!(dname in name_id_map)) {
371+
372+
console.log('----> DNAME', dname);
373+
console.log('----> RUNTIMES', runtimes);
330374
continue;
331375
}
332376

0 commit comments

Comments
 (0)