Skip to content

Fix run without platform on ios. #2982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions docs/man_pages/project/testing/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ run

Usage | Synopsis
---|---
<% if((isConsole && isMacOS) || isHtml) { %>General | `$ tns run <Platform>`<% } %><% 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 <Device ID> [--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
`<Platform>` 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
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns device <Platform> --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

Expand All @@ -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.
<% } %>
<% } %>
4 changes: 2 additions & 2 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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<Mobile.IDevice> {
if (this.$options.forDevice && this.$options.emulator) {
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);
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,6 @@ interface IDevicePathProvider {
}

interface ILiveSyncCommandHelper {
getDevicesLiveSyncInfo(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void>;
executeLiveSyncOperation(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void>;
getPlatformsForOperation(platform: string): string[];
}
16 changes: 13 additions & 3 deletions lib/services/livesync/livesync-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
public getPlatformsForOperation(platform: string): string[] {
const availablePlatforms = platform ? [platform] : _.values<string>(this.$platformsData.availablePlatforms);
return availablePlatforms;
}

public async executeLiveSyncOperation(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void> {
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);
Expand Down Expand Up @@ -75,7 +85,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
clean: true,
}, this.$options.argv);

const availablePlatforms = platform ? [platform] : _.values<string>(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);
Expand Down
2 changes: 1 addition & 1 deletion test/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function createTestInjector(): IInjector {
testInjector.register("prompter", {});
testInjector.registerCommand("debug|android", DebugAndroidCommand);
testInjector.register("liveSyncCommandHelper", {
getDevicesLiveSyncInfo: async (): Promise<void> => {
executeLiveSyncOperation: async (): Promise<void> => {
return null;
}
});
Expand Down