Skip to content

emulate --availableDevices fixed #1815

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 1 commit into from
Jun 8, 2016
Merged
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
25 changes: 23 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
///<reference path="../.d.ts"/>
"use strict";

import * as child_process from "child_process";
import * as path from "path";
import * as shell from "shelljs";
import * as constants from "../constants";
Expand Down Expand Up @@ -482,8 +483,28 @@ export class PlatformService implements IPlatformService {
}

public deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
this.$options.emulator = true;
return this.deployOnDevice(platform, buildConfig);
platform = platform.toLowerCase();

if (this.$options.availableDevices) {
return (() => {
let callback = (error: Error, stdout: Buffer, stderr: Buffer) => {
if (error !== null) {
this.$errors.fail(error);
} else {
this.$logger.info(stdout);
}
};

if (this.$mobileHelper.isiOSPlatform(platform)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole code looks the same.
It seems safer to check outside if this is iOS or Android and exec(command, ...) because the function after that call are same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of branching here you can use something like:

let platformData = this.$platformsData.getPlatformData(platform); 
platformData.platformProjectService.listDevices().wait();

And add the listDevices to the project interface and implement as necessary for the iOS and Android project services.

child_process.exec("instruments -s devices", callback);
} else if (this.$mobileHelper.isAndroidPlatform(platform)) {
child_process.exec("android list avd", callback);
}
}).future<void>()();
} else {
this.$options.emulator = true;
return this.deployOnDevice(platform, buildConfig);
}
}

public validatePlatform(platform: string): void {
Expand Down