@@ -2,7 +2,7 @@ const simctl = require('simctl')
22
33function fixSimCtlList ( list ) {
44 // Xcode 9 `xcrun simctl list devicetypes` have obfuscated names for 2017 iPhones and Apple Watches.
5- let deviceTypeNameMap = {
5+ const deviceTypeNameMap = {
66 'iPhone2017-A' : 'iPhone 8' ,
77 'iPhone2017-B' : 'iPhone 8 Plus' ,
88 'iPhone2017-C' : 'iPhone X' ,
@@ -13,7 +13,7 @@ function fixSimCtlList (list) {
1313
1414 // `iPad Pro` in iOS 9.3 has mapped to `iPad Pro (9.7 inch)`
1515 // `Apple TV 1080p` has mapped to `Apple TV`
16- let deviceNameMap = {
16+ const deviceNameMap = {
1717 'Apple TV 1080p' : 'Apple TV' ,
1818 'iPad Pro' : 'iPad Pro (9.7-inch)'
1919 }
@@ -25,36 +25,36 @@ function fixSimCtlList (list) {
2525}
2626
2727function getDeviceTypes ( druntimes ) {
28- let options = { silent : true }
28+ const options = { silent : true }
2929 let list = simctl . list ( options ) . json
3030 list = fixSimCtlList ( list )
3131
3232 if ( ! druntimes ) {
3333 druntimes = findRuntimesGroupByDeviceProperty ( list , 'name' , true , { lowerCase : true } )
3434 }
35- let name_id_map = { }
35+ const name_id_map = { }
3636
3737 list . devicetypes . forEach ( function ( device ) {
38- name_id_map [ filterDeviceName ( device . name ) . toLowerCase ( ) ] = device . identifier
38+ name_id_map [ filterDeviceName ( device . name ) . toLowerCase ( ) ] = device . identifier
3939 } )
4040
4141 list = [ ]
42- let remove = function ( devicename , runtime ) {
42+ const remove = function ( devicename , runtime ) {
4343 // remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id
44- const deviceName = name_id_map [ devicename ] . replace ( / ^ c o m .a p p l e .C o r e S i m u l a t o r .S i m D e v i c e T y p e ./ , '' )
44+ const deviceName = name_id_map [ devicename ] . replace ( / ^ c o m .a p p l e .C o r e S i m u l a t o r .S i m D e v i c e T y p e ./ , '' )
4545 const runtimeName = runtime . replace ( / ^ i O S / , '' )
4646 list . push ( `${ deviceName } , ${ runtimeName } ` )
4747 }
4848
49- let cur = function ( devicename ) {
49+ const cur = function ( devicename ) {
5050 return function ( runtime ) {
5151 remove ( devicename , runtime )
5252 }
5353 }
5454
55- for ( let deviceName in druntimes ) {
56- let runtimes = druntimes [ deviceName ]
57- let dname = filterDeviceName ( deviceName ) . toLowerCase ( )
55+ for ( const deviceName in druntimes ) {
56+ const runtimes = druntimes [ deviceName ]
57+ const dname = filterDeviceName ( deviceName ) . toLowerCase ( )
5858
5959 if ( ! ( dname in name_id_map ) ) {
6060 continue
@@ -71,7 +71,7 @@ function fixNameKey (array, mapping) {
7171 }
7272
7373 return array . map ( function ( elem ) {
74- let name = mapping [ elem . name ]
74+ const name = mapping [ elem . name ]
7575 if ( name ) {
7676 elem . name = name
7777 }
@@ -101,8 +101,8 @@ function findRuntimesGroupByDeviceProperty (list, deviceProperty, availableOnly,
101101 }
102102 */
103103
104- let runtimes = { }
105- let available_runtimes = { }
104+ const runtimes = { }
105+ const available_runtimes = { }
106106
107107 list . runtimes . forEach ( function ( runtime ) {
108108 // runtime.name should already be normalized, 'identifier' key has the namespaced name
@@ -113,7 +113,7 @@ function findRuntimesGroupByDeviceProperty (list, deviceProperty, availableOnly,
113113 list . devices [ deviceGroup ] . forEach ( function ( device ) {
114114 // deviceGroup has not been normalized, it can either be the namespaced name, or the
115115 // human readable name. We normalize it
116- let normalizedRuntimeName = fixRuntimeName ( deviceGroup )
116+ const normalizedRuntimeName = fixRuntimeName ( deviceGroup )
117117
118118 let devicePropertyValue = device [ deviceProperty ]
119119
@@ -143,16 +143,16 @@ function parseEnvironmentVariables (envVariables, fixsymctl) {
143143 envVariables = envVariables || [ ]
144144 fixsymctl = typeof fixsymctl !== 'undefined' ? fixsymctl : true
145145
146- let envMap = { }
146+ const envMap = { }
147147 envVariables . forEach ( function ( variable ) {
148- let envPair = variable . split ( '=' , 2 )
148+ const envPair = variable . split ( '=' , 2 )
149149 if ( envPair . length === 2 ) {
150150 let key = envPair [ 0 ]
151- let value = envPair [ 1 ]
151+ const value = envPair [ 1 ]
152152 if ( fixsymctl ) {
153153 key = 'SIMCTL_CHILD_' + key
154154 }
155- envMap [ key ] = value
155+ envMap [ key ] = value
156156 }
157157 } )
158158 return envMap
@@ -161,11 +161,11 @@ function parseEnvironmentVariables (envVariables, fixsymctl) {
161161// Injects specified environment variables to the process and then runs action
162162// returns environment variables back to original state after action completes
163163function withInjectedEnvironmentVariablesToProcess ( process , envVariables , action ) {
164- let oldVariables = Object . assign ( { } , process . env )
164+ const oldVariables = Object . assign ( { } , process . env )
165165
166166 // Inject additional environment variables to process
167- for ( let key in envVariables ) {
168- let value = envVariables [ key ]
167+ for ( const key in envVariables ) {
168+ const value = envVariables [ key ]
169169 process . env [ key ] = value
170170 }
171171
@@ -186,13 +186,13 @@ function getDeviceFromDeviceTypeId (devicetypeid) {
186186 */
187187
188188 // the object to return
189- let ret_obj = {
189+ const ret_obj = {
190190 name : null ,
191191 id : null ,
192192 runtime : null
193193 }
194194
195- let options = { ' silent' : true }
195+ const options = { silent : true }
196196 let list = simctl . list ( options ) . json
197197 list = fixSimCtlList ( list )
198198
@@ -205,7 +205,7 @@ function getDeviceFromDeviceTypeId (devicetypeid) {
205205 // --devicetypeid is a string in the form "devicetype, runtime_version" (optional: runtime_version)
206206 let devicetype = null
207207 if ( arr . length < 1 ) {
208- let dv = findFirstAvailableDevice ( list )
208+ const dv = findFirstAvailableDevice ( list )
209209 console . error ( `--devicetypeid was not specified, using first available device: ${ dv . name } ` )
210210 return dv
211211 } else {
@@ -216,13 +216,13 @@ function getDeviceFromDeviceTypeId (devicetypeid) {
216216 }
217217
218218 // check whether devicetype has the "com.apple.CoreSimulator.SimDeviceType." prefix, if not, add it
219- let prefix = 'com.apple.CoreSimulator.SimDeviceType.'
219+ const prefix = 'com.apple.CoreSimulator.SimDeviceType.'
220220 if ( devicetype . indexOf ( prefix ) !== 0 ) {
221221 devicetype = prefix + devicetype
222222 }
223223
224224 // now find the devicename from the devicetype
225- let devicename_found = list . devicetypes . some ( function ( deviceGroup ) {
225+ const devicename_found = list . devicetypes . some ( function ( deviceGroup ) {
226226 if ( deviceGroup . identifier === devicetype ) {
227227 ret_obj . name = deviceGroup . name
228228 return true
@@ -247,10 +247,10 @@ function getDeviceFromDeviceTypeId (devicetypeid) {
247247 }
248248
249249 // now find the deviceid (by runtime and devicename)
250- let deviceid_found = Object . keys ( list . devices ) . some ( function ( deviceGroup ) {
250+ const deviceid_found = Object . keys ( list . devices ) . some ( function ( deviceGroup ) {
251251 // deviceGroup has not been normalized, it can either be the namespaced name, or the
252252 // human readable name. We normalize it
253- let normalizedRuntimeName = fixRuntimeName ( deviceGroup )
253+ const normalizedRuntimeName = fixRuntimeName ( deviceGroup )
254254 if ( normalizedRuntimeName === ret_obj . runtime ) {
255255 return list . devices [ deviceGroup ] . some ( function ( device ) {
256256 if ( filterDeviceName ( device . name ) . toLowerCase ( ) === filterDeviceName ( ret_obj . name ) . toLowerCase ( ) ) {
@@ -275,9 +275,9 @@ function getDeviceFromDeviceTypeId (devicetypeid) {
275275function findAvailableRuntime ( list , devicename ) {
276276 const device_name = devicename . toLowerCase ( )
277277
278- let all_druntimes = findRuntimesGroupByDeviceProperty ( list , 'name' , true , { lowerCase : true } )
279- let druntime = all_druntimes [ filterDeviceName ( device_name ) ] || all_druntimes [ device_name ]
280- let runtime_found = druntime && druntime . length > 0
278+ const all_druntimes = findRuntimesGroupByDeviceProperty ( list , 'name' , true , { lowerCase : true } )
279+ const druntime = all_druntimes [ filterDeviceName ( device_name ) ] || all_druntimes [ device_name ]
280+ const runtime_found = druntime && druntime . length > 0
281281
282282 if ( ! runtime_found ) {
283283 throw new Error ( `No available runtimes could be found for "${ devicename } ".` )
@@ -304,7 +304,7 @@ function findFirstAvailableDevice (list) {
304304 runtime : null
305305 }
306306
307- let available_runtimes = { }
307+ const available_runtimes = { }
308308
309309 list . runtimes . forEach ( function ( runtime ) {
310310 // runtime.name should already be normalized, 'identifier' key has the namespaced name
@@ -315,7 +315,7 @@ function findFirstAvailableDevice (list) {
315315 return list . devices [ deviceGroup ] . some ( function ( device ) {
316316 // deviceGroup has not been normalized, it can either be the namespaced name, or the
317317 // human readable name. We normalize it
318- let normalizedRuntimeName = fixRuntimeName ( deviceGroup )
318+ const normalizedRuntimeName = fixRuntimeName ( deviceGroup )
319319 if ( available_runtimes [ normalizedRuntimeName ] ) {
320320 ret_obj = {
321321 name : device . name ,
@@ -337,7 +337,7 @@ function fixRuntimeName (runtimeName) {
337337 const match = pattern . exec ( runtimeName )
338338
339339 if ( match ) {
340- const [ , , os , version ] = match
340+ const [ , , os , version ] = match
341341 // all or nothing -- os, version will always have a value for match
342342 return `${ os } ${ version . replace ( '-' , '.' ) } `
343343 }
0 commit comments