|
1 | 1 | ///<reference path="../.d.ts"/>
|
2 | 2 | "use strict";
|
3 | 3 |
|
4 |
| -import * as child_process from "child_process"; |
5 | 4 | import * as path from "path";
|
6 | 5 | import * as shell from "shelljs";
|
7 | 6 | import * as constants from "../constants";
|
@@ -35,7 +34,8 @@ export class PlatformService implements IPlatformService {
|
35 | 34 | private $xmlValidator: IXmlValidator,
|
36 | 35 | private $npm: INodePackageManager,
|
37 | 36 | private $sysInfo: ISysInfo,
|
38 |
| - private $staticConfig: Config.IStaticConfig) { } |
| 37 | + private $staticConfig: Config.IStaticConfig, |
| 38 | + private $childProcess: IChildProcess) { } |
39 | 39 |
|
40 | 40 | public addPlatforms(platforms: string[]): IFuture<void> {
|
41 | 41 | return (() => {
|
@@ -485,20 +485,39 @@ export class PlatformService implements IPlatformService {
|
485 | 485 | public deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
|
486 | 486 | platform = platform.toLowerCase();
|
487 | 487 |
|
488 |
| - if (this.$options.availableDevices) { |
| 488 | + if (this.$options.avd) { |
| 489 | + this.$logger.warn(`Option --avd is no longer supported. Please use --device isntead!`); |
| 490 | + } |
| 491 | + |
| 492 | + if (this.$options.availableDevices || this.$options.device || this.$options.avd) { |
489 | 493 | return (() => {
|
490 |
| - let callback = (error: Error, stdout: Buffer, stderr: Buffer) => { |
491 |
| - if (error !== null) { |
492 |
| - this.$errors.fail(error); |
493 |
| - } else { |
494 |
| - this.$logger.info(stdout); |
495 |
| - } |
496 |
| - }; |
| 494 | + let devices: string; |
497 | 495 |
|
498 | 496 | if (this.$mobileHelper.isiOSPlatform(platform)) {
|
499 |
| - child_process.exec("instruments -s devices", callback); |
| 497 | + devices = this.$childProcess.exec("instruments -s devices").wait(); |
500 | 498 | } else if (this.$mobileHelper.isAndroidPlatform(platform)) {
|
501 |
| - child_process.exec("android list avd", callback); |
| 499 | + let androidPath = path.join(process.env.ANDROID_HOME, "tools", "android"); |
| 500 | + devices = this.$childProcess.exec(`${androidPath} list avd`).wait(); |
| 501 | + } |
| 502 | + |
| 503 | + if(this.$options.availableDevices) { |
| 504 | + this.$logger.info(devices); |
| 505 | + } |
| 506 | + |
| 507 | + if(this.$options.device || this.$options.avd) { |
| 508 | + let deviceName = this.$options.device || this.$options.avd; |
| 509 | + |
| 510 | + if(devices.indexOf(deviceName) !== -1) { |
| 511 | + let packageFile: string, logFilePath: string; |
| 512 | + let platformData = this.$platformsData.getPlatformData(platform); |
| 513 | + let emulatorServices = platformData.emulatorServices; |
| 514 | + |
| 515 | + emulatorServices.checkAvailability().wait(); |
| 516 | + emulatorServices.checkDependencies().wait(); |
| 517 | + emulatorServices.runApplicationOnEmulator(packageFile, { stderrFilePath: logFilePath, stdoutFilePath: logFilePath, appId: this.$projectData.projectId }).wait(); |
| 518 | + } else { |
| 519 | + this.$errors.fail(`Cannot find device with name: ${this.$options.device}.`); |
| 520 | + } |
502 | 521 | }
|
503 | 522 | }).future<void>()();
|
504 | 523 | } else {
|
|
0 commit comments