diff --git a/bin/nativescript.js b/bin/nativescript.js new file mode 100644 index 0000000000..6d5f43ff3e --- /dev/null +++ b/bin/nativescript.js @@ -0,0 +1,4 @@ +#!/usr/bin/env node + +"use strict"; +require("../lib/nativescript-cli.js"); diff --git a/lib/commands/appstore-upload.ts b/lib/commands/appstore-upload.ts index 69d9c73e42..079b6b7448 100644 --- a/lib/commands/appstore-upload.ts +++ b/lib/commands/appstore-upload.ts @@ -65,7 +65,7 @@ export class PublishIOS implements ICommand { }; this.$logger.info("Building .ipa with the selected mobile provision and/or certificate."); // This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here. - this.$platformService.prepareAndBuild(platform, iOSBuildConfig, true).wait(); + this.$platformService.buildPlatform(platform, iOSBuildConfig, true).wait(); ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice }); } else { this.$logger.info("No .ipa, mobile provision or certificate set. Perfect! Now we'll build .xcarchive and let Xcode pick the distribution certificate and provisioning profile for you when exporting .ipa for AppStore submission."); diff --git a/lib/commands/build.ts b/lib/commands/build.ts index 79230dc98a..93923fe195 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -2,11 +2,10 @@ export class BuildCommandBase { constructor(protected $options: IOptions, private $platformService: IPlatformService) { } - executeCore(args: string[], buildConfig?: IBuildConfig): IFuture { + executeCore(args: string[]): IFuture { return (() => { let platform = args[0].toLowerCase(); - this.$platformService.preparePlatform(platform, true).wait(); - this.$platformService.buildPlatform(platform, buildConfig).wait(); + this.$platformService.buildPlatform(platform, null, true).wait(); if(this.$options.copyTo) { this.$platformService.copyLastOutput(platform, this.$options.copyTo, {isForDevice: this.$options.forDevice}).wait(); } diff --git a/lib/commands/deploy.ts b/lib/commands/deploy.ts index 1599d3b5d6..1681771df8 100644 --- a/lib/commands/deploy.ts +++ b/lib/commands/deploy.ts @@ -6,7 +6,7 @@ export class DeployOnDeviceCommand implements ICommand { private $mobileHelper: Mobile.IMobileHelper) { } execute(args: string[]): IFuture { - return this.$platformService.deployOnDevice(args[0]); + return this.$platformService.deployPlatform(args[0]); } public canExecute(args: string[]): IFuture { diff --git a/lib/commands/emulate.ts b/lib/commands/emulate.ts index 490cf8f992..a9b4b55a3f 100644 --- a/lib/commands/emulate.ts +++ b/lib/commands/emulate.ts @@ -2,7 +2,7 @@ export class EmulateCommandBase { constructor(private $platformService: IPlatformService) { } executeCore(args: string[]): IFuture { - return this.$platformService.deployOnEmulator(args[0]); + return this.$platformService.emulatePlatform(args[0]); } } diff --git a/lib/commands/run.ts b/lib/commands/run.ts index 3da8d4016f..dfdd8a12a5 100644 --- a/lib/commands/run.ts +++ b/lib/commands/run.ts @@ -3,11 +3,12 @@ export class RunCommandBase { private $usbLiveSyncService: ILiveSyncService, protected $options: IOptions) { } - public executeCore(args: string[], buildConfig?: IBuildConfig): IFuture { + public executeCore(args: string[]): IFuture { if (this.$options.watch) { + this.$platformService.deployPlatform(args[0]).wait(); return this.$usbLiveSyncService.liveSync(args[0]); } else { - return this.$platformService.runPlatform(args[0], buildConfig); + return this.$platformService.runPlatform(args[0]); } } } diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index 5d9fda2795..58364b3fb4 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -5,15 +5,12 @@ interface IPlatformService { getPreparedPlatforms(): IFuture; removePlatforms(platforms: string[]): IFuture; updatePlatforms(platforms: string[]): IFuture; - runPlatform(platform: string, buildConfig?: IBuildConfig): IFuture; preparePlatform(platform: string, force?: boolean, skipModulesAndResources?: boolean): IFuture; + buildPlatform(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture; + deployPlatform(platform: string): IFuture; + runPlatform(platform: string): IFuture; + emulatePlatform(platform: string): IFuture; cleanDestinationApp(platform: string): IFuture; - buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture; - buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture; - installOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture; - deployOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture; - startOnDevice(platform: string): IFuture; - deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture; validatePlatformInstalled(platform: string): void; validatePlatform(platform: string): void; @@ -22,8 +19,6 @@ interface IPlatformService { copyLastOutput(platform: string, targetPath: string, settings: {isForDevice: boolean}): IFuture; lastOutputPath(platform: string, settings: { isForDevice: boolean }): string; ensurePlatformInstalled(platform: string): IFuture; - - prepareAndBuild(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture; } interface IPlatformData { diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index e53b8a8182..28c0679972 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -68,7 +68,6 @@ interface IPlatformProjectService { interpolateConfigurationFile(configurationFilePath?: string): IFuture; afterCreateProject(projectRoot: string): IFuture; buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture; - buildForDeploy(projectRoot: string, buildConfig?: IBuildConfig): IFuture; prepareProject(): IFuture; prepareAppResources(appResourcesDirectoryPath: string): IFuture; isPlatformPrepared(projectRoot: string): IFuture; diff --git a/lib/providers/livesync-provider.ts b/lib/providers/livesync-provider.ts index 797cb0fb82..9e26829f42 100644 --- a/lib/providers/livesync-provider.ts +++ b/lib/providers/livesync-provider.ts @@ -57,7 +57,7 @@ export class LiveSyncProvider implements ILiveSyncProvider { public buildForDevice(device: Mobile.IDevice): IFuture { return (() => { - this.$platformService.buildForDeploy(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait(); + this.$platformService.buildPlatform(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait(); let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform); if (device.isEmulator) { return this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait().packageName; diff --git a/lib/services/android-debug-service.ts b/lib/services/android-debug-service.ts index 0c8c5fbc83..f125f89535 100644 --- a/lib/services/android-debug-service.ts +++ b/lib/services/android-debug-service.ts @@ -42,7 +42,7 @@ class AndroidDebugService implements IDebugService { private debugOnEmulator(): IFuture { return (() => { - this.$platformService.deployOnEmulator(this.platform).wait(); + this.$platformService.deployPlatform(this.platform).wait(); // Assure we've detected the emulator as device // For example in case deployOnEmulator had stated new emulator instance // we need some time to detect it. Let's force detection. @@ -111,7 +111,7 @@ class AndroidDebugService implements IDebugService { let cachedDeviceOption = this.$options.forDevice; this.$options.forDevice = true; if (this.$options.rebuild) { - this.$platformService.prepareAndBuild(this.platform).wait(); + this.$platformService.buildPlatform(this.platform).wait(); } this.$options.forDevice = !!cachedDeviceOption; diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 090fec9e16..371948179d 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -291,10 +291,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject return buildOptions; } - public buildForDeploy(projectRoot: string, buildConfig?: IBuildConfig): IFuture { - return this.buildProject(projectRoot, buildConfig); - } - public isPlatformPrepared(projectRoot: string): IFuture { return this.$fs.exists(path.join(this.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME)); } diff --git a/lib/services/ios-debug-service.ts b/lib/services/ios-debug-service.ts index 1698d51ba4..2e45ce13eb 100644 --- a/lib/services/ios-debug-service.ts +++ b/lib/services/ios-debug-service.ts @@ -106,7 +106,7 @@ class IOSDebugService implements IDebugService { return (() => { let platformData = this.$platformsData.getPlatformData(this.platform); if (this.$options.rebuild) { - this.$platformService.prepareAndBuild(this.platform).wait(); + this.$platformService.buildPlatform(this.platform).wait(); } let emulatorPackage = this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait(); @@ -159,9 +159,9 @@ class IOSDebugService implements IDebugService { // we intentionally do not wait on this here, because if we did, we'd miss the AppLaunching notification let action: IFuture; if (this.$config.debugLivesync) { - action = this.$platformService.startOnDevice(this.platform); + action = this.$platformService.runPlatform(this.platform); } else { - action = this.$platformService.deployOnDevice(this.platform); + action = this.$platformService.deployPlatform(this.platform); } this.debugBrkCore(device, shouldBreak).wait(); action.wait(); diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 38da9f2230..fa1cb53293 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -244,7 +244,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ "build", 'SHARED_PRECOMPS_DIR=' + path.join(projectRoot, 'build', 'sharedpch') ]; - basicArgs = basicArgs.concat(this.xcbuildProjectArgs(projectRoot)); // Starting from tns-ios 1.4 the xcconfig file is referenced in the project template @@ -253,37 +252,58 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ basicArgs.push("-xcconfig", path.join(projectRoot, this.$projectData.projectName, "build.xcconfig")); } - let args: string[] = []; let buildForDevice = this.$options.forDevice || (buildConfig && buildConfig.buildForDevice); if (buildForDevice) { - let defaultArchitectures = [ - 'ARCHS=armv7 arm64', - 'VALID_ARCHS=armv7 arm64' - ]; - - args = basicArgs.concat([ - "-sdk", "iphoneos", - "CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "device") - ]); + this.buildForDevice(projectRoot, basicArgs, buildConfig).wait(); + } else { + this.buildForSimulator(projectRoot, basicArgs, buildConfig).wait(); + } + }).future()(); + } - args = args.concat((buildConfig && buildConfig.architectures) || defaultArchitectures); + private buildForDevice(projectRoot: string, args: string[], buildConfig?: IiOSBuildConfig): IFuture { + return (() => { + let defaultArchitectures = [ + 'ARCHS=armv7 arm64', + 'VALID_ARCHS=armv7 arm64' + ]; - let xcodeBuildVersion = this.getXcodeVersion(); - if (helpers.versionCompare(xcodeBuildVersion, "8.0") >= 0) { - let teamId = this.getDevelopmentTeam(); - if (teamId) { - args = args.concat("DEVELOPMENT_TEAM=" + teamId); + // build only for device specific architecture + if (!this.$options.release && !(buildConfig && buildConfig.architectures)) { + this.$devicesService.initialize({ platform: this.$devicePlatformsConstants.iOS.toLowerCase(), deviceId: this.$options.device }).wait(); + let instances = this.$devicesService.getDeviceInstances(); + let devicesArchitectures = _(instances) + .filter(d => this.$mobileHelper.isiOSPlatform(d.deviceInfo.platform) && d.deviceInfo.activeArchitecture) + .map(d => d.deviceInfo.activeArchitecture) + .uniq() + .value(); + if (devicesArchitectures.length > 0) { + let architectures = [ + `ARCHS=${devicesArchitectures.join(" ")}`, + `VALID_ARCHS=${devicesArchitectures.join(" ")}` + ]; + if (devicesArchitectures.length > 1) { + architectures.push('ONLY_ACTIVE_ARCH=NO'); + } + if (!buildConfig) { + buildConfig = {}; } + buildConfig.architectures = architectures; + } + } + args = args.concat((buildConfig && buildConfig.architectures) || defaultArchitectures); + + args = args.concat([ + "-sdk", "iphoneos", + "CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "device") + ]); + + let xcodeBuildVersion = this.getXcodeVersion(); + if (helpers.versionCompare(xcodeBuildVersion, "8.0") >= 0) { + let teamId = this.getDevelopmentTeam(); + if (teamId) { + args = args.concat("DEVELOPMENT_TEAM=" + teamId); } - } else { - args = basicArgs.concat([ - "-sdk", "iphonesimulator", - "ARCHS=i386 x86_64", - "VALID_ARCHS=i386 x86_64", - "ONLY_ACTIVE_ARCH=NO", - "CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "emulator"), - "CODE_SIGN_IDENTITY=" - ]); } if (buildConfig && buildConfig.codeSignIdentity) { @@ -295,47 +315,38 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ } this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", { cwd: this.$options, stdio: 'inherit' }).wait(); + this.createIpa(projectRoot).wait(); - if (buildForDevice) { - let buildOutputPath = path.join(projectRoot, "build", "device"); - - // Produce ipa file - let xcrunArgs = [ - "-sdk", "iphoneos", - "PackageApplication", - "-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"), - "-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa") - ]; - - this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit", { cwd: this.$options, stdio: 'inherit' }).wait(); - } }).future()(); } - public buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture { - if (this.$options.release) { - return this.buildProject(this.platformData.projectRoot, buildConfig); - } - - let devicesArchitectures = _(this.$devicesService.getDeviceInstances()) - .filter(d => this.$mobileHelper.isiOSPlatform(d.deviceInfo.platform)) - .map(d => d.deviceInfo.activeArchitecture) - .uniq() - .value(); - - let architectures = [ - `ARCHS=${devicesArchitectures.join(" ")}`, - `VALID_ARCHS=${devicesArchitectures.join(" ")}` - ]; + private buildForSimulator(projectRoot: string, args: string[], buildConfig?: IiOSBuildConfig): IFuture { + return (() => { + args = args.concat([ + "-sdk", "iphonesimulator", + "ARCHS=i386 x86_64", + "VALID_ARCHS=i386 x86_64", + "ONLY_ACTIVE_ARCH=NO", + "CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "emulator"), + "CODE_SIGN_IDENTITY=" + ]); - if (devicesArchitectures.length > 1) { - architectures.push('ONLY_ACTIVE_ARCH=NO'); - } + this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", { cwd: this.$options, stdio: 'inherit' }).wait(); - buildConfig = buildConfig || {}; - buildConfig.architectures = architectures; + }).future()(); + } - return this.buildProject(this.platformData.projectRoot, buildConfig); + private createIpa(projectRoot: string): IFuture { + return (() => { + let buildOutputPath = path.join(projectRoot, "build", "device"); + let xcrunArgs = [ + "-sdk", "iphoneos", + "PackageApplication", + "-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"), + "-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa") + ]; + this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit", { cwd: this.$options, stdio: 'inherit' }).wait(); + }).future()(); } public isPlatformPrepared(projectRoot: string): IFuture { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 98d3ca2712..25841cb4ce 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -6,6 +6,7 @@ import * as semver from "semver"; import {AppFilesUpdater} from "./app-files-updater"; import * as temp from "temp"; import {ProjectChangesInfo, IPrepareInfo} from "./project-changes-info"; +import Future = require("fibers/future"); temp.track(); let clui = require("clui"); @@ -54,7 +55,7 @@ export class PlatformService implements IPlatformService { private addPlatform(platformParam: string): IFuture { return (() => { let data = platformParam.split("@"), - platform = data[0], + platform = data[0].toLowerCase(), version = data[1]; this.validatePlatform(platform); @@ -328,16 +329,7 @@ export class PlatformService implements IPlatformService { }).future()(); } - public buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture { - return (() => { - platform = platform.toLowerCase(); - let platformData = this.$platformsData.getPlatformData(platform); - platformData.platformProjectService.buildProject(platformData.projectRoot, buildConfig).wait(); - this.$logger.out("Project successfully built."); - }).future()(); - } - - public prepareAndBuild(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture { + public buildPlatform(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture { return (() => { let shouldBuild = this.preparePlatform(platform, false).wait(); let platformData = this.$platformsData.getPlatformData(platform); @@ -352,12 +344,20 @@ export class PlatformService implements IPlatformService { } } if (shouldBuild || forceBuild) { - this.buildForDeploy(platform, buildConfig).wait(); + this.buildPlatformCore(platform, buildConfig).wait(); this.$fs.writeFile(buildInfoFile, this._prepareInfo.time).wait(); } }).future()(); } + private buildPlatformCore(platform: string, buildConfig?: IBuildConfig) { + return (() => { + let platformData = this.$platformsData.getPlatformData(platform); + platformData.platformProjectService.buildProject(platformData.projectRoot, buildConfig).wait(); + this.$logger.out("Project successfully built."); + }).future()(); + } + private getBuildOutputPath(platform: string, platformData: IPlatformData, buildConfig?: IBuildConfig): string { let buildForDevice = buildConfig ? buildConfig.buildForDevice : this.$options.forDevice; if (platform === this.$devicePlatformsConstants.iOS.toLowerCase()) { @@ -366,15 +366,6 @@ export class PlatformService implements IPlatformService { return platformData.deviceBuildOutputPath; } - public buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture { - return (() => { - platform = platform.toLowerCase(); - let platformData = this.$platformsData.getPlatformData(platform); - platformData.platformProjectService.buildForDeploy(platformData.projectRoot, buildConfig).wait(); - this.$logger.out("Project successfully built"); - }).future()(); - } - public lastOutputPath(platform: string, settings: { isForDevice: boolean }): string { let packageFile: string; let platformData = this.$platformsData.getPlatformData(platform); @@ -442,37 +433,23 @@ export class PlatformService implements IPlatformService { }).future()(); } - public runPlatform(platform: string, buildConfig?: IBuildConfig): IFuture { - platform = platform.toLowerCase(); - if (this.$options.emulator) { - return this.deployOnEmulator(platform, buildConfig); - } - - return this.deployOnDevice(platform, buildConfig); - } - - public installOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture { + public deployPlatform(platform: string): IFuture { return (() => { - platform = platform.toLowerCase(); - this.ensurePlatformInstalled(platform).wait(); let platformData = this.$platformsData.getPlatformData(platform); - this.$devicesService.initialize({ platform: platform, deviceId: this.$options.device }).wait(); let packageFileDict: IStringDictionary = {}; - let action = (device: Mobile.IDevice): IFuture => { return (() => { - let packageFileKey = this.getPackageFileKey(device); let packageFile = packageFileDict[packageFileKey]; if (!packageFile) { - if (this.$devicesService.isiOSSimulator(device)) { - this.prepareAndBuild(platform, buildConfig).wait(); + let buildConfig: IBuildConfig = {}; + let isSimulator = this.$devicesService.isiOSSimulator(device); + buildConfig.buildForDevice = !isSimulator; + this.buildPlatform(platform, buildConfig, false).wait(); + if (isSimulator) { packageFile = this.getLatestApplicationPackageForEmulator(platformData).wait().packageName; } else { - let deviceBuildConfig = buildConfig || {}; - deviceBuildConfig.buildForDevice = true; - this.prepareAndBuild(platform, deviceBuildConfig).wait(); packageFile = this.getLatestApplicationPackageForDevice(platformData).wait().packageName; } } @@ -482,34 +459,38 @@ export class PlatformService implements IPlatformService { this.$logger.info(`Successfully deployed on device with identifier '${device.deviceInfo.identifier}'.`); packageFileDict[packageFileKey] = packageFile; - }).future()(); }; this.$devicesService.execute(action, this.getCanExecuteAction(platform)).wait(); }).future()(); } - private getPackageFileKey(device: Mobile.IDevice): string { - if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) { - return device.deviceInfo.platform.toLowerCase(); + public runPlatform(platform: string): IFuture { + if (this.$options.avd) { + this.$logger.warn(`Option --avd is no longer supported. Please use --device instead!`); + return Future.fromResult(); } - return device.deviceInfo.platform.toLowerCase() + device.deviceInfo.type; - } - - public deployOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture { - return (() => { - this.installOnDevice(platform, buildConfig).wait(); - this.startOnDevice(platform).wait(); - }).future()(); - } - - public startOnDevice(platform: string): IFuture { return (() => { + this.deployPlatform(platform).wait(); let action = (device: Mobile.IDevice) => device.applicationManager.startApplication(this.$projectData.projectId); this.$devicesService.execute(action, this.getCanExecuteAction(platform)).wait(); }).future()(); } + public emulatePlatform(platform: string): IFuture { + if (this.$options.availableDevices) { + return $injector.resolveCommand("device").execute([platform]); + } + return this.runPlatform(platform); + } + + private getPackageFileKey(device: Mobile.IDevice): string { + if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) { + return device.deviceInfo.platform.toLowerCase(); + } + return device.deviceInfo.platform.toLowerCase() + device.deviceInfo.type; + } + private getCanExecuteAction(platform: string): any { let canExecute = (currentDevice: Mobile.IDevice): boolean => { if (this.$options.device && currentDevice && currentDevice.deviceInfo) { @@ -533,61 +514,6 @@ export class PlatformService implements IPlatformService { return canExecute; } - public deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture { - platform = platform.toLowerCase(); - if (this.$options.avd) { - this.$logger.warn(`Option --avd is no longer supported. Please use --device instead!`); - } - - if (this.$options.availableDevices || this.$options.device || this.$options.avd) { - return (() => { - let devices: string; - - if (this.$mobileHelper.isiOSPlatform(platform)) { - devices = this.$childProcess.exec("instruments -s devices").wait(); - } else if (this.$mobileHelper.isAndroidPlatform(platform)) { - let androidPath = path.join(process.env.ANDROID_HOME, "tools", "android"); - devices = this.$childProcess.exec(`${androidPath} list avd`).wait(); - } - - if (this.$options.availableDevices) { - this.$logger.info(devices); - } - - if (this.$options.device || this.$options.avd) { - if (this.$options.device) { - this.$options.avd = this.$options.device; - } - - if (devices.indexOf(this.$options.device) !== -1 || devices.indexOf(this.$options.avd) !== -1) { - this.ensurePlatformInstalled(platform).wait(); - - let packageFile: string, logFilePath: string; - let platformData = this.$platformsData.getPlatformData(platform); - let emulatorServices = platformData.emulatorServices; - - emulatorServices.checkAvailability().wait(); - emulatorServices.checkDependencies().wait(); - - this.prepareAndBuild(platform, buildConfig).wait(); - - packageFile = this.getLatestApplicationPackageForEmulator(platformData).wait().packageName; - this.$logger.out("Using ", packageFile); - - logFilePath = path.join(platformData.projectRoot, this.$projectData.projectName, "emulator.log"); - - emulatorServices.runApplicationOnEmulator(packageFile, { stderrFilePath: logFilePath, stdoutFilePath: logFilePath, appId: this.$projectData.projectId }).wait(); - } else { - this.$errors.fail(`Cannot find device with name: ${this.$options.device || this.$options.avd}.`); - } - } - }).future()(); - } else { - this.$options.emulator = true; - return this.deployOnDevice(platform, buildConfig); - } - } - public validatePlatform(platform: string): void { if (!platform) { this.$errors.fail("No platform specified.");