@akylas/nativescript-cli 8.8.2 → 8.8.3

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 (275) hide show
  1. package/lib/android-tools-info.js +9 -20
  2. package/lib/base-package-manager.js +47 -64
  3. package/lib/bun-package-manager.js +65 -88
  4. package/lib/color.js +2 -2
  5. package/lib/commands/add-platform.js +14 -30
  6. package/lib/commands/apple-login.js +18 -29
  7. package/lib/commands/appstore-list.js +34 -45
  8. package/lib/commands/appstore-upload.js +55 -68
  9. package/lib/commands/build.js +57 -86
  10. package/lib/commands/clean.js +161 -176
  11. package/lib/commands/command-base.js +14 -27
  12. package/lib/commands/config.js +51 -70
  13. package/lib/commands/create-project.js +210 -229
  14. package/lib/commands/debug.js +66 -88
  15. package/lib/commands/deploy.js +28 -44
  16. package/lib/commands/embedding/embed.js +33 -52
  17. package/lib/commands/extensibility/install-extension.js +5 -16
  18. package/lib/commands/extensibility/list-extensions.js +13 -24
  19. package/lib/commands/extensibility/uninstall-extension.js +4 -15
  20. package/lib/commands/fonts.js +30 -41
  21. package/lib/commands/generate-assets.js +13 -28
  22. package/lib/commands/generate-help.js +2 -13
  23. package/lib/commands/generate.js +17 -26
  24. package/lib/commands/info.js +2 -13
  25. package/lib/commands/install.js +34 -49
  26. package/lib/commands/list-platforms.js +14 -25
  27. package/lib/commands/migrate.js +15 -26
  28. package/lib/commands/native-add.js +23 -46
  29. package/lib/commands/platform-clean.js +19 -32
  30. package/lib/commands/plugin/add-plugin.js +12 -25
  31. package/lib/commands/plugin/build-plugin.js +34 -39
  32. package/lib/commands/plugin/create-plugin.js +110 -133
  33. package/lib/commands/plugin/list-plugins.js +22 -33
  34. package/lib/commands/plugin/remove-plugin.js +20 -33
  35. package/lib/commands/plugin/update-plugin.js +20 -33
  36. package/lib/commands/post-install.js +20 -33
  37. package/lib/commands/prepare.js +19 -35
  38. package/lib/commands/preview.js +49 -62
  39. package/lib/commands/remove-platform.js +7 -18
  40. package/lib/commands/resources/resources-update.js +13 -26
  41. package/lib/commands/run.js +55 -76
  42. package/lib/commands/start.js +6 -19
  43. package/lib/commands/test-init.js +123 -134
  44. package/lib/commands/test.js +66 -89
  45. package/lib/commands/typings.js +126 -142
  46. package/lib/commands/update-platform.js +22 -35
  47. package/lib/commands/update.js +30 -43
  48. package/lib/common/child-process.js +53 -72
  49. package/lib/common/codeGeneration/code-entity.js +1 -1
  50. package/lib/common/codeGeneration/code-printer.js +1 -1
  51. package/lib/common/command-params.js +7 -18
  52. package/lib/common/commands/analytics.js +27 -40
  53. package/lib/common/commands/autocompletion.js +39 -56
  54. package/lib/common/commands/device/device-log-stream.js +12 -23
  55. package/lib/common/commands/device/get-file.js +22 -33
  56. package/lib/common/commands/device/list-applications.js +12 -23
  57. package/lib/common/commands/device/list-devices.js +72 -87
  58. package/lib/common/commands/device/list-files.js +23 -34
  59. package/lib/common/commands/device/put-file.js +22 -33
  60. package/lib/common/commands/device/run-application.js +12 -25
  61. package/lib/common/commands/device/stop-application.js +11 -22
  62. package/lib/common/commands/device/uninstall-application.js +6 -17
  63. package/lib/common/commands/generate-messages.js +17 -28
  64. package/lib/common/commands/help.js +20 -33
  65. package/lib/common/commands/package-manager-get.js +6 -17
  66. package/lib/common/commands/package-manager-set.js +9 -20
  67. package/lib/common/commands/post-install.js +2 -13
  68. package/lib/common/commands/preuninstall.js +23 -38
  69. package/lib/common/commands/proxy/proxy-base.js +8 -19
  70. package/lib/common/commands/proxy/proxy-clear.js +4 -15
  71. package/lib/common/commands/proxy/proxy-get.js +3 -14
  72. package/lib/common/commands/proxy/proxy-set.js +87 -100
  73. package/lib/common/constants.js +11 -11
  74. package/lib/common/decorators.js +10 -22
  75. package/lib/common/dispatchers.js +79 -96
  76. package/lib/common/errors.js +89 -104
  77. package/lib/common/file-system.js +106 -127
  78. package/lib/common/header.js +1 -2
  79. package/lib/common/helpers.js +149 -178
  80. package/lib/common/host-info.js +37 -50
  81. package/lib/common/http-client.js +93 -108
  82. package/lib/common/logger/appenders/cli-appender.js +1 -2
  83. package/lib/common/logger/appenders/emit-appender.js +1 -2
  84. package/lib/common/logger/layouts/cli-layout.js +1 -2
  85. package/lib/common/logger/logger.js +1 -1
  86. package/lib/common/mobile/android/android-application-manager.js +121 -142
  87. package/lib/common/mobile/android/android-debug-bridge-result-handler.js +1 -1
  88. package/lib/common/mobile/android/android-debug-bridge.js +87 -112
  89. package/lib/common/mobile/android/android-device-file-system.js +98 -131
  90. package/lib/common/mobile/android/android-device-hash-service.js +50 -75
  91. package/lib/common/mobile/android/android-device.js +74 -91
  92. package/lib/common/mobile/android/android-emulator-services.js +105 -130
  93. package/lib/common/mobile/android/android-log-filter.js +1 -1
  94. package/lib/common/mobile/android/android-virtual-device-service.js +76 -97
  95. package/lib/common/mobile/android/device-android-debug-bridge.js +13 -29
  96. package/lib/common/mobile/android/genymotion/genymotion-service.js +91 -118
  97. package/lib/common/mobile/android/genymotion/virtualbox-service.js +64 -81
  98. package/lib/common/mobile/android/logcat-helper.js +108 -127
  99. package/lib/common/mobile/application-manager-base.js +84 -107
  100. package/lib/common/mobile/device-log-provider-base.js +7 -18
  101. package/lib/common/mobile/ios/device/ios-application-manager.js +79 -108
  102. package/lib/common/mobile/ios/device/ios-device-file-system.js +78 -105
  103. package/lib/common/mobile/ios/device/ios-device-operations.js +105 -142
  104. package/lib/common/mobile/ios/device/ios-device.js +20 -36
  105. package/lib/common/mobile/ios/ios-device-base.js +58 -81
  106. package/lib/common/mobile/ios/simulator/ios-emulator-services.js +63 -92
  107. package/lib/common/mobile/ios/simulator/ios-sim-resolver.js +1 -1
  108. package/lib/common/mobile/ios/simulator/ios-simulator-application-manager.js +60 -89
  109. package/lib/common/mobile/ios/simulator/ios-simulator-device.js +27 -43
  110. package/lib/common/mobile/ios/simulator/ios-simulator-file-system.js +37 -62
  111. package/lib/common/mobile/ios/simulator/ios-simulator-log-provider.js +24 -35
  112. package/lib/common/mobile/mobile-core/android-device-discovery.js +43 -62
  113. package/lib/common/mobile/mobile-core/android-emulator-discovery.js +21 -32
  114. package/lib/common/mobile/mobile-core/android-process-service.js +143 -182
  115. package/lib/common/mobile/mobile-core/device-discovery.js +2 -13
  116. package/lib/common/mobile/mobile-core/devices-service.js +385 -436
  117. package/lib/common/mobile/mobile-core/ios-device-discovery.js +24 -35
  118. package/lib/common/mobile/mobile-core/ios-simulator-discovery.js +47 -62
  119. package/lib/common/mobile/mobile-helper.js +15 -26
  120. package/lib/common/mobile/wp8/wp8-emulator-services.js +25 -52
  121. package/lib/common/opener.js +2 -2
  122. package/lib/common/plist-parser.js +2 -2
  123. package/lib/common/prompter.js +90 -105
  124. package/lib/common/queue.js +9 -20
  125. package/lib/common/services/auto-completion-service.js +39 -52
  126. package/lib/common/services/cancellation.js +17 -28
  127. package/lib/common/services/commands-service.js +146 -169
  128. package/lib/common/services/help-service.js +132 -157
  129. package/lib/common/services/hooks-service.js +93 -108
  130. package/lib/common/services/ios-notification-service.js +21 -34
  131. package/lib/common/services/json-file-settings-service.js +52 -71
  132. package/lib/common/services/lock-service.js +35 -52
  133. package/lib/common/services/message-contract-generator.js +35 -46
  134. package/lib/common/services/micro-templating-service.js +4 -15
  135. package/lib/common/services/net-service.js +90 -107
  136. package/lib/common/services/project-files-manager.js +10 -23
  137. package/lib/common/services/proxy-service.js +13 -24
  138. package/lib/common/services/qr.js +13 -24
  139. package/lib/common/services/settings-service.js +1 -1
  140. package/lib/common/services/xcode-select-service.js +20 -35
  141. package/lib/common/utils.js +2 -2
  142. package/lib/common/validators/project-name-validator.js +1 -1
  143. package/lib/common/validators/validation-result.js +1 -1
  144. package/lib/common/verify-node-version.js +2 -3
  145. package/lib/common/yok.js +23 -36
  146. package/lib/config.js +7 -58
  147. package/lib/constants.js +24 -24
  148. package/lib/controllers/build-controller.js +82 -99
  149. package/lib/controllers/debug-controller.js +107 -128
  150. package/lib/controllers/deploy-controller.js +17 -22
  151. package/lib/controllers/migrate-controller.js +722 -795
  152. package/lib/controllers/platform-controller.js +72 -87
  153. package/lib/controllers/prepare-controller.js +266 -299
  154. package/lib/controllers/run-controller.js +392 -406
  155. package/lib/controllers/update-controller-base.js +16 -29
  156. package/lib/controllers/update-controller.js +94 -119
  157. package/lib/data/prepare-data.js +4 -1
  158. package/lib/definitions/ios-debugger-port-service.d.ts +1 -1
  159. package/lib/definitions/livesync.d.ts +1 -1
  160. package/lib/detached-processes/cleanup-js-subprocess.js +3 -12
  161. package/lib/detached-processes/cleanup-process.js +16 -25
  162. package/lib/device-path-provider.js +23 -34
  163. package/lib/device-sockets/ios/app-debug-socket-proxy-factory.js +149 -164
  164. package/lib/device-sockets/ios/notification.js +1 -1
  165. package/lib/device-sockets/ios/socket-request-executor.js +24 -39
  166. package/lib/helpers/android-bundle-validator-helper.js +1 -1
  167. package/lib/helpers/deploy-command-helper.js +45 -49
  168. package/lib/helpers/key-command-helper.js +4 -13
  169. package/lib/helpers/livesync-command-helper.js +137 -152
  170. package/lib/helpers/network-connectivity-validator.js +6 -17
  171. package/lib/helpers/options-track-helper.js +6 -17
  172. package/lib/helpers/platform-command-helper.js +99 -120
  173. package/lib/key-commands/index.js +161 -211
  174. package/lib/nativescript-cli.js +5 -14
  175. package/lib/node-package-manager.js +81 -104
  176. package/lib/options.js +3 -12
  177. package/lib/package-installation-manager.js +130 -165
  178. package/lib/package-manager.js +63 -86
  179. package/lib/platform-command-param.js +4 -15
  180. package/lib/pnpm-package-manager.js +59 -78
  181. package/lib/project-data.js +1 -1
  182. package/lib/providers/project-files-provider.js +1 -1
  183. package/lib/services/analytics/analytics-broker-process.js +13 -22
  184. package/lib/services/analytics/analytics-broker.js +17 -30
  185. package/lib/services/analytics/analytics-service.js +161 -198
  186. package/lib/services/analytics/google-analytics-provider.js +41 -56
  187. package/lib/services/analytics-settings-service.js +15 -32
  188. package/lib/services/android/android-bundle-tool-service.js +43 -60
  189. package/lib/services/android/gradle-build-args-service.js +9 -20
  190. package/lib/services/android/gradle-build-service.js +34 -47
  191. package/lib/services/android/gradle-command-service.js +22 -35
  192. package/lib/services/android-device-debug-service.js +90 -117
  193. package/lib/services/android-plugin-build-service.js +230 -256
  194. package/lib/services/android-project-service.js +163 -199
  195. package/lib/services/android-resources-migration-service.js +51 -64
  196. package/lib/services/apple-portal/apple-portal-application-service.js +46 -63
  197. package/lib/services/apple-portal/apple-portal-session-service.js +171 -188
  198. package/lib/services/assets-generation/assets-generation-service.js +98 -115
  199. package/lib/services/build-artifacts-service.js +9 -20
  200. package/lib/services/build-info-file-service.js +20 -35
  201. package/lib/services/cleanup-service.js +47 -76
  202. package/lib/services/cocoapods-service.js +115 -136
  203. package/lib/services/device/device-install-app-service.js +73 -90
  204. package/lib/services/doctor-service.js +99 -118
  205. package/lib/services/extensibility-service.js +81 -100
  206. package/lib/services/files-hash-service.js +26 -43
  207. package/lib/services/hmr-status-service.js +1 -1
  208. package/lib/services/initialize-service.js +37 -50
  209. package/lib/services/ios/export-options-plist-service.js +38 -51
  210. package/lib/services/ios/ios-signing-service.js +161 -180
  211. package/lib/services/ios/spm-service.js +40 -53
  212. package/lib/services/ios/xcodebuild-args-service.js +77 -94
  213. package/lib/services/ios/xcodebuild-command-service.js +14 -25
  214. package/lib/services/ios/xcodebuild-service.js +50 -69
  215. package/lib/services/ios-debugger-port-service.js +23 -36
  216. package/lib/services/ios-device-debug-service.js +75 -102
  217. package/lib/services/ios-entitlements-service.js +31 -42
  218. package/lib/services/ios-extensions-service.js +18 -29
  219. package/lib/services/ios-project-service.js +405 -460
  220. package/lib/services/ios-provision-service.js +108 -129
  221. package/lib/services/ios-watch-app-service.js +21 -32
  222. package/lib/services/ip-service.js +38 -53
  223. package/lib/services/itmstransporter-service.js +129 -152
  224. package/lib/services/livesync/android-device-livesync-service-base.js +31 -48
  225. package/lib/services/livesync/android-device-livesync-service.js +120 -149
  226. package/lib/services/livesync/android-device-livesync-sockets-service.js +121 -152
  227. package/lib/services/livesync/android-livesync-service.js +14 -35
  228. package/lib/services/livesync/android-livesync-tool.js +89 -112
  229. package/lib/services/livesync/device-livesync-service-base.js +15 -28
  230. package/lib/services/livesync/ios-device-livesync-service.js +114 -143
  231. package/lib/services/livesync/ios-livesync-service.js +42 -58
  232. package/lib/services/livesync/platform-livesync-service-base.js +94 -119
  233. package/lib/services/log-parser-service.js +1 -1
  234. package/lib/services/log-source-map-service.js +30 -41
  235. package/lib/services/marking-mode-service.js +15 -28
  236. package/lib/services/npm-config-service.js +1 -1
  237. package/lib/services/pacote-service.js +49 -64
  238. package/lib/services/performance-service.js +1 -1
  239. package/lib/services/platform/add-platform-service.js +50 -71
  240. package/lib/services/platform/platform-validation-service.js +22 -33
  241. package/lib/services/platform/prepare-native-platform-service.js +49 -62
  242. package/lib/services/platform-environment-requirements.js +26 -37
  243. package/lib/services/plugins-service.js +122 -147
  244. package/lib/services/project-backup-service.js +1 -1
  245. package/lib/services/project-changes-service.js +124 -141
  246. package/lib/services/project-cleanup-service.js +64 -77
  247. package/lib/services/project-config-service.js +71 -80
  248. package/lib/services/project-data-service.js +101 -118
  249. package/lib/services/project-name-service.js +28 -43
  250. package/lib/services/project-service.js +84 -103
  251. package/lib/services/project-templates-service.js +52 -67
  252. package/lib/services/start-service.js +41 -59
  253. package/lib/services/temp-service.js +8 -21
  254. package/lib/services/terminal-spinner-service.js +13 -24
  255. package/lib/services/test-execution-service.js +59 -72
  256. package/lib/services/test-initialization-service.js +2 -2
  257. package/lib/services/timeline-profiler-service.js +1 -1
  258. package/lib/services/versions-service.js +119 -138
  259. package/lib/services/webpack/webpack-compiler-service.js +211 -231
  260. package/lib/services/xcconfig-service.js +8 -19
  261. package/lib/sys-info.js +45 -62
  262. package/lib/tools/node-modules/node-modules-builder.js +16 -27
  263. package/lib/yarn-package-manager.js +59 -78
  264. package/lib/yarn2-package-manager.js +60 -79
  265. package/package.json +57 -55
  266. package/vendor/aab-tool/bundletool.jar +0 -0
  267. package/lib/common/resources/platform-tools/android/darwin/NOTICE.txt +0 -3407
  268. package/lib/common/resources/platform-tools/android/darwin/adb +0 -0
  269. package/lib/common/resources/platform-tools/android/linux/NOTICE.txt +0 -4451
  270. package/lib/common/resources/platform-tools/android/linux/adb +0 -0
  271. package/lib/common/resources/platform-tools/android/win32/AdbWinApi.dll +0 -0
  272. package/lib/common/resources/platform-tools/android/win32/AdbWinUsbApi.dll +0 -0
  273. package/lib/common/resources/platform-tools/android/win32/NOTICE.txt +0 -4451
  274. package/lib/common/resources/platform-tools/android/win32/adb.exe +0 -0
  275. package/lib/common/resources/platform-tools/android/win32/fastboot.exe +0 -0
@@ -5,15 +5,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
8
  Object.defineProperty(exports, "__esModule", { value: true });
18
9
  exports.DevicesService = void 0;
19
10
  const assert = require("assert");
@@ -63,107 +54,101 @@ class DevicesService extends events_1.EventEmitter {
63
54
  this.$iOSSimulatorDiscovery,
64
55
  ];
65
56
  }
66
- pickSingleDevice(options) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- if (options.onlyDevices && options.onlyEmulators) {
69
- this.$errors.fail(constants_1.DebugCommandErrors.UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR);
70
- }
71
- if (options.deviceId) {
72
- const device = yield this.getDevice(options.deviceId);
73
- return device;
57
+ async pickSingleDevice(options) {
58
+ if (options.onlyDevices && options.onlyEmulators) {
59
+ this.$errors.fail(constants_1.DebugCommandErrors.UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR);
60
+ }
61
+ if (options.deviceId) {
62
+ const device = await this.getDevice(options.deviceId);
63
+ return device;
64
+ }
65
+ const availableDevicesAndEmulators = this.getDeviceInstances().filter((d) => d.deviceInfo.status === constants_2.CONNECTED_STATUS &&
66
+ (!this.platform ||
67
+ d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase()));
68
+ const selectedDevices = availableDevicesAndEmulators.filter((d) => options.onlyEmulators
69
+ ? d.isEmulator
70
+ : options.onlyDevices
71
+ ? !d.isEmulator
72
+ : true);
73
+ if (selectedDevices.length > 1) {
74
+ if ((0, helpers_1.isInteractive)()) {
75
+ const choices = selectedDevices.map((e) => `${e.deviceInfo.identifier} - ${e.deviceInfo.displayName}`);
76
+ const selectedDeviceString = await this.$prompter.promptForChoice("Select device for debugging", choices);
77
+ const selectedDevice = _.find(selectedDevices, (d) => `${d.deviceInfo.identifier} - ${d.deviceInfo.displayName}` ===
78
+ selectedDeviceString);
79
+ return selectedDevice;
74
80
  }
75
- const availableDevicesAndEmulators = this.getDeviceInstances().filter((d) => d.deviceInfo.status === constants_2.CONNECTED_STATUS &&
76
- (!this.platform ||
77
- d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase()));
78
- const selectedDevices = availableDevicesAndEmulators.filter((d) => options.onlyEmulators
79
- ? d.isEmulator
80
- : options.onlyDevices
81
- ? !d.isEmulator
82
- : true);
83
- if (selectedDevices.length > 1) {
84
- if ((0, helpers_1.isInteractive)()) {
85
- const choices = selectedDevices.map((e) => `${e.deviceInfo.identifier} - ${e.deviceInfo.displayName}`);
86
- const selectedDeviceString = yield this.$prompter.promptForChoice("Select device for debugging", choices);
87
- const selectedDevice = _.find(selectedDevices, (d) => `${d.deviceInfo.identifier} - ${d.deviceInfo.displayName}` ===
88
- selectedDeviceString);
89
- return selectedDevice;
81
+ else {
82
+ const sortedInstances = _.sortBy(selectedDevices, (e) => e.deviceInfo.version);
83
+ const emulators = sortedInstances.filter((e) => e.isEmulator);
84
+ const devices = sortedInstances.filter((d) => !d.isEmulator);
85
+ let selectedInstance;
86
+ if (options.onlyEmulators || options.onlyDevices) {
87
+ selectedInstance = _.last(sortedInstances);
90
88
  }
91
89
  else {
92
- const sortedInstances = _.sortBy(selectedDevices, (e) => e.deviceInfo.version);
93
- const emulators = sortedInstances.filter((e) => e.isEmulator);
94
- const devices = sortedInstances.filter((d) => !d.isEmulator);
95
- let selectedInstance;
96
- if (options.onlyEmulators || options.onlyDevices) {
97
- selectedInstance = _.last(sortedInstances);
90
+ if (emulators.length) {
91
+ selectedInstance = _.last(emulators);
98
92
  }
99
93
  else {
100
- if (emulators.length) {
101
- selectedInstance = _.last(emulators);
102
- }
103
- else {
104
- selectedInstance = _.last(devices);
105
- }
94
+ selectedInstance = _.last(devices);
106
95
  }
107
- this.$logger.warn(`Multiple devices/emulators found. Starting debugger on ${selectedInstance.deviceInfo.identifier}. ` +
108
- "If you want to debug on specific device/emulator, you can specify it with --device option.");
109
- return selectedInstance;
110
96
  }
97
+ this.$logger.warn(`Multiple devices/emulators found. Starting debugger on ${selectedInstance.deviceInfo.identifier}. ` +
98
+ "If you want to debug on specific device/emulator, you can specify it with --device option.");
99
+ return selectedInstance;
111
100
  }
112
- else if (selectedDevices.length === 1) {
113
- return _.head(selectedDevices);
114
- }
115
- this.$errors.fail(constants_1.DebugCommandErrors.NO_DEVICES_EMULATORS_FOUND_FOR_OPTIONS);
116
- });
101
+ }
102
+ else if (selectedDevices.length === 1) {
103
+ return _.head(selectedDevices);
104
+ }
105
+ this.$errors.fail(constants_1.DebugCommandErrors.NO_DEVICES_EMULATORS_FOUND_FOR_OPTIONS);
117
106
  }
118
- getEmulatorImages(options) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- const result = Object.create(null);
121
- if (this.$hostInfo.isDarwin &&
122
- (!options ||
123
- !options.platform ||
124
- this.$mobileHelper.isiOSPlatform(options.platform))) {
125
- result.ios = yield this.$iOSEmulatorServices.getEmulatorImages();
126
- }
127
- if (!options ||
107
+ async getEmulatorImages(options) {
108
+ const result = Object.create(null);
109
+ if (this.$hostInfo.isDarwin &&
110
+ (!options ||
128
111
  !options.platform ||
129
- this.$mobileHelper.isAndroidPlatform(options.platform)) {
130
- result.android = yield this.$androidEmulatorServices.getEmulatorImages();
131
- }
132
- return result;
133
- });
112
+ this.$mobileHelper.isiOSPlatform(options.platform))) {
113
+ result.ios = await this.$iOSEmulatorServices.getEmulatorImages();
114
+ }
115
+ if (!options ||
116
+ !options.platform ||
117
+ this.$mobileHelper.isAndroidPlatform(options.platform)) {
118
+ result.android = await this.$androidEmulatorServices.getEmulatorImages();
119
+ }
120
+ return result;
134
121
  }
135
- startEmulator(options) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- if (!options || (!options.imageIdentifier && !options.emulatorIdOrName)) {
138
- return ["Missing mandatory image identifier or name option."];
139
- }
140
- const availableEmulatorsOutput = yield this.getEmulatorImages({
141
- platform: options.platform,
142
- });
143
- const emulators = this.$emulatorHelper.getEmulatorsFromAvailableEmulatorsOutput(availableEmulatorsOutput);
144
- const errors = this.$emulatorHelper.getErrorsFromAvailableEmulatorsOutput(availableEmulatorsOutput);
145
- let emulator = null;
146
- if (options.imageIdentifier) {
147
- emulator = this.$emulatorHelper.getEmulatorByImageIdentifier(options.imageIdentifier, emulators);
148
- }
149
- else if (options.emulatorIdOrName) {
150
- emulator = this.$emulatorHelper.getEmulatorByIdOrName(options.emulatorIdOrName, emulators);
151
- }
152
- if (!emulator) {
153
- const additionalErrors = errors && errors.length ? errors : [];
154
- return [
155
- `Unable to find emulator with provided options: ${options}`,
156
- ...additionalErrors,
157
- ];
158
- }
159
- if (emulator.status === constants.RUNNING_EMULATOR_STATUS) {
160
- return null;
161
- }
162
- options.emulator = emulator;
163
- const emulatorService = this.resolveEmulatorServices(emulator.platform);
164
- const result = yield emulatorService.startEmulator(options);
165
- return result.errors && result.errors.length ? result.errors : null;
122
+ async startEmulator(options) {
123
+ if (!options || (!options.imageIdentifier && !options.emulatorIdOrName)) {
124
+ return ["Missing mandatory image identifier or name option."];
125
+ }
126
+ const availableEmulatorsOutput = await this.getEmulatorImages({
127
+ platform: options.platform,
166
128
  });
129
+ const emulators = this.$emulatorHelper.getEmulatorsFromAvailableEmulatorsOutput(availableEmulatorsOutput);
130
+ const errors = this.$emulatorHelper.getErrorsFromAvailableEmulatorsOutput(availableEmulatorsOutput);
131
+ let emulator = null;
132
+ if (options.imageIdentifier) {
133
+ emulator = this.$emulatorHelper.getEmulatorByImageIdentifier(options.imageIdentifier, emulators);
134
+ }
135
+ else if (options.emulatorIdOrName) {
136
+ emulator = this.$emulatorHelper.getEmulatorByIdOrName(options.emulatorIdOrName, emulators);
137
+ }
138
+ if (!emulator) {
139
+ const additionalErrors = errors && errors.length ? errors : [];
140
+ return [
141
+ `Unable to find emulator with provided options: ${options}`,
142
+ ...additionalErrors,
143
+ ];
144
+ }
145
+ if (emulator.status === constants.RUNNING_EMULATOR_STATUS) {
146
+ return null;
147
+ }
148
+ options.emulator = emulator;
149
+ const emulatorService = this.resolveEmulatorServices(emulator.platform);
150
+ const result = await emulatorService.startEmulator(options);
151
+ return result.errors && result.errors.length ? result.errors : null;
167
152
  }
168
153
  get platform() {
169
154
  return this._platform;
@@ -207,11 +192,9 @@ class DevicesService extends events_1.EventEmitter {
207
192
  return device;
208
193
  });
209
194
  }
210
- getInstalledApplications(deviceIdentifier) {
211
- return __awaiter(this, void 0, void 0, function* () {
212
- const device = yield this.getDevice(deviceIdentifier);
213
- return device.applicationManager.getInstalledApplications();
214
- });
195
+ async getInstalledApplications(deviceIdentifier) {
196
+ const device = await this.getDevice(deviceIdentifier);
197
+ return device.applicationManager.getInstalledApplications();
215
198
  }
216
199
  addDeviceDiscovery(deviceDiscovery) {
217
200
  this._otherDeviceDiscoveries.push(deviceDiscovery);
@@ -264,66 +247,62 @@ class DevicesService extends events_1.EventEmitter {
264
247
  delete this._availableEmulators[emulator.imageIdentifier];
265
248
  this.emit(constants.EmulatorDiscoveryNames.EMULATOR_IMAGE_LOST, emulator);
266
249
  }
267
- detectCurrentlyAttachedDevices(deviceInitOpts) {
268
- return __awaiter(this, void 0, void 0, function* () {
269
- const options = this.getDeviceLookingOptions(deviceInitOpts);
270
- for (const deviceDiscovery of this._allDeviceDiscoveries) {
271
- try {
272
- yield deviceDiscovery.startLookingForDevices(options);
273
- }
274
- catch (err) {
275
- this.$logger.trace("Error while checking for devices.", err);
276
- }
277
- }
278
- });
279
- }
280
- detectCurrentlyAvailableEmulators() {
281
- return __awaiter(this, void 0, void 0, function* () {
282
- try {
283
- yield this.$androidEmulatorDiscovery.startLookingForDevices();
284
- }
285
- catch (err) {
286
- this.$logger.trace(`Error while checking for Android emulators. ${err}`);
287
- }
250
+ async detectCurrentlyAttachedDevices(deviceInitOpts) {
251
+ const options = this.getDeviceLookingOptions(deviceInitOpts);
252
+ for (const deviceDiscovery of this._allDeviceDiscoveries) {
288
253
  try {
289
- yield this.$iOSSimulatorDiscovery.checkForAvailableSimulators();
254
+ await deviceDiscovery.startLookingForDevices(options);
290
255
  }
291
256
  catch (err) {
292
- this.$logger.trace(`Error while checking for iOS simulators. ${err}`);
257
+ this.$logger.trace("Error while checking for devices.", err);
293
258
  }
294
- });
259
+ }
260
+ }
261
+ async detectCurrentlyAvailableEmulators() {
262
+ try {
263
+ await this.$androidEmulatorDiscovery.startLookingForDevices();
264
+ }
265
+ catch (err) {
266
+ this.$logger.trace(`Error while checking for Android emulators. ${err}`);
267
+ }
268
+ try {
269
+ await this.$iOSSimulatorDiscovery.checkForAvailableSimulators();
270
+ }
271
+ catch (err) {
272
+ this.$logger.trace(`Error while checking for iOS simulators. ${err}`);
273
+ }
295
274
  }
296
275
  startDeviceDetectionInterval(deviceInitOpts = {}) {
297
276
  if (!this.deviceDetectionInterval) {
298
277
  let isDeviceDetectionIntervalInProgress = false;
299
- this.deviceDetectionInterval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
278
+ this.deviceDetectionInterval = setInterval(async () => {
300
279
  if (isDeviceDetectionIntervalInProgress) {
301
280
  return;
302
281
  }
303
282
  isDeviceDetectionIntervalInProgress = true;
304
- yield this.detectCurrentlyAttachedDevices(deviceInitOpts);
283
+ await this.detectCurrentlyAttachedDevices(deviceInitOpts);
305
284
  try {
306
285
  const trustedDevices = _.filter(this._devices, (device) => device.deviceInfo.status === constants.CONNECTED_STATUS);
307
- yield (0, helpers_1.settlePromises)(_.map(trustedDevices, (device) => device.applicationManager.checkForApplicationUpdates()));
286
+ await (0, helpers_1.settlePromises)(_.map(trustedDevices, (device) => device.applicationManager.checkForApplicationUpdates()));
308
287
  }
309
288
  catch (err) {
310
289
  this.$logger.trace("Error checking for application updates on devices.", err);
311
290
  }
312
291
  isDeviceDetectionIntervalInProgress = false;
313
- }), deviceInitOpts.detectionInterval || DevicesService.DEVICE_LOOKING_INTERVAL);
292
+ }, deviceInitOpts.detectionInterval || DevicesService.DEVICE_LOOKING_INTERVAL);
314
293
  this.deviceDetectionInterval.unref();
315
294
  }
316
295
  }
317
296
  startEmulatorDetectionInterval(opts = {}) {
318
297
  let isEmulatorDetectionIntervalRunning = false;
319
- this.emulatorDetectionInterval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
298
+ this.emulatorDetectionInterval = setInterval(async () => {
320
299
  if (isEmulatorDetectionIntervalRunning) {
321
300
  return;
322
301
  }
323
302
  isEmulatorDetectionIntervalRunning = true;
324
- yield this.detectCurrentlyAvailableEmulators();
303
+ await this.detectCurrentlyAvailableEmulators();
325
304
  isEmulatorDetectionIntervalRunning = false;
326
- }), opts.detectionInterval || DevicesService.EMULATOR_IMAGES_DETECTION_INTERVAL);
305
+ }, opts.detectionInterval || DevicesService.EMULATOR_IMAGES_DETECTION_INTERVAL);
327
306
  this.emulatorDetectionInterval.unref();
328
307
  }
329
308
  stopDeviceDetectionInterval() {
@@ -351,89 +330,81 @@ class DevicesService extends events_1.EventEmitter {
351
330
  }
352
331
  return searchedDevice;
353
332
  }
354
- startLookingForDevices(deviceInitOpts) {
355
- return __awaiter(this, void 0, void 0, function* () {
356
- this.$logger.trace("startLookingForDevices; platform is %s", this._platform);
357
- if (this._platform) {
358
- return this.detectCurrentlyAttachedDevices(deviceInitOpts);
359
- }
360
- yield this.detectCurrentlyAttachedDevices(deviceInitOpts);
361
- yield this.detectCurrentlyAvailableEmulators();
362
- yield this.startDeviceDetectionInterval(deviceInitOpts);
363
- });
333
+ async startLookingForDevices(deviceInitOpts) {
334
+ this.$logger.trace("startLookingForDevices; platform is %s", this._platform);
335
+ if (this._platform) {
336
+ return this.detectCurrentlyAttachedDevices(deviceInitOpts);
337
+ }
338
+ await this.detectCurrentlyAttachedDevices(deviceInitOpts);
339
+ await this.detectCurrentlyAvailableEmulators();
340
+ await this.startDeviceDetectionInterval(deviceInitOpts);
364
341
  }
365
342
  getDeviceByIndex(index) {
366
343
  this.validateIndex(index - 1);
367
344
  return this.getDeviceInstances()[index - 1];
368
345
  }
369
- getDevice(deviceOption) {
370
- return __awaiter(this, void 0, void 0, function* () {
371
- let device = null;
372
- if (!device) {
373
- device = _.find(this.getDeviceInstances(), (d) => (d.deviceInfo.identifier &&
374
- d.deviceInfo.identifier === deviceOption) ||
375
- (d.deviceInfo.displayName &&
376
- d.deviceInfo.displayName === deviceOption) ||
377
- (d.deviceInfo.imageIdentifier &&
378
- d.deviceInfo.imageIdentifier === deviceOption));
379
- }
380
- if (!device && helpers.isNumberWithoutExponent(deviceOption)) {
381
- device = this.getDeviceByIndex(parseInt(deviceOption, 10));
382
- }
383
- if (!device) {
384
- this.$errors.fail(this.$messages.Devices
385
- .NotFoundDeviceByIdentifierErrorMessageWithIdentifier, deviceOption, this.$staticConfig.CLIENT_NAME.toLowerCase());
386
- }
387
- return device;
388
- });
346
+ async getDevice(deviceOption) {
347
+ let device = null;
348
+ if (!device) {
349
+ device = _.find(this.getDeviceInstances(), (d) => (d.deviceInfo.identifier &&
350
+ d.deviceInfo.identifier === deviceOption) ||
351
+ (d.deviceInfo.displayName &&
352
+ d.deviceInfo.displayName === deviceOption) ||
353
+ (d.deviceInfo.imageIdentifier &&
354
+ d.deviceInfo.imageIdentifier === deviceOption));
355
+ }
356
+ if (!device && helpers.isNumberWithoutExponent(deviceOption)) {
357
+ device = this.getDeviceByIndex(parseInt(deviceOption, 10));
358
+ }
359
+ if (!device) {
360
+ this.$errors.fail(this.$messages.Devices
361
+ .NotFoundDeviceByIdentifierErrorMessageWithIdentifier, deviceOption, this.$staticConfig.CLIENT_NAME.toLowerCase());
362
+ }
363
+ return device;
389
364
  }
390
- executeOnDevice(action, canExecute) {
391
- return __awaiter(this, void 0, void 0, function* () {
392
- if (!canExecute || canExecute(this._device)) {
393
- return {
394
- deviceIdentifier: this._device.deviceInfo.identifier,
395
- result: yield action(this._device),
396
- };
397
- }
398
- });
365
+ async executeOnDevice(action, canExecute) {
366
+ if (!canExecute || canExecute(this._device)) {
367
+ return {
368
+ deviceIdentifier: this._device.deviceInfo.identifier,
369
+ result: await action(this._device),
370
+ };
371
+ }
399
372
  }
400
- executeOnAllConnectedDevices(action, canExecute) {
401
- return __awaiter(this, void 0, void 0, function* () {
402
- const devices = this.filterDevicesByPlatform();
403
- const sortedDevices = _.sortBy(devices, (device) => device.deviceInfo.platform);
404
- const result = [];
405
- const errors = [];
406
- for (const device of sortedDevices) {
407
- try {
408
- if (!canExecute || canExecute(device)) {
409
- result.push({
410
- deviceIdentifier: device.deviceInfo.identifier,
411
- result: yield action(device),
412
- });
413
- }
414
- }
415
- catch (err) {
416
- err.deviceIdentifier = device.deviceInfo.identifier;
417
- this.$logger.trace(`Error while executing action on device ${device.deviceInfo.identifier}. The error is`, err);
418
- errors.push(err);
373
+ async executeOnAllConnectedDevices(action, canExecute) {
374
+ const devices = this.filterDevicesByPlatform();
375
+ const sortedDevices = _.sortBy(devices, (device) => device.deviceInfo.platform);
376
+ const result = [];
377
+ const errors = [];
378
+ for (const device of sortedDevices) {
379
+ try {
380
+ if (!canExecute || canExecute(device)) {
381
+ result.push({
382
+ deviceIdentifier: device.deviceInfo.identifier,
383
+ result: await action(device),
384
+ });
419
385
  }
420
386
  }
421
- if (errors.length) {
422
- let preErrorMsg = "";
423
- if (errors.length > 1) {
424
- preErrorMsg = "Multiple errors were thrown:" + os_1.EOL;
425
- }
426
- const errorMessage = `${preErrorMsg}${errors
427
- .map((e) => e.stack || e.message || e)
428
- .join(os_1.EOL)}`;
429
- this.$errors.fail(errorMessage);
387
+ catch (err) {
388
+ err.deviceIdentifier = device.deviceInfo.identifier;
389
+ this.$logger.trace(`Error while executing action on device ${device.deviceInfo.identifier}. The error is`, err);
390
+ errors.push(err);
430
391
  }
431
- return result;
432
- });
392
+ }
393
+ if (errors.length) {
394
+ let preErrorMsg = "";
395
+ if (errors.length > 1) {
396
+ preErrorMsg = "Multiple errors were thrown:" + os_1.EOL;
397
+ }
398
+ const errorMessage = `${preErrorMsg}${errors
399
+ .map((e) => e.stack || e.message || e)
400
+ .join(os_1.EOL)}`;
401
+ this.$errors.fail(errorMessage);
402
+ }
403
+ return result;
433
404
  }
434
405
  deployOnDevices(deviceIdentifiers, packagePath, appId, projectName, projectDir) {
435
406
  this.$logger.trace(`Called deployOnDevices for identifiers ${deviceIdentifiers} for packageFile: ${packagePath}. Application identifier is ${appId}. Project Name is: ${projectName}`);
436
- return _.map(deviceIdentifiers, (deviceIdentifier) => __awaiter(this, void 0, void 0, function* () {
407
+ return _.map(deviceIdentifiers, async (deviceIdentifier) => {
437
408
  const device = this.getDeviceByIdentifier(deviceIdentifier);
438
409
  let identifier;
439
410
  if (typeof appId === "string") {
@@ -448,117 +419,109 @@ class DevicesService extends events_1.EventEmitter {
448
419
  projectName,
449
420
  projectDir,
450
421
  });
451
- }));
422
+ });
452
423
  }
453
- execute(action, canExecute, options) {
454
- return __awaiter(this, void 0, void 0, function* () {
455
- assert.ok(this._isInitialized, "Devices services not initialized!");
456
- if (this.hasDevices) {
457
- if (this.$hostInfo.isDarwin &&
458
- this._platform &&
459
- this.$mobileHelper.isiOSPlatform(this._platform) &&
460
- this.$options.emulator &&
461
- !this.isOnlyiOSSimultorRunning()) {
462
- const originalCanExecute = canExecute;
463
- canExecute = (dev) => this.isiOSSimulator(dev) &&
464
- (!originalCanExecute || !!originalCanExecute(dev));
465
- }
466
- return this.executeCore(action, canExecute);
424
+ async execute(action, canExecute, options) {
425
+ assert.ok(this._isInitialized, "Devices services not initialized!");
426
+ if (this.hasDevices) {
427
+ if (this.$hostInfo.isDarwin &&
428
+ this._platform &&
429
+ this.$mobileHelper.isiOSPlatform(this._platform) &&
430
+ this.$options.emulator &&
431
+ !this.isOnlyiOSSimultorRunning()) {
432
+ const originalCanExecute = canExecute;
433
+ canExecute = (dev) => this.isiOSSimulator(dev) &&
434
+ (!originalCanExecute || !!originalCanExecute(dev));
435
+ }
436
+ return this.executeCore(action, canExecute);
437
+ }
438
+ else {
439
+ const message = constants.ERROR_NO_DEVICES;
440
+ if (options && options.allowNoDevices) {
441
+ this.$logger.info(message);
467
442
  }
468
443
  else {
469
- const message = constants.ERROR_NO_DEVICES;
470
- if (options && options.allowNoDevices) {
471
- this.$logger.info(message);
444
+ if (!this.$hostInfo.isDarwin &&
445
+ this._platform &&
446
+ this.$mobileHelper.isiOSPlatform(this._platform)) {
447
+ this.$errors.fail(message);
472
448
  }
473
449
  else {
474
- if (!this.$hostInfo.isDarwin &&
475
- this._platform &&
476
- this.$mobileHelper.isiOSPlatform(this._platform)) {
477
- this.$errors.fail(message);
478
- }
479
- else {
480
- return this.executeCore(action, canExecute);
481
- }
450
+ return this.executeCore(action, canExecute);
482
451
  }
483
452
  }
484
- });
453
+ }
485
454
  }
486
- startEmulatorIfNecessary(deviceInitOpts) {
487
- return __awaiter(this, void 0, void 0, function* () {
488
- if (deviceInitOpts && deviceInitOpts.deviceId && deviceInitOpts.emulator) {
489
- this.$errors.fail(`--device and --emulator are incompatible options.
455
+ async startEmulatorIfNecessary(deviceInitOpts) {
456
+ if (deviceInitOpts && deviceInitOpts.deviceId && deviceInitOpts.emulator) {
457
+ this.$errors.fail(`--device and --emulator are incompatible options.
490
458
  If you are trying to run on specific emulator, use "${this.$staticConfig.CLIENT_NAME} run --device <DeviceID>`);
459
+ }
460
+ if (deviceInitOpts &&
461
+ deviceInitOpts.platform &&
462
+ !deviceInitOpts.skipEmulatorStart) {
463
+ this._platform = deviceInitOpts.platform;
464
+ try {
465
+ await this.startLookingForDevices(deviceInitOpts);
491
466
  }
492
- if (deviceInitOpts &&
493
- deviceInitOpts.platform &&
494
- !deviceInitOpts.skipEmulatorStart) {
495
- this._platform = deviceInitOpts.platform;
496
- try {
497
- yield this.startLookingForDevices(deviceInitOpts);
498
- }
499
- catch (err) {
500
- this.$logger.trace("Error while checking for devices.", err);
501
- }
502
- const deviceInstances = this.getDeviceInstances();
503
- if (!deviceInitOpts.deviceId && _.isEmpty(deviceInstances)) {
504
- if (!this.$hostInfo.isDarwin &&
505
- this.$mobileHelper.isApplePlatform(deviceInitOpts.platform)) {
506
- this.$errors.fail(constants.ERROR_NO_DEVICES_CANT_USE_IOS_SIMULATOR);
507
- }
508
- }
509
- try {
510
- yield this._startEmulatorIfNecessary(deviceInitOpts);
511
- }
512
- catch (err) {
513
- const errorMessage = this.getEmulatorError(err, deviceInitOpts.platform);
514
- this.$errors.fail(errorMessage);
515
- }
467
+ catch (err) {
468
+ this.$logger.trace("Error while checking for devices.", err);
516
469
  }
517
- });
518
- }
519
- _startEmulatorIfNecessary(data) {
520
- return __awaiter(this, void 0, void 0, function* () {
521
470
  const deviceInstances = this.getDeviceInstances();
522
- if (!data.deviceId && _.isEmpty(deviceInstances)) {
523
- return this.startEmulatorCore(data);
524
- }
525
- if (data.deviceId) {
526
- if (!helpers.isNumberWithoutExponent(data.deviceId)) {
527
- const activeDeviceInstance = _.find(deviceInstances, (device) => device.deviceInfo.identifier === data.deviceId);
528
- if (!activeDeviceInstance) {
529
- return this.startEmulatorCore(data);
530
- }
471
+ if (!deviceInitOpts.deviceId && _.isEmpty(deviceInstances)) {
472
+ if (!this.$hostInfo.isDarwin &&
473
+ this.$mobileHelper.isApplePlatform(deviceInitOpts.platform)) {
474
+ this.$errors.fail(constants.ERROR_NO_DEVICES_CANT_USE_IOS_SIMULATOR);
531
475
  }
532
476
  }
533
- if (data.platform === this.$devicePlatformsConstants.visionOS &&
534
- deviceInstances.length) {
535
- const runningDeviceInstance = deviceInstances.find((device) => device.deviceInfo.platform === this.$devicePlatformsConstants.visionOS);
536
- if (!runningDeviceInstance) {
537
- return this.startEmulatorCore(data);
538
- }
477
+ try {
478
+ await this._startEmulatorIfNecessary(deviceInitOpts);
539
479
  }
540
- if (data.emulator && deviceInstances.length) {
541
- const runningDeviceInstance = _.some(deviceInstances, (value) => value.isEmulator);
542
- if (!runningDeviceInstance) {
543
- return this.startEmulatorCore(data);
544
- }
480
+ catch (err) {
481
+ const errorMessage = this.getEmulatorError(err, deviceInitOpts.platform);
482
+ this.$errors.fail(errorMessage);
545
483
  }
546
- });
484
+ }
547
485
  }
548
- initialize(data) {
549
- return __awaiter(this, void 0, void 0, function* () {
550
- if (!this._deviceInitializePromise) {
551
- this._deviceInitializePromise = this.initializeCore(data);
486
+ async _startEmulatorIfNecessary(data) {
487
+ const deviceInstances = this.getDeviceInstances();
488
+ if (!data.deviceId && _.isEmpty(deviceInstances)) {
489
+ return this.startEmulatorCore(data);
490
+ }
491
+ if (data.deviceId) {
492
+ if (!helpers.isNumberWithoutExponent(data.deviceId)) {
493
+ const activeDeviceInstance = _.find(deviceInstances, (device) => device.deviceInfo.identifier === data.deviceId);
494
+ if (!activeDeviceInstance) {
495
+ return this.startEmulatorCore(data);
496
+ }
552
497
  }
553
- try {
554
- yield this._deviceInitializePromise;
498
+ }
499
+ if (data.platform === this.$devicePlatformsConstants.visionOS &&
500
+ deviceInstances.length) {
501
+ const runningDeviceInstance = deviceInstances.find((device) => device.deviceInfo.platform === this.$devicePlatformsConstants.visionOS);
502
+ if (!runningDeviceInstance) {
503
+ return this.startEmulatorCore(data);
555
504
  }
556
- catch (err) {
557
- this.$logger.trace(`Error while initializing devicesService: ${err}`);
558
- this._deviceInitializePromise = null;
559
- throw err;
505
+ }
506
+ if (data.emulator && deviceInstances.length) {
507
+ const runningDeviceInstance = _.some(deviceInstances, (value) => value.isEmulator);
508
+ if (!runningDeviceInstance) {
509
+ return this.startEmulatorCore(data);
560
510
  }
561
- });
511
+ }
512
+ }
513
+ async initialize(data) {
514
+ if (!this._deviceInitializePromise) {
515
+ this._deviceInitializePromise = this.initializeCore(data);
516
+ }
517
+ try {
518
+ await this._deviceInitializePromise;
519
+ }
520
+ catch (err) {
521
+ this.$logger.trace(`Error while initializing devicesService: ${err}`);
522
+ this._deviceInitializePromise = null;
523
+ throw err;
524
+ }
562
525
  }
563
526
  getPlatformsFromDeviceDescriptors(deviceDescriptors) {
564
527
  const platforms = _(deviceDescriptors)
@@ -568,91 +531,89 @@ class DevicesService extends events_1.EventEmitter {
568
531
  .value();
569
532
  return platforms;
570
533
  }
571
- initializeCore(deviceInitOpts) {
572
- return __awaiter(this, void 0, void 0, function* () {
573
- if (this._isInitialized) {
574
- return;
575
- }
576
- if (!this.$options.json) {
577
- this.$logger.info("Searching for devices...");
578
- }
579
- deviceInitOpts = deviceInitOpts || {};
580
- this._data = deviceInitOpts;
581
- if (!deviceInitOpts.skipEmulatorStart) {
582
- yield this.startEmulatorIfNecessary(deviceInitOpts);
583
- }
584
- const platform = deviceInitOpts.platform;
585
- const deviceOption = deviceInitOpts.deviceId;
586
- const deviceLookingOptions = {
587
- emulator: deviceInitOpts.emulator,
588
- platform: deviceInitOpts.platform,
589
- shouldReturnImmediateResult: deviceInitOpts.shouldReturnImmediateResult,
590
- detectionInterval: deviceInitOpts.detectionInterval,
591
- fullDiscovery: deviceInitOpts.fullDiscovery,
592
- };
593
- if (platform && deviceOption) {
594
- this._platform = this.$mobileHelper.validatePlatformName(deviceInitOpts.platform);
595
- yield this.startLookingForDevices(deviceLookingOptions);
596
- this._device = yield this.getDevice(deviceOption);
597
- if (this._device.deviceInfo.platform !== this._platform) {
598
- this.$errors.fail(constants.ERROR_CANNOT_RESOLVE_DEVICE);
534
+ async initializeCore(deviceInitOpts) {
535
+ if (this._isInitialized) {
536
+ return;
537
+ }
538
+ if (!this.$options.json) {
539
+ this.$logger.info("Searching for devices...");
540
+ }
541
+ deviceInitOpts = deviceInitOpts || {};
542
+ this._data = deviceInitOpts;
543
+ if (!deviceInitOpts.skipEmulatorStart) {
544
+ await this.startEmulatorIfNecessary(deviceInitOpts);
545
+ }
546
+ const platform = deviceInitOpts.platform;
547
+ const deviceOption = deviceInitOpts.deviceId;
548
+ const deviceLookingOptions = {
549
+ emulator: deviceInitOpts.emulator,
550
+ platform: deviceInitOpts.platform,
551
+ shouldReturnImmediateResult: deviceInitOpts.shouldReturnImmediateResult,
552
+ detectionInterval: deviceInitOpts.detectionInterval,
553
+ fullDiscovery: deviceInitOpts.fullDiscovery,
554
+ };
555
+ if (platform && deviceOption) {
556
+ this._platform = this.$mobileHelper.validatePlatformName(deviceInitOpts.platform);
557
+ await this.startLookingForDevices(deviceLookingOptions);
558
+ this._device = await this.getDevice(deviceOption);
559
+ if (this._device.deviceInfo.platform !== this._platform) {
560
+ this.$errors.fail(constants.ERROR_CANNOT_RESOLVE_DEVICE);
561
+ }
562
+ this.$logger.warn("Your application will be deployed only on the device specified by the provided index or identifier.");
563
+ }
564
+ else if (!platform && deviceOption) {
565
+ await this.startLookingForDevices(deviceLookingOptions);
566
+ this._device = await this.getDevice(deviceOption);
567
+ this._platform = this._device.deviceInfo.platform;
568
+ }
569
+ else if (platform && !deviceOption) {
570
+ this._platform = this.$mobileHelper.validatePlatformName(platform);
571
+ await this.startLookingForDevices(deviceLookingOptions);
572
+ }
573
+ else {
574
+ if (deviceInitOpts.skipInferPlatform) {
575
+ if (deviceInitOpts.skipDeviceDetectionInterval) {
576
+ await this.detectCurrentlyAttachedDevices(deviceLookingOptions);
577
+ }
578
+ else {
579
+ deviceInitOpts.shouldReturnImmediateResult = true;
580
+ await this.startLookingForDevices(deviceLookingOptions);
599
581
  }
600
- this.$logger.warn("Your application will be deployed only on the device specified by the provided index or identifier.");
601
- }
602
- else if (!platform && deviceOption) {
603
- yield this.startLookingForDevices(deviceLookingOptions);
604
- this._device = yield this.getDevice(deviceOption);
605
- this._platform = this._device.deviceInfo.platform;
606
- }
607
- else if (platform && !deviceOption) {
608
- this._platform = this.$mobileHelper.validatePlatformName(platform);
609
- yield this.startLookingForDevices(deviceLookingOptions);
610
582
  }
611
583
  else {
612
- if (deviceInitOpts.skipInferPlatform) {
613
- if (deviceInitOpts.skipDeviceDetectionInterval) {
614
- yield this.detectCurrentlyAttachedDevices(deviceLookingOptions);
584
+ await this.startLookingForDevices(deviceLookingOptions);
585
+ const devices = this.getDeviceInstances();
586
+ const platforms = _(devices)
587
+ .map((device) => device.deviceInfo.platform)
588
+ .filter((pl) => {
589
+ try {
590
+ return !!this.$mobileHelper.validatePlatformName(pl);
615
591
  }
616
- else {
617
- deviceInitOpts.shouldReturnImmediateResult = true;
618
- yield this.startLookingForDevices(deviceLookingOptions);
592
+ catch (err) {
593
+ this.$logger.warn(err.message);
594
+ return null;
619
595
  }
596
+ })
597
+ .uniq()
598
+ .value();
599
+ if (platforms.length === 1) {
600
+ this._platform = platforms[0];
601
+ }
602
+ else if (platforms.length === 0) {
603
+ this.$errors.fail(constants.ERROR_NO_DEVICES);
620
604
  }
621
605
  else {
622
- yield this.startLookingForDevices(deviceLookingOptions);
623
- const devices = this.getDeviceInstances();
624
- const platforms = _(devices)
625
- .map((device) => device.deviceInfo.platform)
626
- .filter((pl) => {
627
- try {
628
- return !!this.$mobileHelper.validatePlatformName(pl);
629
- }
630
- catch (err) {
631
- this.$logger.warn(err.message);
632
- return null;
633
- }
634
- })
635
- .uniq()
636
- .value();
637
- if (platforms.length === 1) {
638
- this._platform = platforms[0];
639
- }
640
- else if (platforms.length === 0) {
641
- this.$errors.fail(constants.ERROR_NO_DEVICES);
642
- }
643
- else {
644
- this.$errors.fail("Multiple device platforms detected (%s). Specify platform or device on command line.", helpers.formatListOfNames(platforms, "and"));
645
- }
606
+ this.$errors.fail("Multiple device platforms detected (%s). Specify platform or device on command line.", helpers.formatListOfNames(platforms, "and"));
646
607
  }
647
608
  }
648
- if (!this.$hostInfo.isDarwin &&
649
- this._platform &&
650
- this.$mobileHelper.isiOSPlatform(this._platform) &&
651
- this.$options.emulator) {
652
- this.$errors.fail(constants.ERROR_CANT_USE_SIMULATOR);
653
- }
654
- this._isInitialized = true;
655
- });
609
+ }
610
+ if (!this.$hostInfo.isDarwin &&
611
+ this._platform &&
612
+ this.$mobileHelper.isiOSPlatform(this._platform) &&
613
+ this.$options.emulator) {
614
+ this.$errors.fail(constants.ERROR_CANT_USE_SIMULATOR);
615
+ }
616
+ this._isInitialized = true;
656
617
  }
657
618
  get hasDevices() {
658
619
  if (!this._platform) {
@@ -672,30 +633,24 @@ class DevicesService extends events_1.EventEmitter {
672
633
  getDeviceByDeviceOption() {
673
634
  return this._device;
674
635
  }
675
- mapAbstractToTcpPort(deviceIdentifier, appIdentifier, framework) {
676
- return __awaiter(this, void 0, void 0, function* () {
677
- return this.$androidProcessService.mapAbstractToTcpPort(deviceIdentifier, appIdentifier, framework);
678
- });
636
+ async mapAbstractToTcpPort(deviceIdentifier, appIdentifier, framework) {
637
+ return this.$androidProcessService.mapAbstractToTcpPort(deviceIdentifier, appIdentifier, framework);
679
638
  }
680
639
  getDebuggableApps(deviceIdentifiers) {
681
640
  return _.map(deviceIdentifiers, (deviceIdentifier) => this.getDebuggableAppsCore(deviceIdentifier));
682
641
  }
683
- getDebuggableViews(deviceIdentifier, appIdentifier) {
684
- return __awaiter(this, void 0, void 0, function* () {
685
- const device = this.getDeviceByIdentifier(deviceIdentifier), debuggableViewsPerApp = yield device.applicationManager.getDebuggableAppViews([appIdentifier]);
686
- return debuggableViewsPerApp && debuggableViewsPerApp[appIdentifier];
687
- });
642
+ async getDebuggableViews(deviceIdentifier, appIdentifier) {
643
+ const device = this.getDeviceByIdentifier(deviceIdentifier), debuggableViewsPerApp = await device.applicationManager.getDebuggableAppViews([appIdentifier]);
644
+ return debuggableViewsPerApp && debuggableViewsPerApp[appIdentifier];
688
645
  }
689
646
  getDebuggableAppsCore(deviceIdentifier) {
690
647
  const device = this.getDeviceByIdentifier(deviceIdentifier);
691
648
  return device.applicationManager.getDebuggableApps();
692
649
  }
693
- deployOnDevice(device, appData) {
694
- return __awaiter(this, void 0, void 0, function* () {
695
- yield device.applicationManager.reinstallApplication(appData.appId, appData.packagePath);
696
- this.$logger.info(`Successfully deployed on device with identifier '${device.deviceInfo.identifier}'.`);
697
- yield device.applicationManager.tryStartApplication(appData);
698
- });
650
+ async deployOnDevice(device, appData) {
651
+ await device.applicationManager.reinstallApplication(appData.appId, appData.packagePath);
652
+ this.$logger.info(`Successfully deployed on device with identifier '${device.deviceInfo.identifier}'.`);
653
+ await device.applicationManager.tryStartApplication(appData);
699
654
  }
700
655
  filterDevicesByPlatform() {
701
656
  return _.filter(this.getDeviceInstances(), (device) => {
@@ -723,58 +678,52 @@ class DevicesService extends events_1.EventEmitter {
723
678
  }
724
679
  return null;
725
680
  }
726
- startEmulatorCore(deviceInitOpts = {}) {
727
- return __awaiter(this, void 0, void 0, function* () {
728
- const { deviceId } = deviceInitOpts;
729
- const platform = deviceInitOpts.platform || this._platform;
730
- const emulatorServices = this.resolveEmulatorServices(platform);
731
- if (!emulatorServices) {
732
- this.$errors.fail("Unable to detect platform for which to start emulator.");
733
- }
734
- const result = yield emulatorServices.startEmulator({
735
- emulatorIdOrName: deviceId,
736
- imageIdentifier: deviceId,
737
- platform: platform,
738
- sdk: this._data && this._data.sdk,
739
- });
740
- if (result && result.errors && result.errors.length) {
741
- this.$errors.fail(result.errors.join("\n"));
742
- }
743
- const deviceLookingOptions = this.getDeviceLookingOptions(deviceInitOpts);
744
- if (this.$mobileHelper.isAndroidPlatform(platform)) {
745
- yield this.$androidDeviceDiscovery.startLookingForDevices(deviceLookingOptions);
746
- }
747
- else if (this.$mobileHelper.isiOSPlatform(platform) &&
748
- this.$hostInfo.isDarwin) {
749
- yield this.$iOSSimulatorDiscovery.startLookingForDevices(deviceLookingOptions);
750
- }
681
+ async startEmulatorCore(deviceInitOpts = {}) {
682
+ const { deviceId } = deviceInitOpts;
683
+ const platform = deviceInitOpts.platform || this._platform;
684
+ const emulatorServices = this.resolveEmulatorServices(platform);
685
+ if (!emulatorServices) {
686
+ this.$errors.fail("Unable to detect platform for which to start emulator.");
687
+ }
688
+ const result = await emulatorServices.startEmulator({
689
+ emulatorIdOrName: deviceId,
690
+ imageIdentifier: deviceId,
691
+ platform: platform,
692
+ sdk: this._data && this._data.sdk,
751
693
  });
694
+ if (result && result.errors && result.errors.length) {
695
+ this.$errors.fail(result.errors.join("\n"));
696
+ }
697
+ const deviceLookingOptions = this.getDeviceLookingOptions(deviceInitOpts);
698
+ if (this.$mobileHelper.isAndroidPlatform(platform)) {
699
+ await this.$androidDeviceDiscovery.startLookingForDevices(deviceLookingOptions);
700
+ }
701
+ else if (this.$mobileHelper.isiOSPlatform(platform) &&
702
+ this.$hostInfo.isDarwin) {
703
+ await this.$iOSSimulatorDiscovery.startLookingForDevices(deviceLookingOptions);
704
+ }
752
705
  }
753
- executeCore(action, canExecute) {
754
- return __awaiter(this, void 0, void 0, function* () {
755
- if (this._device) {
756
- return [yield this.executeOnDevice(action, canExecute)];
757
- }
758
- return this.executeOnAllConnectedDevices(action, canExecute);
759
- });
706
+ async executeCore(action, canExecute) {
707
+ if (this._device) {
708
+ return [await this.executeOnDevice(action, canExecute)];
709
+ }
710
+ return this.executeOnAllConnectedDevices(action, canExecute);
760
711
  }
761
- isApplicationInstalledOnDevice(deviceIdentifier, appData) {
762
- return __awaiter(this, void 0, void 0, function* () {
763
- let isInstalled = false;
764
- const device = this.getDeviceByIdentifier(deviceIdentifier);
765
- try {
766
- isInstalled = yield device.applicationManager.isApplicationInstalled(appData.appId);
767
- yield device.applicationManager.tryStartApplication(appData);
768
- }
769
- catch (err) {
770
- this.$logger.trace("Error while checking is application installed. Error is: ", err);
771
- }
772
- return {
773
- appIdentifier: appData.appId,
774
- deviceIdentifier,
775
- isInstalled,
776
- };
777
- });
712
+ async isApplicationInstalledOnDevice(deviceIdentifier, appData) {
713
+ let isInstalled = false;
714
+ const device = this.getDeviceByIdentifier(deviceIdentifier);
715
+ try {
716
+ isInstalled = await device.applicationManager.isApplicationInstalled(appData.appId);
717
+ await device.applicationManager.tryStartApplication(appData);
718
+ }
719
+ catch (err) {
720
+ this.$logger.trace("Error while checking is application installed. Error is: ", err);
721
+ }
722
+ return {
723
+ appIdentifier: appData.appId,
724
+ deviceIdentifier,
725
+ isInstalled,
726
+ };
778
727
  }
779
728
  getDeviceLookingOptions(deviceInitOpts = {}) {
780
729
  const { shouldReturnImmediateResult, emulator } = deviceInitOpts;
@@ -797,6 +746,7 @@ class DevicesService extends events_1.EventEmitter {
797
746
  `To list available ${emulatorName.toLowerCase()} images, run '${this.$staticConfig.CLIENT_NAME.toLowerCase()} device <Platform> --available-devices'.`);
798
747
  }
799
748
  }
749
+ exports.DevicesService = DevicesService;
800
750
  DevicesService.DEVICE_LOOKING_INTERVAL = 200;
801
751
  DevicesService.EMULATOR_IMAGES_DETECTION_INTERVAL = 60 * 1000;
802
752
  __decorate([
@@ -850,5 +800,4 @@ __decorate([
850
800
  __decorate([
851
801
  (0, decorators_1.exported)("devicesService")
852
802
  ], DevicesService.prototype, "getDebuggableViews", null);
853
- exports.DevicesService = DevicesService;
854
803
  yok_1.injector.register("devicesService", DevicesService);