diff --git a/src/lib.js b/src/lib.js index 1063851..902ccad 100644 --- a/src/lib.js +++ b/src/lib.js @@ -141,6 +141,7 @@ function getDeviceFromDeviceTypeId(devicetypeid) { var options = { 'silent': true }; var list = simctl.list(options).json; + list = fixSimCtlList(list); var arr = []; if (devicetypeid) { @@ -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() { @@ -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) { @@ -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 = {}; @@ -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; }