microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/ios/iOSPlatform.ts
470lines · modeblame
8a67e140Artem Egorov8 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
| 4 | import * as path from "path"; | |
df8c800dArtem Egorov8 years ago | 5 | import * as semver from "semver"; |
8a67e140Artem Egorov8 years ago | 6 | |
09f6024fHeniker4 years ago | 7 | import * as nls from "vscode-nls"; |
34472878RedMickey5 years ago | 8 | import { ChildProcess } from "../../common/node/childProcess"; |
| 9 | import { CommandExecutor } from "../../common/commandExecutor"; | |
4cd25962JiglioNero4 years ago | 10 | import { MobilePlatformDeps, TargetType } from "../generalPlatform"; |
34472878RedMickey5 years ago | 11 | import { IIOSRunOptions, PlatformType } from "../launchArgs"; |
| 12 | import { OutputVerifier, PatternToFailure } from "../../common/outputVerifier"; | |
| 13 | import { TelemetryHelper } from "../../common/telemetryHelper"; | |
fc602bb6Yuri Skorokhodov7 years ago | 14 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; |
7e74daf7Yuri Skorokhodov6 years ago | 15 | import { AppLauncher } from "../appLauncher"; |
4cd25962JiglioNero4 years ago | 16 | import { GeneralMobilePlatform } from "../generalMobilePlatform"; |
| 17 | import { ErrorHelper } from "../../common/error/errorHelper"; | |
47927908RedMickey4 years ago | 18 | import { ProjectVersionHelper } from "../../common/projectVersionHelper"; |
09f6024fHeniker4 years ago | 19 | import { IDebuggableIOSTarget, IOSTarget, IOSTargetManager } from "./iOSTargetManager"; |
| 20 | import { IOSDebugModeManager } from "./iOSDebugModeManager"; | |
| 21 | import { PlistBuddy } from "./plistBuddy"; | |
| 22 | | |
34472878RedMickey5 years ago | 23 | nls.config({ |
| 24 | messageFormat: nls.MessageFormat.bundle, | |
| 25 | bundleFormat: nls.BundleFormat.standalone, | |
| 26 | })(); | |
d7d405aeYuri Skorokhodov7 years ago | 27 | const localize = nls.loadMessageBundle(); |
8022afdfVladimir Kotikov8 years ago | 28 | |
8a67e140Artem Egorov8 years ago | 29 | export class IOSPlatform extends GeneralMobilePlatform { |
| 30 | public static DEFAULT_IOS_PROJECT_RELATIVE_PATH = "ios"; | |
0a68f8dbArtem Egorov8 years ago | 31 | |
47927908RedMickey4 years ago | 32 | private static readonly NEW_RN_CLI_BEHAVIOUR_VERSION = "0.60.0"; |
| 33 | | |
8a67e140Artem Egorov8 years ago | 34 | private plistBuddy = new PlistBuddy(); |
0db0be15Artem Egorov8 years ago | 35 | private iosProjectRoot: string; |
7daed3fcArtem Egorov8 years ago | 36 | private iosDebugModeManager: IOSDebugModeManager; |
| 37 | | |
db6fd42aRuslan Bikkinin7 years ago | 38 | private defaultConfiguration: string = "Debug"; |
| 39 | private configurationArgumentName: string = "--configuration"; | |
8a67e140Artem Egorov8 years ago | 40 | |
4cd25962JiglioNero4 years ago | 41 | protected target?: IOSTarget; |
| 42 | | |
0a68f8dbArtem Egorov8 years ago | 43 | // We should add the common iOS build/run errors we find to this list |
34472878RedMickey5 years ago | 44 | private static RUN_IOS_FAILURE_PATTERNS: PatternToFailure[] = [ |
| 45 | { | |
| 46 | pattern: "No devices are booted", | |
| 47 | errorCode: InternalErrorCode.IOSSimulatorNotLaunchable, | |
| 48 | }, | |
| 49 | { | |
| 50 | pattern: "FBSOpenApplicationErrorDomain", | |
| 51 | errorCode: InternalErrorCode.IOSSimulatorNotLaunchable, | |
| 52 | }, | |
| 53 | { | |
| 54 | pattern: "ios-deploy", | |
| 55 | errorCode: InternalErrorCode.IOSDeployNotFound, | |
| 56 | }, | |
| 57 | ]; | |
8a67e140Artem Egorov8 years ago | 58 | |
9fbbf669RedMickey4 years ago | 59 | private static readonly RUN_IOS_SUCCESS_PATTERNS = [ |
| 60 | "BUILD SUCCEEDED|success Successfully built the app", | |
| 61 | ]; | |
8a67e140Artem Egorov8 years ago | 62 | |
0a68f8dbArtem Egorov8 years ago | 63 | constructor(protected runOptions: IIOSRunOptions, platformDeps: MobilePlatformDeps = {}) { |
| 64 | super(runOptions, platformDeps); | |
8a67e140Artem Egorov8 years ago | 65 | |
4cd25962JiglioNero4 years ago | 66 | this.targetManager = new IOSTargetManager(); |
db6fd42aRuslan Bikkinin7 years ago | 67 | this.runOptions.configuration = this.getConfiguration(); |
| 68 | | |
34472878RedMickey5 years ago | 69 | if (this.runOptions.iosRelativeProjectPath) { |
| 70 | // Deprecated option | |
| 71 | this.logger.warning( | |
| 72 | localize( | |
| 73 | "iosRelativeProjectPathOptionIsDeprecatedUseRunArgumentsInstead", | |
| 74 | "'iosRelativeProjectPath' option is deprecated. Please use 'runArguments' instead.", | |
| 75 | ), | |
| 76 | ); | |
8a67e140Artem Egorov8 years ago | 77 | } |
| 78 | | |
34472878RedMickey5 years ago | 79 | const iosProjectFolderPath = IOSPlatform.getOptFromRunArgs( |
| 80 | this.runArguments, | |
| 81 | "--project-path", | |
| 82 | false, | |
| 83 | ); | |
| 84 | this.iosProjectRoot = path.join( | |
| 85 | this.projectPath, | |
| 86 | iosProjectFolderPath || | |
| 87 | this.runOptions.iosRelativeProjectPath || | |
| 88 | IOSPlatform.DEFAULT_IOS_PROJECT_RELATIVE_PATH, | |
| 89 | ); | |
116c3cb0Ruslan Bikkinin7 years ago | 90 | const schemeFromArgs = IOSPlatform.getOptFromRunArgs(this.runArguments, "--scheme", false); |
34472878RedMickey5 years ago | 91 | this.iosDebugModeManager = new IOSDebugModeManager( |
| 92 | this.iosProjectRoot, | |
| 93 | this.projectPath, | |
| 94 | schemeFromArgs ? schemeFromArgs : this.runOptions.scheme, | |
| 95 | ); | |
4cd25962JiglioNero4 years ago | 96 | } |
8a67e140Artem Egorov8 years ago | 97 | |
4cd25962JiglioNero4 years ago | 98 | public async getTarget(): Promise<IOSTarget> { |
| 99 | if (!this.target) { | |
| 100 | const targetFromRunArgs = await this.getTargetFromRunArgs(); | |
| 101 | if (targetFromRunArgs) { | |
| 102 | this.target = targetFromRunArgs; | |
| 103 | } else { | |
09f6024fHeniker4 years ago | 104 | const targets = |
| 105 | (await this.targetManager.getTargetList()) as IDebuggableIOSTarget[]; | |
4cd25962JiglioNero4 years ago | 106 | const targetsBySpecifiedType = targets.filter(target => { |
| 107 | switch (this.runOptions.target) { | |
| 108 | case TargetType.Simulator: | |
| 109 | return target.isVirtualTarget; | |
| 110 | case TargetType.Device: | |
| 111 | return !target.isVirtualTarget; | |
| 112 | case undefined: | |
| 113 | case "": | |
| 114 | return true; | |
| 115 | default: | |
| 116 | return ( | |
| 117 | target.id === this.runOptions.target || | |
| 118 | target.name === this.runOptions.target | |
| 119 | ); | |
| 120 | } | |
| 121 | }); | |
| 122 | if (targetsBySpecifiedType.length) { | |
| 123 | this.target = IOSTarget.fromInterface(targetsBySpecifiedType[0]); | |
| 124 | } else if (targets.length) { | |
| 125 | this.logger.warning( | |
| 126 | localize( | |
| 127 | "ThereIsNoTargetWithSpecifiedTargetType", | |
| 128 | "There is no any target with specified target type '{0}'. Continue with any target.", | |
| 129 | this.runOptions.target, | |
| 130 | ), | |
| 131 | ); | |
| 132 | this.target = IOSTarget.fromInterface(targets[0]); | |
| 133 | } else { | |
| 134 | throw ErrorHelper.getInternalError( | |
| 135 | InternalErrorCode.IOSThereIsNoAnyDebuggableTarget, | |
| 136 | ); | |
| 137 | } | |
| 138 | } | |
8022afdfVladimir Kotikov8 years ago | 139 | } |
4cd25962JiglioNero4 years ago | 140 | return this.target; |
| 141 | } | |
0db0be15Artem Egorov8 years ago | 142 | |
4cd25962JiglioNero4 years ago | 143 | public async showDevMenu(appLauncher: AppLauncher): Promise<void> { |
| 144 | const worker = appLauncher.getAppWorker(); | |
| 145 | if (worker) { | |
| 146 | worker.showDevMenuCommand(); | |
8a67e140Artem Egorov8 years ago | 147 | } |
| 148 | } | |
| 149 | | |
4cd25962JiglioNero4 years ago | 150 | public async reloadApp(appLauncher: AppLauncher): Promise<void> { |
| 151 | const worker = appLauncher.getAppWorker(); | |
| 152 | if (worker) { | |
| 153 | worker.reloadAppCommand(); | |
119d7878JiglioNero5 years ago | 154 | } |
| 155 | } | |
| 156 | | |
0d77292aJiglioNero4 years ago | 157 | public async runApp(): Promise<void> { |
e7a2c40dRedMickey4 years ago | 158 | let extProps: any = { |
031832ffArtem Egorov8 years ago | 159 | platform: { |
259c018fYuri Skorokhodov5 years ago | 160 | value: PlatformType.iOS, |
031832ffArtem Egorov8 years ago | 161 | isPii: false, |
| 162 | }, | |
| 163 | }; | |
| 164 | | |
e7a2c40dRedMickey4 years ago | 165 | if (this.runOptions.isDirect) { |
| 166 | extProps.isDirect = { | |
| 167 | value: true, | |
| 168 | isPii: false, | |
| 169 | }; | |
| 170 | this.projectObserver?.updateRNIosHermesProjectState(true); | |
| 171 | } | |
| 172 | | |
34472878RedMickey5 years ago | 173 | extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties( |
| 174 | this.runOptions, | |
| 175 | this.runOptions.reactNativeVersions, | |
| 176 | extProps, | |
| 177 | ); | |
ba953e9fRedMickey6 years ago | 178 | |
0d77292aJiglioNero4 years ago | 179 | await TelemetryHelper.generate("iOSPlatform.runApp", extProps, async () => { |
031832ffArtem Egorov8 years ago | 180 | // Compile, deploy, and launch the app on either a simulator or a device |
34472878RedMickey5 years ago | 181 | const env = GeneralMobilePlatform.getEnvArgument( |
| 182 | process.env, | |
| 183 | this.runOptions.env, | |
| 184 | this.runOptions.envFile, | |
| 185 | ); | |
| 186 | | |
| 187 | if ( | |
| 188 | !semver.valid( | |
| 189 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
09f6024fHeniker4 years ago | 190 | ) /* Custom RN implementations should support this flag*/ || |
34472878RedMickey5 years ago | 191 | semver.gte( |
| 192 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 193 | IOSPlatform.NO_PACKAGER_VERSION, | |
47927908RedMickey4 years ago | 194 | ) || |
| 195 | ProjectVersionHelper.isCanaryVersion( | |
| 196 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
34472878RedMickey5 years ago | 197 | ) |
| 198 | ) { | |
7fa90b3bRedMickey6 years ago | 199 | this.runArguments.push("--no-packager"); |
| 200 | } | |
| 201 | // Since @react-native-community/cli@2.1.0 build output are hidden by default | |
| 202 | // we are using `--verbose` to show it as it contains `BUILD SUCCESSFUL` and other patterns | |
47927908RedMickey4 years ago | 203 | if ( |
| 204 | semver.gte( | |
| 205 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 206 | IOSPlatform.NEW_RN_CLI_BEHAVIOUR_VERSION, | |
| 207 | ) || | |
| 208 | ProjectVersionHelper.isCanaryVersion( | |
| 209 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 210 | ) | |
| 211 | ) { | |
7fa90b3bRedMickey6 years ago | 212 | this.runArguments.push("--verbose"); |
| 213 | } | |
34472878RedMickey5 years ago | 214 | const runIosSpawn = new CommandExecutor( |
4dfb1c4cetatanova5 years ago | 215 | this.runOptions.nodeModulesRoot, |
34472878RedMickey5 years ago | 216 | this.projectPath, |
| 217 | this.logger, | |
| 218 | ).spawnReactCommand("run-ios", this.runArguments, { env }); | |
0d77292aJiglioNero4 years ago | 219 | await new OutputVerifier( |
ce5e88eeYuri Skorokhodov5 years ago | 220 | () => |
34472878RedMickey5 years ago | 221 | this.generateSuccessPatterns( |
| 222 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 223 | ), | |
| 224 | () => Promise.resolve(IOSPlatform.RUN_IOS_FAILURE_PATTERNS), | |
| 225 | PlatformType.iOS, | |
| 226 | ).process(runIosSpawn); | |
80dcd561ConnorQi013 months ago | 227 | |
1a12db81ConnorQi3 months ago | 228 | // Save target info for status indicator |
80dcd561ConnorQi013 months ago | 229 | if (!this.target) { |
1a12db81ConnorQi3 months ago | 230 | const target = await this.getTarget(); |
| 231 | if (target && target.name) { | |
| 232 | this.target = new IOSTarget( | |
| 233 | target.isOnline, | |
| 234 | target.isVirtualTarget, | |
| 235 | target.id, | |
| 236 | target.name, | |
| 237 | target.system, | |
| 238 | ); | |
| 239 | } | |
80dcd561ConnorQi013 months ago | 240 | } |
031832ffArtem Egorov8 years ago | 241 | }); |
8a67e140Artem Egorov8 years ago | 242 | } |
| 243 | | |
0d77292aJiglioNero4 years ago | 244 | public async enableJSDebuggingMode(): Promise<void> { |
8a67e140Artem Egorov8 years ago | 245 | // Configure the app for debugging |
4cd25962JiglioNero4 years ago | 246 | if (!(await this.getTarget()).isVirtualTarget) { |
8a67e140Artem Egorov8 years ago | 247 | // Note that currently we cannot automatically switch the device into debug mode. |
34472878RedMickey5 years ago | 248 | this.logger.info( |
| 249 | "Application is running on a device, please shake device and select 'Debug JS Remotely' to enable debugging.", | |
| 250 | ); | |
0d77292aJiglioNero4 years ago | 251 | return; |
8a67e140Artem Egorov8 years ago | 252 | } |
| 253 | | |
| 254 | // Wait until the configuration file exists, and check to see if debugging is enabled | |
0d77292aJiglioNero4 years ago | 255 | const [debugModeEnabled, bundleId] = await Promise.all<boolean | string>([ |
1c2424f4RedMickey5 years ago | 256 | this.iosDebugModeManager.getAppRemoteDebuggingSetting( |
34472878RedMickey5 years ago | 257 | this.runOptions.configuration, |
| 258 | this.runOptions.productName, | |
| 259 | ), | |
8a67e140Artem Egorov8 years ago | 260 | this.getBundleId(), |
0d77292aJiglioNero4 years ago | 261 | ]); |
| 262 | if (debugModeEnabled) { | |
| 263 | return; | |
| 264 | } | |
| 265 | // Debugging must still be enabled | |
| 266 | // We enable debugging by writing to a plist file that backs a NSUserDefaults object, | |
| 267 | // but that file is written to by the app on occasion. To avoid races, we shut the app | |
| 268 | // down before writing to the file. | |
| 269 | const childProcess = new ChildProcess(); | |
| 270 | const output = await childProcess.execToString("xcrun simctl spawn booted launchctl list"); | |
| 271 | // Try to find an entry that looks like UIKitApplication:com.example.myApp[0x4f37] | |
09f6024fHeniker4 years ago | 272 | const regex = new RegExp(`(\\S+${String(bundleId)}\\S+)`); |
0d77292aJiglioNero4 years ago | 273 | const match = regex.exec(output); |
| 274 | // If we don't find a match, the app must not be running and so we do not need to close it | |
| 275 | if (match) { | |
| 276 | await childProcess.exec(`xcrun simctl spawn booted launchctl stop ${match[1]}`); | |
| 277 | } | |
| 278 | // Write to the settings file while the app is not running to avoid races | |
| 279 | await this.iosDebugModeManager.setAppRemoteDebuggingSetting( | |
09f6024fHeniker4 years ago | 280 | /* enable=*/ true, |
0d77292aJiglioNero4 years ago | 281 | this.runOptions.configuration, |
| 282 | this.runOptions.productName, | |
| 283 | ); | |
| 284 | // Relaunch the app | |
| 285 | return await this.runApp(); | |
8a67e140Artem Egorov8 years ago | 286 | } |
| 287 | | |
0d77292aJiglioNero4 years ago | 288 | public async disableJSDebuggingMode(): Promise<void> { |
4cd25962JiglioNero4 years ago | 289 | if (!(await this.getTarget()).isVirtualTarget) { |
0d77292aJiglioNero4 years ago | 290 | return; |
c73f53cbJiglioNero5 years ago | 291 | } |
1c2424f4RedMickey5 years ago | 292 | return this.iosDebugModeManager.setAppRemoteDebuggingSetting( |
09f6024fHeniker4 years ago | 293 | /* enable=*/ false, |
34472878RedMickey5 years ago | 294 | this.runOptions.configuration, |
| 295 | this.runOptions.productName, | |
| 296 | ); | |
0a68f8dbArtem Egorov8 years ago | 297 | } |
| 298 | | |
ce5e88eeYuri Skorokhodov5 years ago | 299 | public prewarmBundleCache(): Promise<void> { |
259c018fYuri Skorokhodov5 years ago | 300 | return this.packager.prewarmBundleCache(PlatformType.iOS); |
8a67e140Artem Egorov8 years ago | 301 | } |
| 302 | | |
cbc7ac5bArtem Egorov7 years ago | 303 | public getRunArguments(): string[] { |
8a67e140Artem Egorov8 years ago | 304 | let runArguments: string[] = []; |
0db0be15Artem Egorov8 years ago | 305 | |
| 306 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { | |
b57ea017Artem Egorov8 years ago | 307 | runArguments = this.runOptions.runArguments; |
116c3cb0Ruslan Bikkinin7 years ago | 308 | if (this.runOptions.scheme) { |
34472878RedMickey5 years ago | 309 | const schemeFromArgs = IOSPlatform.getOptFromRunArgs( |
| 310 | runArguments, | |
| 311 | "--scheme", | |
| 312 | false, | |
| 313 | ); | |
116c3cb0Ruslan Bikkinin7 years ago | 314 | if (!schemeFromArgs) { |
| 315 | runArguments.push("--scheme", this.runOptions.scheme); | |
| 316 | } else { | |
34472878RedMickey5 years ago | 317 | this.logger.warning( |
| 318 | localize( | |
| 319 | "iosSchemeParameterAlreadySetInRunArguments", | |
| 320 | "'--scheme' is set as 'runArguments' configuration parameter value, 'scheme' configuration parameter value will be omitted", | |
| 321 | ), | |
| 322 | ); | |
116c3cb0Ruslan Bikkinin7 years ago | 323 | } |
| 324 | } | |
b57ea017Artem Egorov8 years ago | 325 | } else { |
| 326 | if (this.runOptions.target) { | |
de838bbfJiglioNero6 years ago | 327 | runArguments.push(...this.handleTargetArg(this.runOptions.target)); |
b57ea017Artem Egorov8 years ago | 328 | } |
8abbd163Artem Egorov8 years ago | 329 | |
b57ea017Artem Egorov8 years ago | 330 | if (this.runOptions.iosRelativeProjectPath) { |
| 331 | runArguments.push("--project-path", this.runOptions.iosRelativeProjectPath); | |
8022afdfVladimir Kotikov8 years ago | 332 | } |
8a67e140Artem Egorov8 years ago | 333 | |
b57ea017Artem Egorov8 years ago | 334 | // provide any defined scheme |
| 335 | if (this.runOptions.scheme) { | |
| 336 | runArguments.push("--scheme", this.runOptions.scheme); | |
| 337 | } | |
8a67e140Artem Egorov8 years ago | 338 | } |
| 339 | | |
| 340 | return runArguments; | |
| 341 | } | |
| 342 | | |
4cd25962JiglioNero4 years ago | 343 | public async getTargetFromRunArgs(): Promise<IOSTarget | undefined> { |
| 344 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { | |
c76b733bJiglioNero4 years ago | 345 | const targets = (await this.targetManager.getTargetList()) as IDebuggableIOSTarget[]; |
| 346 | | |
4cd25962JiglioNero4 years ago | 347 | const udid = GeneralMobilePlatform.getOptFromRunArgs( |
| 348 | this.runOptions.runArguments, | |
| 349 | "--udid", | |
| 350 | ); | |
| 351 | if (udid) { | |
| 352 | const target = targets.find(target => target.id === udid); | |
| 353 | if (target) { | |
| 354 | return IOSTarget.fromInterface(target); | |
| 355 | } | |
09f6024fHeniker4 years ago | 356 | this.logger.warning( |
| 357 | localize( | |
| 358 | "ThereIsNoIosTargetWithSuchUdid", | |
| 359 | "There is no iOS target with such UDID: {0}", | |
| 360 | udid, | |
| 361 | ), | |
| 362 | ); | |
4cd25962JiglioNero4 years ago | 363 | } |
| 364 | | |
| 365 | const device = GeneralMobilePlatform.getOptFromRunArgs( | |
| 366 | this.runOptions.runArguments, | |
| 367 | "--device", | |
| 368 | ); | |
| 369 | if (device) { | |
| 370 | const target = targets.find( | |
c76b733bJiglioNero4 years ago | 371 | target => !target.isVirtualTarget && target.name === device, |
4cd25962JiglioNero4 years ago | 372 | ); |
| 373 | if (target) { | |
| 374 | return IOSTarget.fromInterface(target); | |
| 375 | } | |
09f6024fHeniker4 years ago | 376 | this.logger.warning( |
| 377 | localize( | |
| 378 | "ThereIsNoIosDeviceWithSuchName", | |
| 379 | "There is no iOS device with such name: {0}", | |
| 380 | device, | |
| 381 | ), | |
| 382 | ); | |
4cd25962JiglioNero4 years ago | 383 | } |
| 384 | | |
| 385 | const simulator = GeneralMobilePlatform.getOptFromRunArgs( | |
| 386 | this.runOptions.runArguments, | |
| 387 | "--simulator", | |
| 388 | ); | |
| 389 | if (simulator) { | |
| 390 | const target = targets.find( | |
c76b733bJiglioNero4 years ago | 391 | target => target.isVirtualTarget && target.name === simulator, |
4cd25962JiglioNero4 years ago | 392 | ); |
| 393 | if (target) { | |
| 394 | return IOSTarget.fromInterface(target); | |
| 395 | } | |
09f6024fHeniker4 years ago | 396 | this.logger.warning( |
| 397 | localize( | |
| 398 | "ThereIsNoIosSimulatorWithSuchName", | |
| 399 | "There is no iOS simulator with such name: {0}", | |
| 400 | simulator, | |
| 401 | ), | |
| 402 | ); | |
4cd25962JiglioNero4 years ago | 403 | } |
| 404 | } | |
| 405 | | |
| 406 | return undefined; | |
| 407 | } | |
| 408 | | |
de838bbfJiglioNero6 years ago | 409 | private handleTargetArg(target: string): string[] { |
09f6024fHeniker4 years ago | 410 | return target === TargetType.Device || target === TargetType.Simulator |
| 411 | ? [`--${target}`] | |
| 412 | : ["--udid", target]; | |
de838bbfJiglioNero6 years ago | 413 | } |
| 414 | | |
0d77292aJiglioNero4 years ago | 415 | private async generateSuccessPatterns(version: string): Promise<string[]> { |
3021756bYuri Skorokhodov6 years ago | 416 | // Clone RUN_IOS_SUCCESS_PATTERNS to avoid its runtime mutation |
09f6024fHeniker4 years ago | 417 | const successPatterns = [...IOSPlatform.RUN_IOS_SUCCESS_PATTERNS]; |
4cd25962JiglioNero4 years ago | 418 | if (!(await this.getTarget()).isVirtualTarget) { |
47927908RedMickey4 years ago | 419 | if ( |
| 420 | semver.gte(version, IOSPlatform.NEW_RN_CLI_BEHAVIOUR_VERSION) || | |
| 421 | ProjectVersionHelper.isCanaryVersion(version) | |
| 422 | ) { | |
3021756bYuri Skorokhodov6 years ago | 423 | successPatterns.push("success Installed the app on the device"); |
| 424 | } else { | |
| 425 | successPatterns.push("INSTALLATION SUCCEEDED"); | |
| 426 | } | |
0d77292aJiglioNero4 years ago | 427 | return successPatterns; |
09f6024fHeniker4 years ago | 428 | } |
| 429 | const bundleId = await this.getBundleId(); | |
47927908RedMickey4 years ago | 430 | if ( |
| 431 | semver.gte(version, IOSPlatform.NEW_RN_CLI_BEHAVIOUR_VERSION) || | |
| 432 | ProjectVersionHelper.isCanaryVersion(version) | |
| 433 | ) { | |
cf6a88fclexie0112 years ago | 434 | successPatterns.push(`Launching "${bundleId}"\nsuccess Successfully launched the app`); |
3021756bYuri Skorokhodov6 years ago | 435 | } else { |
09f6024fHeniker4 years ago | 436 | successPatterns.push(`Launching ${bundleId}\n${bundleId}: `); |
3021756bYuri Skorokhodov6 years ago | 437 | } |
09f6024fHeniker4 years ago | 438 | return successPatterns; |
8a67e140Artem Egorov8 years ago | 439 | } |
| 440 | | |
db6fd42aRuslan Bikkinin7 years ago | 441 | private getConfiguration(): string { |
34472878RedMickey5 years ago | 442 | return ( |
| 443 | IOSPlatform.getOptFromRunArgs(this.runArguments, this.configurationArgumentName) || | |
| 444 | this.defaultConfiguration | |
| 445 | ); | |
db6fd42aRuslan Bikkinin7 years ago | 446 | } |
| 447 | | |
ce5e88eeYuri Skorokhodov5 years ago | 448 | private getBundleId(): Promise<string> { |
116c3cb0Ruslan Bikkinin7 years ago | 449 | let scheme = this.runOptions.scheme; |
| 450 | if (!scheme) { | |
34472878RedMickey5 years ago | 451 | const schemeFromArgs = IOSPlatform.getOptFromRunArgs( |
| 452 | this.runArguments, | |
| 453 | "--scheme", | |
| 454 | false, | |
| 455 | ); | |
116c3cb0Ruslan Bikkinin7 years ago | 456 | if (schemeFromArgs) { |
| 457 | scheme = schemeFromArgs; | |
| 458 | } | |
| 459 | } | |
34472878RedMickey5 years ago | 460 | return this.plistBuddy.getBundleId( |
| 461 | this.iosProjectRoot, | |
| 462 | this.projectPath, | |
1c2424f4RedMickey5 years ago | 463 | PlatformType.iOS, |
34472878RedMickey5 years ago | 464 | true, |
| 465 | this.runOptions.configuration, | |
| 466 | this.runOptions.productName, | |
| 467 | scheme, | |
| 468 | ); | |
8a67e140Artem Egorov8 years ago | 469 | } |
| 470 | } |