Skip to content

Commit e5f5a54

Browse files
KristianDDrosen-vladimirov
authored andcommitted
Fix run without platform on ios. (#2982)
* Fix run without platform on ios. * Make `tns run` without platform working Introduce new method in livesync-command-helper to get platforms on which to execute action. Rename a method in the helper as its purpose is to execute livesync, not to get params for livesync operation. Pass correct args to detectCurrentlyAttachedDevices in debug command. Make `tns run` to fail in case there's no running emulators and no devices attached as we are unable to determine for which platform to stat emulator.
1 parent 54d1bcf commit e5f5a54

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

docs/man_pages/project/testing/run.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ run
33

44
Usage | Synopsis
55
---|---
6-
<% if((isConsole && isMacOS) || isHtml) { %>General | `$ tns run <Platform>`<% } %><% if(isConsole && (isLinux || isWindows)) { %>General | `$ tns run android`<% } %>
6+
Run on all connected devices | `$ tns run [--release] [--justlaunch]`
7+
Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run --device <Device ID> [--release] [--justlaunch]`
78

8-
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.
9+
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.
910

10-
<% if((isConsole && isMacOS) || isHtml) { %>### Attributes
11-
`<Platform>` is the target mobile platform on which you want to run your project. You can set the following target platforms.
12-
* `android` - Runs your project on a connected Android device, in the native emulator.
13-
* `ios` - Runs your project on a connected iOS device or in the iOS Simulator.<% } %>
11+
### Options
12+
* `--justlaunch` - If set, does not print the application output in the console.
13+
* `--release` - If set, produces a release build. Otherwise, produces a debug build.
14+
* `--device` - Specifies a connected device/emulator to start and run the app.
15+
16+
### Attributes
17+
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns device <Platform> --available-devices`
1418

1519
<% if(isHtml) { %>
1620
### Command Limitations
1721

18-
* You can run `$ tns run ios` only on OS X systems.
22+
* 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.
23+
* In case a platform is not specified and there's no running devices and emulators, the command will fail.
1924

2025
### Related Commands
2126

@@ -35,4 +40,4 @@ Command | Description
3540
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
3641
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
3742
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
38-
<% } %>
43+
<% } %>

lib/commands/debug.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ export class DebugPlatformCommand implements ICommand {
3737

3838
const selectedDeviceForDebug = await this.getDeviceForDebug();
3939

40-
await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo([selectedDeviceForDebug], this.$debugLiveSyncService, this.platform);
40+
await this.$liveSyncCommandHelper.executeLiveSyncOperation([selectedDeviceForDebug], this.$debugLiveSyncService, this.platform);
4141
}
4242

4343
public async getDeviceForDebug(): Promise<Mobile.IDevice> {
4444
if (this.$options.forDevice && this.$options.emulator) {
4545
this.$errors.fail(DebugCommandErrors.UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR);
4646
}
4747

48-
await this.$devicesService.detectCurrentlyAttachedDevices();
48+
await this.$devicesService.detectCurrentlyAttachedDevices({ platform: this.platform, shouldReturnImmediateResult: false });
4949

5050
if (this.$options.device) {
5151
const device = await this.$devicesService.getDevice(this.$options.device);

lib/commands/run.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class RunCommandBase implements ICommand {
3333
this.platform = this.$devicePlatformsConstants.Android;
3434
}
3535

36-
const availablePlatforms = this.platform ? [this.platform] : this.$platformsData.availablePlatforms;
36+
const availablePlatforms = this.$liveSyncCommandHelper.getPlatformsForOperation(this.platform);
3737
for (let platform of availablePlatforms) {
3838
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
3939
const platformProjectService = platformData.platformProjectService;
@@ -59,7 +59,7 @@ export class RunCommandBase implements ICommand {
5959
await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform });
6060
let devices = this.$devicesService.getDeviceInstances();
6161
devices = devices.filter(d => !this.platform || d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase());
62-
await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo(devices, this.$liveSyncService, this.platform);
62+
await this.$liveSyncCommandHelper.executeLiveSyncOperation(devices, this.$liveSyncService, this.platform);
6363
}
6464
}
6565

lib/definitions/livesync.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,6 @@ interface IDevicePathProvider {
256256
}
257257

258258
interface ILiveSyncCommandHelper {
259-
getDevicesLiveSyncInfo(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void>;
259+
executeLiveSyncOperation(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void>;
260+
getPlatformsForOperation(platform: string): string[];
260261
}

lib/services/livesync/livesync-command-helper.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
66
protected $devicesService: Mobile.IDevicesService,
77
private $iosDeviceOperations: IIOSDeviceOperations,
88
private $mobileHelper: Mobile.IMobileHelper,
9-
private $platformsData: IPlatformsData) {
9+
private $platformsData: IPlatformsData,
10+
private $errors: IErrors) {
1011
}
1112

12-
public async getDevicesLiveSyncInfo(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void> {
13+
public getPlatformsForOperation(platform: string): string[] {
14+
const availablePlatforms = platform ? [platform] : _.values<string>(this.$platformsData.availablePlatforms);
15+
return availablePlatforms;
16+
}
17+
18+
public async executeLiveSyncOperation(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void> {
19+
if (!devices || !devices.length) {
20+
this.$errors.failWithoutHelp("Unable to find applicable devices to execute operation and unable to start emulator when platform is not specified.");
21+
}
22+
1323
await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform });
1424

1525
const workingWithiOSDevices = !platform || this.$mobileHelper.isiOSPlatform(platform);
@@ -75,7 +85,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
7585
clean: true,
7686
}, this.$options.argv);
7787

78-
const availablePlatforms = platform ? [platform] : _.values<string>(this.$platformsData.availablePlatforms);
88+
const availablePlatforms = this.getPlatformsForOperation(platform);
7989
for (const currentPlatform of availablePlatforms) {
8090
await this.$platformService.deployPlatform(currentPlatform, this.$options, deployOptions, this.$projectData, this.$options);
8191
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId);

test/debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function createTestInjector(): IInjector {
6969
testInjector.register("prompter", {});
7070
testInjector.registerCommand("debug|android", DebugAndroidCommand);
7171
testInjector.register("liveSyncCommandHelper", {
72-
getDevicesLiveSyncInfo: async (): Promise<void> => {
72+
executeLiveSyncOperation: async (): Promise<void> => {
7373
return null;
7474
}
7575
});

0 commit comments

Comments
 (0)