11import _ from 'lodash' ;
22import which from 'which' ;
3- import { log , LOG_PREFIX } from './logger' ;
4- import {
5- DEFAULT_EXEC_TIMEOUT , getXcrunBinary ,
6- } from './helpers' ;
7- import { exec as tpExec , SubProcess } from 'teen_process' ;
3+ import { log , LOG_PREFIX } from './logger' ;
4+ import { DEFAULT_EXEC_TIMEOUT , getXcrunBinary } from './helpers' ;
5+ import { exec as tpExec , SubProcess } from 'teen_process' ;
86import * as addmediaCommands from './subcommands/addmedia' ;
97import * as appinfoCommands from './subcommands/appinfo' ;
108import * as bootCommands from './subcommands/boot' ;
@@ -30,9 +28,7 @@ import * as terminateCommands from './subcommands/terminate';
3028import * as uiCommands from './subcommands/ui' ;
3129import * as uninstallCommands from './subcommands/uninstall' ;
3230import * as locationCommands from './subcommands/location' ;
33- import type {
34- XCRun , ExecOpts , SimctlOpts , ExecResult ,
35- } from './types' ;
31+ import type { XCRun , ExecOpts , SimctlOpts , ExecResult } from './types' ;
3632
3733const SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_' ;
3834
@@ -43,27 +39,27 @@ export class Simctl {
4339 private _udid : string | null ;
4440 private _devicesSetPath : string | null ;
4541
46- constructor ( opts : SimctlOpts = { } ) {
47- this . xcrun = _ . cloneDeep ( opts . xcrun ?? { path : null } ) ;
42+ constructor ( opts : SimctlOpts = { } ) {
43+ this . xcrun = _ . cloneDeep ( opts . xcrun ?? { path : null } ) ;
4844 this . execTimeout = opts . execTimeout ?? DEFAULT_EXEC_TIMEOUT ;
4945 this . logErrors = opts . logErrors ?? true ;
5046 this . _udid = opts . udid ?? null ;
5147 this . _devicesSetPath = opts . devicesSetPath ?? null ;
5248 }
5349
54- set udid ( value : string | null ) {
50+ set udid ( value : string | null ) {
5551 this . _udid = value ;
5652 }
5753
58- get udid ( ) : string | null {
54+ get udid ( ) : string | null {
5955 return this . _udid ;
6056 }
6157
62- set devicesSetPath ( value : string | null ) {
58+ set devicesSetPath ( value : string | null ) {
6359 this . _devicesSetPath = value ;
6460 }
6561
66- get devicesSetPath ( ) : string | null {
62+ get devicesSetPath ( ) : string | null {
6763 return this . _devicesSetPath ;
6864 }
6965
@@ -72,26 +68,30 @@ export class Simctl {
7268 * @returns The UDID string
7369 * @throws {Error } If UDID is not set
7470 */
75- requireUdid ( commandName : string | null = null ) : string {
71+ requireUdid ( commandName : string | null = null ) : string {
7672 if ( ! this . udid ) {
77- throw new Error ( `udid is required to be set for ` +
78- ( commandName ? `the '${ commandName } ' command` : 'this simctl command' ) ) ;
73+ throw new Error (
74+ `udid is required to be set for ` +
75+ ( commandName ? `the '${ commandName } ' command` : 'this simctl command' ) ,
76+ ) ;
7977 }
8078 return this . udid ;
8179 }
8280
8381 /**
8482 * @returns Promise resolving to the xcrun binary path
8583 */
86- async requireXcrun ( ) : Promise < string > {
84+ async requireXcrun ( ) : Promise < string > {
8785 const xcrunBinary = getXcrunBinary ( ) ;
8886
8987 if ( ! this . xcrun . path ) {
9088 try {
9189 this . xcrun . path = await which ( xcrunBinary ) ;
9290 } catch {
93- throw new Error ( `${ xcrunBinary } tool has not been found in PATH. ` +
94- `Are Xcode developers tools installed?` ) ;
91+ throw new Error (
92+ `${ xcrunBinary } tool has not been found in PATH. ` +
93+ `Are Xcode developers tools installed?` ,
94+ ) ;
9595 }
9696 }
9797 if ( ! this . xcrun . path ) {
@@ -110,10 +110,7 @@ export class Simctl {
110110 * `SubProcess` instance depending of `opts.asynchronous` value.
111111 * @throws {Error } If the simctl subcommand command returns non-zero return code.
112112 */
113- async exec < T extends ExecOpts > (
114- subcommand : string ,
115- opts ?: T
116- ) : Promise < ExecResult < T > > {
113+ async exec < T extends ExecOpts > ( subcommand : string , opts ?: T ) : Promise < ExecResult < T > > {
117114 const {
118115 args : initialArgs = [ ] ,
119116 env : initialEnv = { } ,
@@ -122,20 +119,21 @@ export class Simctl {
122119 logErrors = true ,
123120 architectures,
124121 timeout,
125- } = opts ?? { } as T ;
122+ } = opts ?? ( { } as T ) ;
126123 // run a particular simctl command
127124 const args = [
128125 'simctl' ,
129126 ...( this . devicesSetPath ? [ '--set' , this . devicesSetPath ] : [ ] ) ,
130127 subcommand ,
131- ...initialArgs
128+ ...initialArgs ,
132129 ] ;
133130 // Prefix all passed in environment variables with 'SIMCTL_CHILD_', simctl
134131 // will then pass these to the child (spawned) process.
135132 const env = _ . defaults (
136- _ . mapKeys ( initialEnv ,
137- ( value , key ) => _ . startsWith ( key , SIMCTL_ENV_PREFIX ) ? key : `${ SIMCTL_ENV_PREFIX } ${ key } ` ) ,
138- process . env
133+ _ . mapKeys ( initialEnv , ( value , key ) =>
134+ _ . startsWith ( key , SIMCTL_ENV_PREFIX ) ? key : `${ SIMCTL_ENV_PREFIX } ${ key } ` ,
135+ ) ,
136+ process . env ,
139137 ) ;
140138
141139 const execOpts : any = {
@@ -150,14 +148,19 @@ export class Simctl {
150148 let execArgs : [ string , string [ ] , any ] ;
151149 if ( architectures ?. length ) {
152150 const archArgs = _ . flatMap (
153- ( _ . isArray ( architectures ) ? architectures : [ architectures ] ) . map ( ( arch ) => [ '-arch' , arch ] )
151+ ( _ . isArray ( architectures ) ? architectures : [ architectures ] ) . map ( ( arch ) => [
152+ '-arch' ,
153+ arch ,
154+ ] ) ,
154155 ) ;
155156 execArgs = [ 'arch' , [ ...archArgs , xcrun , ...args ] , execOpts ] ;
156157 } else {
157158 execArgs = [ xcrun , args , execOpts ] ;
158159 }
159160 // We know what we are doing here - the type system can't handle the dynamic nature
160- return ( asynchronous ? new SubProcess ( ...execArgs ) : await tpExec ( ...execArgs ) ) as ExecResult < T > ;
161+ return (
162+ asynchronous ? new SubProcess ( ...execArgs ) : await tpExec ( ...execArgs )
163+ ) as ExecResult < T > ;
161164 } catch ( e : any ) {
162165 if ( ! this . logErrors || ! logErrors ) {
163166 // if we don't want to see the errors, just throw and allow the calling
@@ -218,4 +221,3 @@ export class Simctl {
218221}
219222
220223export default Simctl ;
221-
0 commit comments