diff --git a/docs/man_pages/project/testing/run.md b/docs/man_pages/project/testing/run.md index 7d5172706f..851cf43611 100644 --- a/docs/man_pages/project/testing/run.md +++ b/docs/man_pages/project/testing/run.md @@ -3,19 +3,24 @@ run Usage | Synopsis ---|--- -<% if((isConsole && isMacOS) || isHtml) { %>General | `$ tns run `<% } %><% if(isConsole && (isLinux || isWindows)) { %>General | `$ tns run android`<% } %> +Run on all connected devices | `$ tns run [--release] [--justlaunch]` +Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run --device [--release] [--justlaunch]` -Runs your project on all connected devices or in native emulators for the selected platform.<% if(isMacOS) { %> You must specify the target platform on which you want to run your project.<% } %><% if(isConsole && (isLinux || isWindows)) { %>You must run `$ tns run android`<% } %> The command will prepare, build and deploy the app when necessary. By default listens for changes in your code, synchronizes those changes and refreshes all selected devices. +Runs your project on all connected devices or in native emulators for the selected platform.<% if(isConsole && (isLinux || isWindows)) { %>The command will work with all currently running Android devices and emulators.<% } %> The command will prepare, build and deploy the app when necessary. By default listens for changes in your code, synchronizes those changes and refreshes all selected devices. -<% if((isConsole && isMacOS) || isHtml) { %>### Attributes -`` is the target mobile platform on which you want to run your project. You can set the following target platforms. -* `android` - Runs your project on a connected Android device, in the native emulator. -* `ios` - Runs your project on a connected iOS device or in the iOS Simulator.<% } %> +### Options +* `--justlaunch` - If set, does not print the application output in the console. +* `--release` - If set, produces a release build. Otherwise, produces a debug build. +* `--device` - Specifies a connected device/emulator to start and run the app. + +### Attributes +* `` is the index or `Device Identifier` of the target device as listed by `$ tns device --available-devices` <% if(isHtml) { %> ### Command Limitations -* You can run `$ tns run ios` only on OS X systems. +* The command will work with all connected devices and running emulators on macOS. On Windows and Linux the command will work with Android devices only. +* In case a platform is not specified and there's no running devices and emulators, the command will fail. ### Related Commands @@ -35,4 +40,4 @@ Command | Description [test init](test-init.html) | Configures your project for unit testing with a selected framework. [test android](test-android.html) | Runs the tests in your project on Android devices or native emulators. [test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator. -<% } %> \ No newline at end of file +<% } %> diff --git a/lib/commands/debug.ts b/lib/commands/debug.ts index 5c1ff1b5a7..54f947de7e 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -37,7 +37,7 @@ export class DebugPlatformCommand implements ICommand { const selectedDeviceForDebug = await this.getDeviceForDebug(); - await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo([selectedDeviceForDebug], this.$debugLiveSyncService, this.platform); + await this.$liveSyncCommandHelper.executeLiveSyncOperation([selectedDeviceForDebug], this.$debugLiveSyncService, this.platform); } public async getDeviceForDebug(): Promise { @@ -45,7 +45,7 @@ export class DebugPlatformCommand implements ICommand { this.$errors.fail(DebugCommandErrors.UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR); } - await this.$devicesService.detectCurrentlyAttachedDevices(); + await this.$devicesService.detectCurrentlyAttachedDevices({ platform: this.platform, shouldReturnImmediateResult: false }); if (this.$options.device) { const device = await this.$devicesService.getDevice(this.$options.device); diff --git a/lib/commands/run.ts b/lib/commands/run.ts index bdd9236c47..2f30032475 100644 --- a/lib/commands/run.ts +++ b/lib/commands/run.ts @@ -33,7 +33,7 @@ export class RunCommandBase implements ICommand { this.platform = this.$devicePlatformsConstants.Android; } - const availablePlatforms = this.platform ? [this.platform] : this.$platformsData.availablePlatforms; + const availablePlatforms = this.$liveSyncCommandHelper.getPlatformsForOperation(this.platform); for (let platform of availablePlatforms) { const platformData = this.$platformsData.getPlatformData(platform, this.$projectData); const platformProjectService = platformData.platformProjectService; @@ -59,7 +59,7 @@ export class RunCommandBase implements ICommand { await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform }); let devices = this.$devicesService.getDeviceInstances(); devices = devices.filter(d => !this.platform || d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase()); - await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo(devices, this.$liveSyncService, this.platform); + await this.$liveSyncCommandHelper.executeLiveSyncOperation(devices, this.$liveSyncService, this.platform); } } diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index 571b616525..11dea74d7e 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -256,5 +256,6 @@ interface IDevicePathProvider { } interface ILiveSyncCommandHelper { - getDevicesLiveSyncInfo(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise; + executeLiveSyncOperation(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise; + getPlatformsForOperation(platform: string): string[]; } diff --git a/lib/services/livesync/livesync-command-helper.ts b/lib/services/livesync/livesync-command-helper.ts index 784dcce81d..c896d6d478 100644 --- a/lib/services/livesync/livesync-command-helper.ts +++ b/lib/services/livesync/livesync-command-helper.ts @@ -6,10 +6,20 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { protected $devicesService: Mobile.IDevicesService, private $iosDeviceOperations: IIOSDeviceOperations, private $mobileHelper: Mobile.IMobileHelper, - private $platformsData: IPlatformsData) { + private $platformsData: IPlatformsData, + private $errors: IErrors) { } - public async getDevicesLiveSyncInfo(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise { + public getPlatformsForOperation(platform: string): string[] { + const availablePlatforms = platform ? [platform] : _.values(this.$platformsData.availablePlatforms); + return availablePlatforms; + } + + public async executeLiveSyncOperation(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise { + if (!devices || !devices.length) { + this.$errors.failWithoutHelp("Unable to find applicable devices to execute operation and unable to start emulator when platform is not specified."); + } + await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform }); const workingWithiOSDevices = !platform || this.$mobileHelper.isiOSPlatform(platform); @@ -75,7 +85,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { clean: true, }, this.$options.argv); - const availablePlatforms = platform ? [platform] : _.values(this.$platformsData.availablePlatforms); + const availablePlatforms = this.getPlatformsForOperation(platform); for (const currentPlatform of availablePlatforms) { await this.$platformService.deployPlatform(currentPlatform, this.$options, deployOptions, this.$projectData, this.$options); await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId); diff --git a/test/debug.ts b/test/debug.ts index 995c73c429..4a89464944 100644 --- a/test/debug.ts +++ b/test/debug.ts @@ -69,7 +69,7 @@ function createTestInjector(): IInjector { testInjector.register("prompter", {}); testInjector.registerCommand("debug|android", DebugAndroidCommand); testInjector.register("liveSyncCommandHelper", { - getDevicesLiveSyncInfo: async (): Promise => { + executeLiveSyncOperation: async (): Promise => { return null; } });