node-simctl 8.0.9 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/index.d.ts +2 -1
  3. package/build/index.d.ts.map +1 -1
  4. package/build/index.js.map +1 -1
  5. package/build/lib/helpers.d.ts +17 -9
  6. package/build/lib/helpers.d.ts.map +1 -1
  7. package/build/lib/helpers.js +50 -4
  8. package/build/lib/helpers.js.map +1 -1
  9. package/build/lib/logger.d.ts +2 -3
  10. package/build/lib/logger.d.ts.map +1 -1
  11. package/build/lib/logger.js +3 -5
  12. package/build/lib/logger.js.map +1 -1
  13. package/build/lib/simctl.d.ts +82 -188
  14. package/build/lib/simctl.d.ts.map +1 -1
  15. package/build/lib/simctl.js +98 -150
  16. package/build/lib/simctl.js.map +1 -1
  17. package/build/lib/subcommands/addmedia.d.ts +14 -16
  18. package/build/lib/subcommands/addmedia.d.ts.map +1 -1
  19. package/build/lib/subcommands/addmedia.js +5 -7
  20. package/build/lib/subcommands/addmedia.js.map +1 -1
  21. package/build/lib/subcommands/appinfo.d.ts +13 -45
  22. package/build/lib/subcommands/appinfo.d.ts.map +1 -1
  23. package/build/lib/subcommands/appinfo.js +31 -42
  24. package/build/lib/subcommands/appinfo.js.map +1 -1
  25. package/build/lib/subcommands/boot.d.ts +9 -12
  26. package/build/lib/subcommands/boot.d.ts.map +1 -1
  27. package/build/lib/subcommands/boot.js +5 -40
  28. package/build/lib/subcommands/boot.js.map +1 -1
  29. package/build/lib/subcommands/bootstatus.d.ts +16 -56
  30. package/build/lib/subcommands/bootstatus.d.ts.map +1 -1
  31. package/build/lib/subcommands/bootstatus.js +8 -22
  32. package/build/lib/subcommands/bootstatus.js.map +1 -1
  33. package/build/lib/subcommands/create.d.ts +15 -34
  34. package/build/lib/subcommands/create.d.ts.map +1 -1
  35. package/build/lib/subcommands/create.js +23 -66
  36. package/build/lib/subcommands/create.js.map +1 -1
  37. package/build/lib/subcommands/delete.d.ts +9 -12
  38. package/build/lib/subcommands/delete.d.ts.map +1 -1
  39. package/build/lib/subcommands/delete.js +3 -5
  40. package/build/lib/subcommands/delete.js.map +1 -1
  41. package/build/lib/subcommands/erase.d.ts +12 -15
  42. package/build/lib/subcommands/erase.d.ts.map +1 -1
  43. package/build/lib/subcommands/erase.js +4 -6
  44. package/build/lib/subcommands/erase.js.map +1 -1
  45. package/build/lib/subcommands/get_app_container.d.ts +19 -22
  46. package/build/lib/subcommands/get_app_container.d.ts.map +1 -1
  47. package/build/lib/subcommands/get_app_container.js +6 -8
  48. package/build/lib/subcommands/get_app_container.js.map +1 -1
  49. package/build/lib/subcommands/getenv.d.ts +11 -14
  50. package/build/lib/subcommands/getenv.d.ts.map +1 -1
  51. package/build/lib/subcommands/getenv.js +5 -7
  52. package/build/lib/subcommands/getenv.js.map +1 -1
  53. package/build/lib/subcommands/install.d.ts +12 -15
  54. package/build/lib/subcommands/install.d.ts.map +1 -1
  55. package/build/lib/subcommands/install.js +4 -6
  56. package/build/lib/subcommands/install.js.map +1 -1
  57. package/build/lib/subcommands/io.d.ts +12 -15
  58. package/build/lib/subcommands/io.d.ts.map +1 -1
  59. package/build/lib/subcommands/io.js +4 -6
  60. package/build/lib/subcommands/io.js.map +1 -1
  61. package/build/lib/subcommands/keychain.d.ts +37 -55
  62. package/build/lib/subcommands/keychain.d.ts.map +1 -1
  63. package/build/lib/subcommands/keychain.js +16 -25
  64. package/build/lib/subcommands/keychain.js.map +1 -1
  65. package/build/lib/subcommands/launch.d.ts +16 -19
  66. package/build/lib/subcommands/launch.d.ts.map +1 -1
  67. package/build/lib/subcommands/launch.js +9 -11
  68. package/build/lib/subcommands/launch.js.map +1 -1
  69. package/build/lib/subcommands/list.d.ts +94 -125
  70. package/build/lib/subcommands/list.d.ts.map +1 -1
  71. package/build/lib/subcommands/list.js +34 -92
  72. package/build/lib/subcommands/list.js.map +1 -1
  73. package/build/lib/subcommands/location.d.ts +18 -22
  74. package/build/lib/subcommands/location.d.ts.map +1 -1
  75. package/build/lib/subcommands/location.js +11 -13
  76. package/build/lib/subcommands/location.js.map +1 -1
  77. package/build/lib/subcommands/openurl.d.ts +15 -17
  78. package/build/lib/subcommands/openurl.d.ts.map +1 -1
  79. package/build/lib/subcommands/openurl.js +5 -7
  80. package/build/lib/subcommands/openurl.js.map +1 -1
  81. package/build/lib/subcommands/pbcopy.d.ts +14 -17
  82. package/build/lib/subcommands/pbcopy.d.ts.map +1 -1
  83. package/build/lib/subcommands/pbcopy.js +5 -7
  84. package/build/lib/subcommands/pbcopy.js.map +1 -1
  85. package/build/lib/subcommands/pbpaste.d.ts +14 -17
  86. package/build/lib/subcommands/pbpaste.d.ts.map +1 -1
  87. package/build/lib/subcommands/pbpaste.js +5 -7
  88. package/build/lib/subcommands/pbpaste.js.map +1 -1
  89. package/build/lib/subcommands/privacy.d.ts +52 -57
  90. package/build/lib/subcommands/privacy.d.ts.map +1 -1
  91. package/build/lib/subcommands/privacy.js +15 -17
  92. package/build/lib/subcommands/privacy.js.map +1 -1
  93. package/build/lib/subcommands/push.d.ts +22 -25
  94. package/build/lib/subcommands/push.d.ts.map +1 -1
  95. package/build/lib/subcommands/push.js +5 -7
  96. package/build/lib/subcommands/push.js.map +1 -1
  97. package/build/lib/subcommands/shutdown.d.ts +9 -12
  98. package/build/lib/subcommands/shutdown.d.ts.map +1 -1
  99. package/build/lib/subcommands/shutdown.js +5 -40
  100. package/build/lib/subcommands/shutdown.js.map +1 -1
  101. package/build/lib/subcommands/spawn.d.ts +24 -27
  102. package/build/lib/subcommands/spawn.d.ts.map +1 -1
  103. package/build/lib/subcommands/spawn.js +12 -14
  104. package/build/lib/subcommands/spawn.js.map +1 -1
  105. package/build/lib/subcommands/terminate.d.ts +12 -15
  106. package/build/lib/subcommands/terminate.d.ts.map +1 -1
  107. package/build/lib/subcommands/terminate.js +4 -6
  108. package/build/lib/subcommands/terminate.js.map +1 -1
  109. package/build/lib/subcommands/ui.d.ts +97 -105
  110. package/build/lib/subcommands/ui.d.ts.map +1 -1
  111. package/build/lib/subcommands/ui.js +24 -26
  112. package/build/lib/subcommands/ui.js.map +1 -1
  113. package/build/lib/subcommands/uninstall.d.ts +13 -16
  114. package/build/lib/subcommands/uninstall.d.ts.map +1 -1
  115. package/build/lib/subcommands/uninstall.js +4 -6
  116. package/build/lib/subcommands/uninstall.js.map +1 -1
  117. package/build/lib/types.d.ts +231 -0
  118. package/build/lib/types.d.ts.map +1 -0
  119. package/build/lib/types.js +3 -0
  120. package/build/lib/types.js.map +1 -0
  121. package/index.ts +13 -0
  122. package/lib/helpers.ts +81 -0
  123. package/lib/{logger.js → logger.ts} +2 -5
  124. package/lib/simctl.ts +221 -0
  125. package/lib/subcommands/{addmedia.js → addmedia.ts} +6 -8
  126. package/lib/subcommands/appinfo.ts +39 -0
  127. package/lib/subcommands/{boot.js → boot.ts} +5 -10
  128. package/lib/subcommands/bootstatus.ts +108 -0
  129. package/lib/subcommands/{create.js → create.ts} +29 -35
  130. package/lib/subcommands/{delete.js → delete.ts} +3 -5
  131. package/lib/subcommands/{erase.js → erase.ts} +4 -7
  132. package/lib/subcommands/{get_app_container.js → get_app_container.ts} +10 -8
  133. package/lib/subcommands/{getenv.js → getenv.ts} +5 -7
  134. package/lib/subcommands/{install.js → install.ts} +4 -6
  135. package/lib/subcommands/{io.js → io.ts} +4 -7
  136. package/lib/subcommands/{keychain.js → keychain.ts} +30 -32
  137. package/lib/subcommands/{launch.js → launch.ts} +9 -12
  138. package/lib/subcommands/{list.js → list.ts} +67 -60
  139. package/lib/subcommands/{location.js → location.ts} +15 -14
  140. package/lib/subcommands/{openurl.js → openurl.ts} +6 -7
  141. package/lib/subcommands/{pbcopy.js → pbcopy.ts} +11 -8
  142. package/lib/subcommands/{pbpaste.js → pbpaste.ts} +5 -7
  143. package/lib/subcommands/{privacy.js → privacy.ts} +13 -17
  144. package/lib/subcommands/{push.js → push.ts} +5 -8
  145. package/lib/subcommands/{shutdown.js → shutdown.ts} +5 -8
  146. package/lib/subcommands/{spawn.js → spawn.ts} +21 -17
  147. package/lib/subcommands/{terminate.js → terminate.ts} +4 -6
  148. package/lib/subcommands/{ui.js → ui.ts} +19 -28
  149. package/lib/subcommands/{uninstall.js → uninstall.ts} +4 -6
  150. package/lib/types.ts +243 -0
  151. package/package.json +2 -2
  152. package/index.js +0 -4
  153. package/lib/helpers.js +0 -37
  154. package/lib/simctl.js +0 -299
  155. package/lib/subcommands/appinfo.js +0 -51
  156. package/lib/subcommands/bootstatus.js +0 -119
@@ -1,13 +1,12 @@
1
- const commands = {};
1
+ import type { Simctl } from '../simctl';
2
2
 
3
3
  /**
4
4
  * Grants the given permission on the app with the given bundle identifier
5
5
  *
6
6
  * @since Xcode 11.4 SDK
7
- * @this {import('../simctl').Simctl}
8
- * @param {string} bundleId the identifier of the application whose
7
+ * @param bundleId the identifier of the application whose
9
8
  * privacy settings are going to be changed
10
- * @param {string} perm one of possible permission values:
9
+ * @param perm one of possible permission values:
11
10
  * - all: Apply the action to all services.
12
11
  * - calendar: Allow access to calendar.
13
12
  * - contacts-limited: Allow access to basic contact info.
@@ -25,48 +24,45 @@ const commands = {};
25
24
  * or there was an error while granting the permission
26
25
  * @throws {Error} If the `udid` instance property is unset
27
26
  */
28
- commands.grantPermission = async function grantPermission (bundleId, perm) {
27
+ export async function grantPermission (this: Simctl, bundleId: string, perm: string): Promise<void> {
29
28
  await this.exec('privacy', {
30
29
  args: [this.requireUdid('privacy grant'), 'grant', perm, bundleId],
31
30
  });
32
- };
31
+ }
33
32
 
34
33
  /**
35
34
  * Revokes the given permission on the app with the given bundle identifier
36
35
  * after it has been granted
37
36
  *
38
37
  * @since Xcode 11.4 SDK
39
- * @this {import('../simctl').Simctl}
40
- * @param {string} bundleId the identifier of the application whose
38
+ * @param bundleId the identifier of the application whose
41
39
  * privacy settings are going to be changed
42
- * @param {string} perm one of possible permission values (see `grantPermission`)
40
+ * @param perm one of possible permission values (see `grantPermission`)
43
41
  * @throws {Error} if the current SDK version does not support the command
44
42
  * or there was an error while revoking the permission
45
43
  * @throws {Error} If the `udid` instance property is unset
46
44
  */
47
- commands.revokePermission = async function revokePermission (bundleId, perm) {
45
+ export async function revokePermission (this: Simctl, bundleId: string, perm: string): Promise<void> {
48
46
  await this.exec('privacy', {
49
47
  args: [this.requireUdid('privacy revoke'), 'revoke', perm, bundleId],
50
48
  });
51
- };
49
+ }
52
50
 
53
51
  /**
54
52
  * Resets the given permission on the app with the given bundle identifier
55
53
  * to its default state
56
54
  *
57
55
  * @since Xcode 11.4 SDK
58
- * @this {import('../simctl').Simctl}
59
- * @param {string} bundleId the identifier of the application whose
56
+ * @param bundleId the identifier of the application whose
60
57
  * privacy settings are going to be changed
61
- * @param {string} perm one of possible permission values (see `grantPermission`)
58
+ * @param perm one of possible permission values (see `grantPermission`)
62
59
  * @throws {Error} if the current SDK version does not support the command
63
60
  * or there was an error while resetting the permission
64
61
  * @throws {Error} If the `udid` instance property is unset
65
62
  */
66
- commands.resetPermission = async function resetPermission (bundleId, perm) {
63
+ export async function resetPermission (this: Simctl, bundleId: string, perm: string): Promise<void> {
67
64
  await this.exec('privacy', {
68
65
  args: [this.requireUdid('private reset'), 'reset', perm, bundleId],
69
66
  });
70
- };
67
+ }
71
68
 
72
- export default commands;
@@ -3,17 +3,15 @@ import { uuidV4 } from '../helpers';
3
3
  import path from 'path';
4
4
  import os from 'os';
5
5
  import fs from 'fs/promises';
6
-
7
- const commands = {};
6
+ import type { Simctl } from '../simctl';
8
7
 
9
8
  /**
10
9
  * Send a simulated push notification
11
10
  *
12
11
  * @since Xcode 11.4 SDK
13
- * @this {import('../simctl').Simctl}
14
- * @param {Object} payload - The object that describes Apple push notification content.
12
+ * @param payload The object that describes Apple push notification content.
15
13
  * It must contain a top-level "Simulator Target Bundle" key with a string value matching
16
- * the target applications bundle identifier and "aps" key with valid Apple Push Notification values.
14
+ * the target application's bundle identifier and "aps" key with valid Apple Push Notification values.
17
15
  * For example:
18
16
  * {
19
17
  * "Simulator Target Bundle": "com.apple.Preferences",
@@ -27,7 +25,7 @@ const commands = {};
27
25
  * or there was an error while pushing the notification
28
26
  * @throws {Error} If the `udid` instance property is unset
29
27
  */
30
- commands.pushNotification = async function pushNotification (payload) {
28
+ export async function pushNotification (this: Simctl, payload: Record<string, any>): Promise<void> {
31
29
  const dstPath = path.resolve(os.tmpdir(), `${await uuidV4()}.json`);
32
30
  try {
33
31
  await fs.writeFile(dstPath, JSON.stringify(payload), 'utf8');
@@ -37,6 +35,5 @@ commands.pushNotification = async function pushNotification (payload) {
37
35
  } finally {
38
36
  await rimraf(dstPath);
39
37
  }
40
- };
38
+ }
41
39
 
42
- export default commands;
@@ -1,27 +1,24 @@
1
1
  import _ from 'lodash';
2
- import log, { LOG_PREFIX } from '../logger';
3
-
4
- const commands = {};
2
+ import { log, LOG_PREFIX } from '../logger';
3
+ import type { Simctl } from '../simctl';
5
4
 
6
5
  /**
7
6
  * Shutdown the given Simulator if it is running.
8
7
  *
9
- * @this {import('../simctl').Simctl}
10
8
  * @throws {Error} If the corresponding simctl subcommand command
11
9
  * returns non-zero return code.
12
10
  * @throws {Error} If the `udid` instance property is unset
13
11
  */
14
- commands.shutdownDevice = async function shutdownDevice () {
12
+ export async function shutdownDevice (this: Simctl): Promise<void> {
15
13
  try {
16
14
  await this.exec('shutdown', {
17
15
  args: [this.requireUdid('shutdown')],
18
16
  });
19
- } catch (e) {
17
+ } catch (e: any) {
20
18
  if (!_.includes(e.message, 'current state: Shutdown')) {
21
19
  throw e;
22
20
  }
23
21
  log.debug(LOG_PREFIX, `Simulator already in 'Shutdown' state. Continuing`);
24
22
  }
25
- };
23
+ }
26
24
 
27
- export default commands;
@@ -1,21 +1,23 @@
1
1
  import _ from 'lodash';
2
-
3
-
4
- const commands = {};
2
+ import type { Simctl } from '../simctl';
3
+ import type { TeenProcessExecResult, SubProcess } from 'teen_process';
5
4
 
6
5
  /**
7
6
  * Spawn the particular process on Simulator.
8
7
  * It is required that Simulator is in _booted_ state.
9
8
  *
10
- * @this {import('../simctl').Simctl}
11
- * @param {string|string[]} args - Spawn arguments
12
- * @param {object} [env={}] - Additional environment variables mapping.
13
- * @return {Promise<import('teen_process').TeenProcessExecResult>} Command execution result.
9
+ * @param args - Spawn arguments
10
+ * @param env - Additional environment variables mapping.
11
+ * @return Command execution result.
14
12
  * @throws {Error} If the corresponding simctl subcommand command
15
13
  * returns non-zero return code.
16
14
  * @throws {Error} If the `udid` instance property is unset
17
15
  */
18
- commands.spawnProcess = async function spawnProcess (args, env = {}) {
16
+ export async function spawnProcess (
17
+ this: Simctl,
18
+ args: string | string[],
19
+ env: Record<string, any> = {}
20
+ ): Promise<TeenProcessExecResult<string>> {
19
21
  if (_.isEmpty(args)) {
20
22
  throw new Error('Spawn arguments are required');
21
23
  }
@@ -24,19 +26,22 @@ commands.spawnProcess = async function spawnProcess (args, env = {}) {
24
26
  args: [this.requireUdid('spawn'), ...(_.isArray(args) ? args : [args])],
25
27
  env,
26
28
  });
27
- };
29
+ }
28
30
 
29
31
  /**
30
32
  * Prepare SubProcess instance for a new process, which is going to be spawned
31
33
  * on Simulator.
32
34
  *
33
- * @this {import('../simctl').Simctl}
34
- * @param {string|string[]} args - Spawn arguments
35
- * @param {object} [env={}] - Additional environment variables mapping.
36
- * @return {Promise<import('teen_process').SubProcess>} The instance of the process to be spawned.
35
+ * @param args - Spawn arguments
36
+ * @param env - Additional environment variables mapping.
37
+ * @return The instance of the process to be spawned.
37
38
  * @throws {Error} If the `udid` instance property is unset
38
39
  */
39
- commands.spawnSubProcess = async function spawnSubProcess (args, env = {}) {
40
+ export async function spawnSubProcess (
41
+ this: Simctl,
42
+ args: string | string[],
43
+ env: Record<string, any> = {}
44
+ ): Promise<SubProcess> {
40
45
  if (_.isEmpty(args)) {
41
46
  throw new Error('Spawn arguments are required');
42
47
  }
@@ -45,7 +50,6 @@ commands.spawnSubProcess = async function spawnSubProcess (args, env = {}) {
45
50
  args: [this.requireUdid('spawn'), ...(_.isArray(args) ? args : [args])],
46
51
  env,
47
52
  asynchronous: true,
48
- });
49
- };
53
+ }) as SubProcess;
54
+ }
50
55
 
51
- export default commands;
@@ -1,20 +1,18 @@
1
- const commands = {};
1
+ import type { Simctl } from '../simctl';
2
2
 
3
3
  /**
4
4
  * Terminate the given running application on Simulator.
5
5
  * It is required that Simulator is in _booted_ state.
6
6
  *
7
- * @this {import('../simctl').Simctl}
8
- * @param {string} bundleId - Bundle identifier of the application,
7
+ * @param bundleId - Bundle identifier of the application,
9
8
  * which is going to be terminated.
10
9
  * @throws {Error} If the corresponding simctl subcommand command
11
10
  * returns non-zero return code.
12
11
  * @throws {Error} If the `udid` instance property is unset
13
12
  */
14
- commands.terminateApp = async function terminateApp (bundleId) {
13
+ export async function terminateApp (this: Simctl, bundleId: string): Promise<void> {
15
14
  await this.exec('terminate', {
16
15
  args: [this.requireUdid('terminate'), bundleId],
17
16
  });
18
- };
17
+ }
19
18
 
20
- export default commands;
@@ -1,40 +1,36 @@
1
1
  import _ from 'lodash';
2
-
3
-
4
- const commands = {};
2
+ import type { Simctl } from '../simctl';
5
3
 
6
4
  /**
7
5
  * Retrieves the current UI appearance value from the given simulator
8
6
  *
9
7
  * @since Xcode 11.4 SDK
10
- * @this {import('../simctl').Simctl}
11
- * @return {Promise<string>} the appearance value, for example 'light' or 'dark'
8
+ * @return the appearance value, for example 'light' or 'dark'
12
9
  * @throws {Error} if the current SDK version does not support the command
13
10
  * or there was an error while getting the value
14
11
  * @throws {Error} If the `udid` instance property is unset
15
12
  */
16
- commands.getAppearance = async function getAppearance () {
13
+ export async function getAppearance (this: Simctl): Promise<string> {
17
14
  const {stdout} = await this.exec('ui', {
18
15
  args: [this.requireUdid('ui'), 'appearance'],
19
16
  });
20
17
  return _.trim(stdout);
21
- };
18
+ }
22
19
 
23
20
  /**
24
21
  * Sets the UI appearance to the given style
25
22
  *
26
23
  * @since Xcode 11.4 SDK
27
- * @this {import('../simctl').Simctl}
28
- * @param {string} appearance valid appearance value, for example 'light' or 'dark'
24
+ * @param appearance valid appearance value, for example 'light' or 'dark'
29
25
  * @throws {Error} if the current SDK version does not support the command
30
26
  * or there was an error while getting the value
31
27
  * @throws {Error} If the `udid` instance property is unset
32
28
  */
33
- commands.setAppearance = async function setAppearance (appearance) {
29
+ export async function setAppearance (this: Simctl, appearance: string): Promise<void> {
34
30
  await this.exec('ui', {
35
31
  args: [this.requireUdid('ui'), 'appearance', appearance],
36
32
  });
37
- };
33
+ }
38
34
 
39
35
  /**
40
36
  * Retrieves the current increase contrast configuration value from the given simulator.
@@ -45,20 +41,19 @@ commands.setAppearance = async function setAppearance (appearance) {
45
41
  * - unknown: The current setting is unknown or there was an error detecting it.
46
42
  *
47
43
  * @since Xcode 15 (but lower xcode could have this command)
48
- * @this {import('../simctl').Simctl}
49
- * @return {Promise<string>} the contrast configuration value.
44
+ * @return the contrast configuration value.
50
45
  * Possible return value is 'enabled', 'disabled',
51
46
  * 'unsupported' or 'unknown' with Xcode 16.2.
52
47
  * @throws {Error} if the current SDK version does not support the command
53
48
  * or there was an error while getting the value.
54
49
  * @throws {Error} If the `udid` instance property is unset
55
50
  */
56
- commands.getIncreaseContrast = async function getIncreaseContrast () {
51
+ export async function getIncreaseContrast (this: Simctl): Promise<string> {
57
52
  const {stdout} = await this.exec('ui', {
58
53
  args: [this.requireUdid('ui'), 'increase_contrast'],
59
54
  });
60
55
  return _.trim(stdout);
61
- };
56
+ }
62
57
 
63
58
  /**
64
59
  * Sets the increase constrast configuration for the given simulator.
@@ -67,18 +62,17 @@ commands.getIncreaseContrast = async function getIncreaseContrast () {
67
62
  * in the caller side.
68
63
  *
69
64
  * @since Xcode 15 (but lower xcode could have this command)
70
- * @this {import('../simctl').Simctl}
71
- * @param {string} increaseContrast valid increase constrast configuration value.
65
+ * @param increaseContrast valid increase constrast configuration value.
72
66
  * Acceptable value is 'enabled' or 'disabled' with Xcode 16.2.
73
67
  * @throws {Error} if the current SDK version does not support the command
74
68
  * or the given value was invalid for the command.
75
69
  * @throws {Error} If the `udid` instance property is unset
76
70
  */
77
- commands.setIncreaseContrast = async function setIncreaseContrast (increaseContrast) {
71
+ export async function setIncreaseContrast (this: Simctl, increaseContrast: string): Promise<void> {
78
72
  await this.exec('ui', {
79
73
  args: [this.requireUdid('ui'), 'increase_contrast', increaseContrast],
80
74
  });
81
- };
75
+ }
82
76
 
83
77
  /**
84
78
  * Retrieves the current content size value from the given simulator.
@@ -91,8 +85,7 @@ commands.setIncreaseContrast = async function setIncreaseContrast (increaseContr
91
85
  * Other values: unknown, unsupported.
92
86
  *
93
87
  * @since Xcode 15 (but lower xcode could have this command)
94
- * @this {import('../simctl').Simctl}
95
- * @return {Promise<string>} the content size value. Possible return value is
88
+ * @return the content size value. Possible return value is
96
89
  * extra-small, small, medium, large, extra-large, extra-extra-large,
97
90
  * extra-extra-extra-large, accessibility-medium, accessibility-large,
98
91
  * accessibility-extra-large, accessibility-extra-extra-large,
@@ -102,12 +95,12 @@ commands.setIncreaseContrast = async function setIncreaseContrast (increaseContr
102
95
  * or there was an error while getting the value.
103
96
  * @throws {Error} If the `udid` instance property is unset
104
97
  */
105
- commands.getContentSize = async function getContentSize () {
98
+ export async function getContentSize (this: Simctl): Promise<string> {
106
99
  const {stdout} = await this.exec('ui', {
107
100
  args: [this.requireUdid('ui'), 'content_size'],
108
101
  });
109
102
  return _.trim(stdout);
110
- };
103
+ }
111
104
 
112
105
  /**
113
106
  * Sets content size for the given simulator.
@@ -122,8 +115,7 @@ commands.getContentSize = async function getContentSize () {
122
115
  * in the caller side.
123
116
  *
124
117
  * @since Xcode 15 (but lower xcode could have this command)
125
- * @this {import('../simctl').Simctl}
126
- * @param {string} contentSizeAction valid content size or action value. Acceptable value is
118
+ * @param contentSizeAction valid content size or action value. Acceptable value is
127
119
  * extra-small, small, medium, large, extra-large, extra-extra-large,
128
120
  * extra-extra-extra-large, accessibility-medium, accessibility-large,
129
121
  * accessibility-extra-large, accessibility-extra-extra-large,
@@ -132,10 +124,9 @@ commands.getContentSize = async function getContentSize () {
132
124
  * or the given value was invalid for the command.
133
125
  * @throws {Error} If the `udid` instance property is unset
134
126
  */
135
- commands.setContentSize = async function setContentSize (contentSizeAction) {
127
+ export async function setContentSize (this: Simctl, contentSizeAction: string): Promise<void> {
136
128
  await this.exec('ui', {
137
129
  args: [this.requireUdid('ui'), 'content_size', contentSizeAction],
138
130
  });
139
- };
131
+ }
140
132
 
141
- export default commands;
@@ -1,21 +1,19 @@
1
- const commands = {};
1
+ import type { Simctl } from '../simctl';
2
2
 
3
3
  /**
4
4
  * Remove the particular application package from Simulator.
5
5
  * It is required that Simulator is in _booted_ state and
6
6
  * the application with given bundle identifier is already installed.
7
7
  *
8
- * @this {import('../simctl').Simctl}
9
- * @param {string} bundleId - Bundle identifier of the application,
8
+ * @param bundleId - Bundle identifier of the application,
10
9
  * which is going to be removed.
11
10
  * @throws {Error} If the corresponding simctl subcommand command
12
11
  * returns non-zero return code.
13
12
  * @throws {Error} If the `udid` instance property is unset
14
13
  */
15
- commands.removeApp = async function removeApp (bundleId) {
14
+ export async function removeApp (this: Simctl, bundleId: string): Promise<void> {
16
15
  await this.exec('uninstall', {
17
16
  args: [this.requireUdid('uninstall'), bundleId],
18
17
  });
19
- };
18
+ }
20
19
 
21
- export default commands;
package/lib/types.ts ADDED
@@ -0,0 +1,243 @@
1
+ import type { SubProcess, TeenProcessExecResult } from 'teen_process';
2
+
3
+ /**
4
+ * XCRun configuration
5
+ */
6
+ export interface XCRun {
7
+ /**
8
+ * Full path to the xcrun script
9
+ */
10
+ path: string | null;
11
+ }
12
+
13
+ /**
14
+ * Options for asynchronous execution
15
+ */
16
+ export interface AsyncExecOpts {
17
+ asynchronous: true;
18
+ }
19
+
20
+ /**
21
+ * Execution options for simctl commands
22
+ */
23
+ export interface ExecOpts {
24
+ /**
25
+ * The list of additional subcommand arguments.
26
+ * It's empty by default.
27
+ */
28
+ args?: string[];
29
+ /**
30
+ * Environment variables mapping. All these variables
31
+ * will be passed Simulator and used in the executing function.
32
+ */
33
+ env?: Record<string, any>;
34
+ /**
35
+ * Set it to _false_ to throw execution errors
36
+ * immediately without logging any additional information.
37
+ */
38
+ logErrors?: boolean;
39
+ /**
40
+ * Whether to execute the given command
41
+ * 'synchronously' or 'asynchronously'. Affects the returned result of the function.
42
+ */
43
+ asynchronous?: boolean;
44
+ /**
45
+ * Explicitly sets streams encoding for the executed
46
+ * command input and outputs.
47
+ */
48
+ encoding?: string;
49
+ /**
50
+ * One or more architecture names to be enforced while
51
+ * executing xcrun. See https://github.com/appium/appium/issues/18966 for more details.
52
+ */
53
+ architectures?: string | string[];
54
+ /**
55
+ * The maximum number of milliseconds
56
+ * to wait for single synchronous xcrun command. If not provided explicitly, then
57
+ * the value of execTimeout property is used by default.
58
+ */
59
+ timeout?: number;
60
+ }
61
+
62
+ /**
63
+ * Simctl instance options
64
+ */
65
+ export interface SimctlOpts {
66
+ /**
67
+ * The xcrun properties. Currently only one property
68
+ * is supported, which is `path` and it by default contains `null`, which enforces
69
+ * the instance to automatically detect the full path to `xcrun` tool and to throw
70
+ * an exception if it cannot be detected. If the path is set upon instance creation
71
+ * then it is going to be used by `exec` and no autodetection will happen.
72
+ */
73
+ xcrun?: XCRun;
74
+ /**
75
+ * The default maximum number of milliseconds
76
+ * to wait for single synchronous xcrun command.
77
+ */
78
+ execTimeout?: number;
79
+ /**
80
+ * Whether to wire xcrun error messages
81
+ * into debug log before throwing them.
82
+ */
83
+ logErrors?: boolean;
84
+ /**
85
+ * The unique identifier of the current device, which is
86
+ * going to be implicitly passed to all methods, which require it. It can either be set
87
+ * upon instance creation if it is already known in advance or later when/if needed via the
88
+ * corresponding instance setter.
89
+ */
90
+ udid?: string | null;
91
+ /**
92
+ * Full path to the set of devices that you want to manage.
93
+ * By default this path usually equals to ~/Library/Developer/CoreSimulator/Devices
94
+ */
95
+ devicesSetPath?: string | null;
96
+ }
97
+
98
+ /**
99
+ * Device information
100
+ */
101
+ export interface DeviceInfo {
102
+ /**
103
+ * The device name.
104
+ */
105
+ name: string;
106
+ /**
107
+ * The device UDID.
108
+ */
109
+ udid: string;
110
+ /**
111
+ * The current Simulator state, for example 'booted' or 'shutdown'.
112
+ */
113
+ state: string;
114
+ /**
115
+ * The SDK version, for example '10.3'.
116
+ */
117
+ sdk: string;
118
+ /**
119
+ * The platform name, for example 'iOS'.
120
+ */
121
+ platform: string;
122
+ }
123
+
124
+ /**
125
+ * Simulator creation options
126
+ */
127
+ export interface SimCreationOpts {
128
+ /**
129
+ * Platform name in order to specify runtime such as 'iOS', 'tvOS', 'watchOS'
130
+ */
131
+ platform?: string;
132
+ /**
133
+ * The maximum number of milliseconds to wait
134
+ * unit device creation is completed.
135
+ */
136
+ timeout?: number;
137
+ }
138
+
139
+ /**
140
+ * Result type for exec method - either SubProcess for async or TeenProcessExecResult for sync
141
+ */
142
+ export type ExecResult<T extends ExecOpts> = T extends AsyncExecOpts
143
+ ? SubProcess
144
+ : TeenProcessExecResult<string>;
145
+
146
+ /**
147
+ * Boot monitor options
148
+ */
149
+ export interface BootMonitorOptions {
150
+ /**
151
+ * Simulator booting timeout in ms.
152
+ */
153
+ timeout?: number;
154
+ /**
155
+ * This event is fired when data migration stage starts.
156
+ */
157
+ onWaitingDataMigration?: () => void;
158
+ /**
159
+ * This event is fired when system app wait stage starts.
160
+ */
161
+ onWaitingSystemApp?: () => void;
162
+ /**
163
+ * This event is fired when Simulator is fully booted.
164
+ */
165
+ onFinished?: () => void;
166
+ /**
167
+ * This event is fired when there was an error while monitoring the booting process
168
+ * or when the timeout has expired.
169
+ */
170
+ onError?: (error: Error) => void;
171
+ /**
172
+ * Whether to preboot the Simulator
173
+ * if this command is called and it is not already in booted or booting state.
174
+ */
175
+ shouldPreboot?: boolean;
176
+ }
177
+
178
+ /**
179
+ * Certificate options
180
+ */
181
+ export interface CertOptions {
182
+ /**
183
+ * whether the `cert` argument
184
+ * is the path to the certificate on the local file system or
185
+ * a raw certificate content
186
+ */
187
+ raw?: boolean;
188
+ }
189
+
190
+ /**
191
+ * App information returned by simctl appinfo when the app is found
192
+ */
193
+ export interface AppInfo {
194
+ /**
195
+ * Application type (e.g., "Hidden")
196
+ */
197
+ ApplicationType: string;
198
+ /**
199
+ * Bundle URL (file:// URL)
200
+ */
201
+ Bundle?: string;
202
+ /**
203
+ * Bundle container URL (file:// URL)
204
+ */
205
+ BundleContainer?: string;
206
+ /**
207
+ * Display name of the application
208
+ */
209
+ CFBundleDisplayName: string;
210
+ /**
211
+ * Executable name
212
+ */
213
+ CFBundleExecutable: string;
214
+ /**
215
+ * Bundle identifier
216
+ */
217
+ CFBundleIdentifier: string;
218
+ /**
219
+ * Bundle name
220
+ */
221
+ CFBundleName: string;
222
+ /**
223
+ * Bundle version
224
+ */
225
+ CFBundleVersion: string | number;
226
+ /**
227
+ * Data container URL (file:// URL)
228
+ */
229
+ DataContainer?: string;
230
+ /**
231
+ * Group containers dictionary
232
+ */
233
+ GroupContainers?: Record<string, any>;
234
+ /**
235
+ * Path to the app bundle
236
+ */
237
+ Path: string;
238
+ /**
239
+ * SpringBoard app tags
240
+ */
241
+ SBAppTags?: string[];
242
+ }
243
+
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "ios",
7
7
  "simctl"
8
8
  ],
9
- "version": "8.0.9",
9
+ "version": "8.1.0",
10
10
  "author": "Appium Contributors",
11
11
  "license": "Apache-2.0",
12
12
  "repository": {
@@ -26,7 +26,7 @@
26
26
  "lib": "./lib"
27
27
  },
28
28
  "files": [
29
- "index.js",
29
+ "index.ts",
30
30
  "lib",
31
31
  "build/index.*",
32
32
  "build/lib",
package/index.js DELETED
@@ -1,4 +0,0 @@
1
- import { Simctl } from './lib/simctl';
2
-
3
- export { Simctl };
4
- export default Simctl;