@akylas/nativescript-cli 8.7.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 (295) hide show
  1. package/config/test-deps-versions-generated.json +1 -1
  2. package/docs/man_pages/project/configuration/native/native-add-java.md +32 -0
  3. package/docs/man_pages/project/configuration/native/native-add-kotlin.md +34 -0
  4. package/docs/man_pages/project/configuration/native/native-add-objective-c.md +34 -0
  5. package/docs/man_pages/project/configuration/native/native-add-swift.md +32 -0
  6. package/docs/man_pages/project/configuration/native/native-add.md +31 -0
  7. package/docs/man_pages/project/configuration/native/native.md +31 -0
  8. package/lib/.d.ts +2 -0
  9. package/lib/android-tools-info.js +9 -20
  10. package/lib/base-package-manager.js +47 -64
  11. package/lib/bootstrap.js +8 -0
  12. package/lib/bun-package-manager.js +65 -88
  13. package/lib/color.js +2 -2
  14. package/lib/commands/add-platform.js +14 -30
  15. package/lib/commands/apple-login.js +18 -29
  16. package/lib/commands/appstore-list.js +34 -45
  17. package/lib/commands/appstore-upload.js +55 -68
  18. package/lib/commands/build.js +57 -86
  19. package/lib/commands/clean.js +161 -176
  20. package/lib/commands/command-base.js +14 -27
  21. package/lib/commands/config.js +51 -70
  22. package/lib/commands/create-project.js +210 -229
  23. package/lib/commands/debug.js +66 -88
  24. package/lib/commands/deploy.js +28 -44
  25. package/lib/commands/embedding/embed.js +72 -0
  26. package/lib/commands/extensibility/install-extension.js +5 -16
  27. package/lib/commands/extensibility/list-extensions.js +13 -24
  28. package/lib/commands/extensibility/uninstall-extension.js +4 -15
  29. package/lib/commands/fonts.js +30 -41
  30. package/lib/commands/generate-assets.js +13 -28
  31. package/lib/commands/generate-help.js +2 -13
  32. package/lib/commands/generate.js +17 -26
  33. package/lib/commands/info.js +2 -13
  34. package/lib/commands/install.js +34 -49
  35. package/lib/commands/list-platforms.js +14 -25
  36. package/lib/commands/migrate.js +15 -26
  37. package/lib/commands/native-add.js +277 -0
  38. package/lib/commands/platform-clean.js +19 -32
  39. package/lib/commands/plugin/add-plugin.js +12 -25
  40. package/lib/commands/plugin/build-plugin.js +34 -45
  41. package/lib/commands/plugin/create-plugin.js +110 -133
  42. package/lib/commands/plugin/list-plugins.js +22 -33
  43. package/lib/commands/plugin/remove-plugin.js +20 -33
  44. package/lib/commands/plugin/update-plugin.js +20 -33
  45. package/lib/commands/post-install.js +20 -33
  46. package/lib/commands/prepare.js +28 -35
  47. package/lib/commands/preview.js +49 -62
  48. package/lib/commands/remove-platform.js +7 -18
  49. package/lib/commands/resources/resources-update.js +13 -26
  50. package/lib/commands/run.js +55 -76
  51. package/lib/commands/start.js +6 -19
  52. package/lib/commands/test-init.js +123 -134
  53. package/lib/commands/test.js +66 -89
  54. package/lib/commands/typings.js +126 -142
  55. package/lib/commands/update-platform.js +22 -35
  56. package/lib/commands/update.js +30 -43
  57. package/lib/common/child-process.js +53 -72
  58. package/lib/common/codeGeneration/code-entity.js +1 -1
  59. package/lib/common/codeGeneration/code-printer.js +1 -1
  60. package/lib/common/command-params.js +7 -18
  61. package/lib/common/commands/analytics.js +27 -40
  62. package/lib/common/commands/autocompletion.js +39 -56
  63. package/lib/common/commands/device/device-log-stream.js +12 -23
  64. package/lib/common/commands/device/get-file.js +22 -33
  65. package/lib/common/commands/device/list-applications.js +12 -23
  66. package/lib/common/commands/device/list-devices.js +72 -87
  67. package/lib/common/commands/device/list-files.js +23 -34
  68. package/lib/common/commands/device/put-file.js +22 -33
  69. package/lib/common/commands/device/run-application.js +12 -25
  70. package/lib/common/commands/device/stop-application.js +11 -22
  71. package/lib/common/commands/device/uninstall-application.js +6 -17
  72. package/lib/common/commands/generate-messages.js +17 -28
  73. package/lib/common/commands/help.js +20 -33
  74. package/lib/common/commands/package-manager-get.js +6 -17
  75. package/lib/common/commands/package-manager-set.js +9 -20
  76. package/lib/common/commands/post-install.js +2 -13
  77. package/lib/common/commands/preuninstall.js +23 -38
  78. package/lib/common/commands/proxy/proxy-base.js +8 -19
  79. package/lib/common/commands/proxy/proxy-clear.js +4 -15
  80. package/lib/common/commands/proxy/proxy-get.js +3 -14
  81. package/lib/common/commands/proxy/proxy-set.js +87 -100
  82. package/lib/common/constants.js +11 -11
  83. package/lib/common/decorators.js +10 -22
  84. package/lib/common/dispatchers.js +79 -96
  85. package/lib/common/errors.js +89 -104
  86. package/lib/common/file-system.js +106 -127
  87. package/lib/common/header.js +1 -2
  88. package/lib/common/helpers.js +149 -178
  89. package/lib/common/host-info.js +37 -50
  90. package/lib/common/http-client.js +93 -108
  91. package/lib/common/logger/appenders/cli-appender.js +1 -2
  92. package/lib/common/logger/appenders/emit-appender.js +1 -2
  93. package/lib/common/logger/layouts/cli-layout.js +1 -2
  94. package/lib/common/logger/logger.js +1 -1
  95. package/lib/common/mobile/android/android-application-manager.js +121 -142
  96. package/lib/common/mobile/android/android-debug-bridge-result-handler.js +1 -1
  97. package/lib/common/mobile/android/android-debug-bridge.js +87 -112
  98. package/lib/common/mobile/android/android-device-file-system.js +98 -131
  99. package/lib/common/mobile/android/android-device-hash-service.js +50 -75
  100. package/lib/common/mobile/android/android-device.js +74 -91
  101. package/lib/common/mobile/android/android-emulator-services.js +105 -130
  102. package/lib/common/mobile/android/android-log-filter.js +1 -1
  103. package/lib/common/mobile/android/android-virtual-device-service.js +76 -94
  104. package/lib/common/mobile/android/device-android-debug-bridge.js +13 -29
  105. package/lib/common/mobile/android/genymotion/genymotion-service.js +91 -118
  106. package/lib/common/mobile/android/genymotion/virtualbox-service.js +64 -81
  107. package/lib/common/mobile/android/logcat-helper.js +108 -118
  108. package/lib/common/mobile/application-manager-base.js +84 -107
  109. package/lib/common/mobile/device-log-provider-base.js +7 -18
  110. package/lib/common/mobile/emulator-helper.js +1 -0
  111. package/lib/common/mobile/ios/device/ios-application-manager.js +79 -108
  112. package/lib/common/mobile/ios/device/ios-device-file-system.js +78 -105
  113. package/lib/common/mobile/ios/device/ios-device-operations.js +105 -142
  114. package/lib/common/mobile/ios/device/ios-device.js +20 -36
  115. package/lib/common/mobile/ios/ios-device-base.js +58 -81
  116. package/lib/common/mobile/ios/simulator/ios-emulator-services.js +63 -92
  117. package/lib/common/mobile/ios/simulator/ios-sim-resolver.js +1 -1
  118. package/lib/common/mobile/ios/simulator/ios-simulator-application-manager.js +60 -89
  119. package/lib/common/mobile/ios/simulator/ios-simulator-device.js +27 -43
  120. package/lib/common/mobile/ios/simulator/ios-simulator-file-system.js +37 -62
  121. package/lib/common/mobile/ios/simulator/ios-simulator-log-provider.js +24 -35
  122. package/lib/common/mobile/mobile-core/android-device-discovery.js +43 -62
  123. package/lib/common/mobile/mobile-core/android-emulator-discovery.js +21 -32
  124. package/lib/common/mobile/mobile-core/android-process-service.js +143 -182
  125. package/lib/common/mobile/mobile-core/device-discovery.js +2 -13
  126. package/lib/common/mobile/mobile-core/devices-service.js +385 -436
  127. package/lib/common/mobile/mobile-core/ios-device-discovery.js +24 -35
  128. package/lib/common/mobile/mobile-core/ios-simulator-discovery.js +47 -62
  129. package/lib/common/mobile/mobile-helper.js +15 -26
  130. package/lib/common/mobile/wp8/wp8-emulator-services.js +25 -52
  131. package/lib/common/opener.js +2 -2
  132. package/lib/common/plist-parser.js +2 -2
  133. package/lib/common/prompter.js +90 -105
  134. package/lib/common/queue.js +9 -20
  135. package/lib/common/services/auto-completion-service.js +39 -52
  136. package/lib/common/services/cancellation.js +17 -28
  137. package/lib/common/services/commands-service.js +146 -169
  138. package/lib/common/services/help-service.js +132 -157
  139. package/lib/common/services/hooks-service.js +93 -108
  140. package/lib/common/services/ios-notification-service.js +21 -34
  141. package/lib/common/services/json-file-settings-service.js +52 -71
  142. package/lib/common/services/lock-service.js +35 -52
  143. package/lib/common/services/message-contract-generator.js +35 -46
  144. package/lib/common/services/micro-templating-service.js +4 -15
  145. package/lib/common/services/net-service.js +90 -107
  146. package/lib/common/services/project-files-manager.js +10 -23
  147. package/lib/common/services/proxy-service.js +13 -24
  148. package/lib/common/services/qr.js +13 -24
  149. package/lib/common/services/settings-service.js +1 -1
  150. package/lib/common/services/xcode-select-service.js +20 -35
  151. package/lib/common/utils.js +7 -0
  152. package/lib/common/validators/project-name-validator.js +1 -1
  153. package/lib/common/validators/validation-result.js +1 -1
  154. package/lib/common/verify-node-version.js +2 -3
  155. package/lib/common/yok.js +23 -36
  156. package/lib/config.js +7 -58
  157. package/lib/constants.js +24 -24
  158. package/lib/controllers/build-controller.js +82 -99
  159. package/lib/controllers/debug-controller.js +107 -128
  160. package/lib/controllers/deploy-controller.js +17 -22
  161. package/lib/controllers/migrate-controller.js +727 -800
  162. package/lib/controllers/platform-controller.js +72 -83
  163. package/lib/controllers/prepare-controller.js +264 -250
  164. package/lib/controllers/run-controller.js +392 -406
  165. package/lib/controllers/update-controller-base.js +16 -29
  166. package/lib/controllers/update-controller.js +94 -119
  167. package/lib/data/build-data.js +2 -0
  168. package/lib/data/prepare-data.js +5 -1
  169. package/lib/declarations.d.ts +14 -3
  170. package/lib/definitions/android-plugin-migrator.d.ts +1 -0
  171. package/lib/definitions/ios-debugger-port-service.d.ts +1 -1
  172. package/lib/definitions/livesync.d.ts +1 -1
  173. package/lib/definitions/platform.d.ts +1 -0
  174. package/lib/definitions/prepare.d.ts +3 -0
  175. package/lib/definitions/project.d.ts +5 -0
  176. package/lib/detached-processes/cleanup-js-subprocess.js +3 -12
  177. package/lib/detached-processes/cleanup-process.js +16 -25
  178. package/lib/device-path-provider.js +23 -34
  179. package/lib/device-sockets/ios/app-debug-socket-proxy-factory.js +149 -164
  180. package/lib/device-sockets/ios/notification.js +1 -1
  181. package/lib/device-sockets/ios/socket-request-executor.js +24 -39
  182. package/lib/helpers/android-bundle-validator-helper.js +1 -1
  183. package/lib/helpers/deploy-command-helper.js +45 -49
  184. package/lib/helpers/key-command-helper.js +4 -13
  185. package/lib/helpers/livesync-command-helper.js +137 -152
  186. package/lib/helpers/network-connectivity-validator.js +6 -17
  187. package/lib/helpers/options-track-helper.js +6 -17
  188. package/lib/helpers/platform-command-helper.js +102 -114
  189. package/lib/key-commands/index.js +161 -211
  190. package/lib/nativescript-cli.js +5 -14
  191. package/lib/node-package-manager.js +81 -104
  192. package/lib/options.js +12 -14
  193. package/lib/package-installation-manager.js +130 -165
  194. package/lib/package-manager.js +63 -86
  195. package/lib/platform-command-param.js +4 -15
  196. package/lib/pnpm-package-manager.js +59 -78
  197. package/lib/project-data.js +5 -2
  198. package/lib/providers/project-files-provider.js +2 -2
  199. package/lib/services/analytics/analytics-broker-process.js +13 -22
  200. package/lib/services/analytics/analytics-broker.js +17 -30
  201. package/lib/services/analytics/analytics-service.js +161 -198
  202. package/lib/services/analytics/google-analytics-provider.js +41 -56
  203. package/lib/services/analytics-settings-service.js +15 -32
  204. package/lib/services/android/android-bundle-tool-service.js +43 -60
  205. package/lib/services/android/gradle-build-args-service.js +13 -23
  206. package/lib/services/android/gradle-build-service.js +34 -47
  207. package/lib/services/android/gradle-command-service.js +23 -32
  208. package/lib/services/android-device-debug-service.js +90 -117
  209. package/lib/services/android-plugin-build-service.js +233 -247
  210. package/lib/services/android-project-service.js +180 -219
  211. package/lib/services/android-resources-migration-service.js +51 -64
  212. package/lib/services/apple-portal/apple-portal-application-service.js +46 -63
  213. package/lib/services/apple-portal/apple-portal-session-service.js +171 -188
  214. package/lib/services/assets-generation/assets-generation-service.js +100 -113
  215. package/lib/services/build-artifacts-service.js +9 -20
  216. package/lib/services/build-info-file-service.js +20 -35
  217. package/lib/services/cleanup-service.js +47 -76
  218. package/lib/services/cocoapods-service.js +118 -133
  219. package/lib/services/device/device-install-app-service.js +73 -90
  220. package/lib/services/doctor-service.js +99 -118
  221. package/lib/services/extensibility-service.js +81 -100
  222. package/lib/services/files-hash-service.js +28 -44
  223. package/lib/services/hmr-status-service.js +1 -1
  224. package/lib/services/initialize-service.js +37 -50
  225. package/lib/services/ios/export-options-plist-service.js +38 -51
  226. package/lib/services/ios/ios-signing-service.js +161 -180
  227. package/lib/services/ios/spm-service.js +40 -53
  228. package/lib/services/ios/xcodebuild-args-service.js +77 -94
  229. package/lib/services/ios/xcodebuild-command-service.js +14 -25
  230. package/lib/services/ios/xcodebuild-service.js +50 -69
  231. package/lib/services/ios-debugger-port-service.js +23 -36
  232. package/lib/services/ios-device-debug-service.js +75 -102
  233. package/lib/services/ios-entitlements-service.js +31 -42
  234. package/lib/services/ios-extensions-service.js +18 -29
  235. package/lib/services/ios-project-service.js +418 -440
  236. package/lib/services/ios-provision-service.js +108 -129
  237. package/lib/services/ios-watch-app-service.js +21 -32
  238. package/lib/services/ip-service.js +38 -53
  239. package/lib/services/itmstransporter-service.js +129 -152
  240. package/lib/services/livesync/android-device-livesync-service-base.js +31 -48
  241. package/lib/services/livesync/android-device-livesync-service.js +120 -149
  242. package/lib/services/livesync/android-device-livesync-sockets-service.js +123 -155
  243. package/lib/services/livesync/android-livesync-service.js +16 -37
  244. package/lib/services/livesync/android-livesync-tool.js +89 -112
  245. package/lib/services/livesync/device-livesync-service-base.js +15 -28
  246. package/lib/services/livesync/ios-device-livesync-service.js +114 -143
  247. package/lib/services/livesync/ios-livesync-service.js +44 -60
  248. package/lib/services/livesync/platform-livesync-service-base.js +96 -120
  249. package/lib/services/log-parser-service.js +1 -1
  250. package/lib/services/log-source-map-service.js +33 -43
  251. package/lib/services/marking-mode-service.js +15 -28
  252. package/lib/services/npm-config-service.js +1 -1
  253. package/lib/services/pacote-service.js +49 -64
  254. package/lib/services/performance-service.js +1 -1
  255. package/lib/services/platform/add-platform-service.js +53 -69
  256. package/lib/services/platform/platform-validation-service.js +22 -33
  257. package/lib/services/platform/prepare-native-platform-service.js +50 -60
  258. package/lib/services/platform-environment-requirements.js +29 -38
  259. package/lib/services/plugins-service.js +128 -147
  260. package/lib/services/project-backup-service.js +1 -1
  261. package/lib/services/project-changes-service.js +129 -139
  262. package/lib/services/project-cleanup-service.js +64 -77
  263. package/lib/services/project-config-service.js +71 -80
  264. package/lib/services/project-data-service.js +116 -139
  265. package/lib/services/project-name-service.js +28 -43
  266. package/lib/services/project-service.js +84 -103
  267. package/lib/services/project-templates-service.js +52 -67
  268. package/lib/services/start-service.js +41 -59
  269. package/lib/services/temp-service.js +8 -21
  270. package/lib/services/terminal-spinner-service.js +13 -24
  271. package/lib/services/test-execution-service.js +59 -72
  272. package/lib/services/test-initialization-service.js +2 -2
  273. package/lib/services/timeline-profiler-service.js +1 -1
  274. package/lib/services/versions-service.js +119 -138
  275. package/lib/services/webpack/webpack-compiler-service.js +212 -224
  276. package/lib/services/xcconfig-service.js +8 -19
  277. package/lib/services/xcproj-service.js +12 -0
  278. package/lib/sys-info.js +45 -62
  279. package/lib/tools/node-modules/node-modules-builder.js +16 -27
  280. package/lib/yarn-package-manager.js +59 -78
  281. package/lib/yarn2-package-manager.js +60 -79
  282. package/package.json +59 -57
  283. package/vendor/aab-tool/README.txt +1 -1
  284. package/vendor/aab-tool/bundletool.jar +0 -0
  285. package/vendor/gradle-app/app/build.gradle +12 -4
  286. package/vendor/gradle-plugin/build.gradle +12 -4
  287. package/lib/common/resources/platform-tools/android/darwin/NOTICE.txt +0 -3407
  288. package/lib/common/resources/platform-tools/android/darwin/adb +0 -0
  289. package/lib/common/resources/platform-tools/android/linux/NOTICE.txt +0 -4451
  290. package/lib/common/resources/platform-tools/android/linux/adb +0 -0
  291. package/lib/common/resources/platform-tools/android/win32/AdbWinApi.dll +0 -0
  292. package/lib/common/resources/platform-tools/android/win32/AdbWinUsbApi.dll +0 -0
  293. package/lib/common/resources/platform-tools/android/win32/NOTICE.txt +0 -4451
  294. package/lib/common/resources/platform-tools/android/win32/adb.exe +0 -0
  295. 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);