diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index fdf144481f..3edeb6af49 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -81,7 +81,7 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter { * @param {string} @optional outputPath Directory containing build information and artifacts. * @returns {Promise} true indicates that the application should be installed. */ - shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise; + shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: IRelease, outputPath?: string): Promise; /** * Determines whether the project should undergo the prepare process. @@ -260,7 +260,7 @@ interface IPlatformData { projectRoot: string; normalizedPlatformName: string; appDestinationDirectoryPath: string; - deviceBuildOutputPath: string; + getDeviceBuildOutputPath(options: IRelease): string; emulatorBuildOutputPath?: string; getValidPackageNames(buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[]; frameworkFilesExtensions: string[]; diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index cc0ee62403..d71b9a6583 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -142,6 +142,10 @@ interface IBuildForDevice { buildForDevice: boolean; } +interface IShouldInstall extends IBuildForDevice, IRelease { + +} + interface INativePrepare { skipNativePrepare: boolean; } diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index d0073652a2..0b7c230ef1 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -83,7 +83,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject platformProjectService: this, emulatorServices: this.$androidEmulatorServices, projectRoot: projectRoot, - deviceBuildOutputPath: this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData), + getDeviceBuildOutputPath: (options: IRelease): string => { + return this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData, options); + }, getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => { const buildMode = buildOptions.isReleaseBuild ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase(); @@ -106,10 +108,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject return this._platformData; } - private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData): string { + private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData, options: IRelease): string { const currentPlatformData: IDictionary = this.$projectDataService.getNSValue(projectData.projectDir, constants.TNS_ANDROID_RUNTIME_NAME); const platformVersion = currentPlatformData && currentPlatformData[constants.VERSION_STRING]; - const normalizedPath = path.join(currentPath, "debug"); + const buildType = options.release === true ? "release" : "debug"; + const normalizedPath = path.join(currentPath, buildType); if (semver.valid(platformVersion)) { const gradleAndroidPluginVersion3xx = "4.0.0"; diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 2efaea3163..ab12660aab 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -71,7 +71,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ platformProjectService: this, emulatorServices: this.$iOSEmulatorServices, projectRoot: projectRoot, - deviceBuildOutputPath: path.join(projectRoot, "build", "device"), + getDeviceBuildOutputPath: (options: IRelease): string => { + return path.join(projectRoot, "build", "device"); + }, emulatorBuildOutputPath: path.join(projectRoot, "build", "emulator"), getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => { if (buildOptions.isForDevice) { diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index 5e71fef48d..da16aea9fc 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -413,7 +413,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi await this.trackAction(action, platform, options); - const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options.deviceBuildInfoDescriptor.outputPath); + const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options, options.deviceBuildInfoDescriptor.outputPath); if (shouldInstall) { await this.$platformService.installApplication(options.device, { release: false }, options.projectData, pathToBuildItem, options.deviceBuildInfoDescriptor.outputPath); appInstalledOnDeviceResult.appInstalled = true; diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index e09da69dcd..0eaea50425 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -333,7 +333,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { const platformData = this.$platformsData.getPlatformData(platform, projectData); const forDevice = !buildConfig || buildConfig.buildForDevice; - outputPath = outputPath || (forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath); + outputPath = outputPath || (forDevice ? platformData.getDeviceBuildOutputPath(buildConfig) : platformData.emulatorBuildOutputPath || platformData.getDeviceBuildOutputPath(buildConfig)); if (!this.$fs.exists(outputPath)) { return true; } @@ -433,7 +433,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { this.$fs.writeJson(buildInfoFile, buildInfo); } - public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise { + public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: IBuildConfig, outputPath?: string): Promise { const platform = device.deviceInfo.platform; if (!(await device.applicationManager.isApplicationInstalled(projectData.projectId))) { return true; @@ -441,7 +441,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { const platformData = this.$platformsData.getPlatformData(platform, projectData); const deviceBuildInfo: IBuildInfo = await this.getDeviceBuildInfo(device, projectData); - const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator }, outputPath); + const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator, release: release.release }, outputPath); return !localBuildInfo || !deviceBuildInfo || deviceBuildInfo.buildTime !== localBuildInfo.buildTime; } @@ -469,7 +469,9 @@ export class PlatformService extends EventEmitter implements IPlatformService { if (!buildConfig.release) { const deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData); - const buildInfoFilePath = outputFilePath || this.getBuildOutputPath(device.deviceInfo.platform, platformData, { buildForDevice: !device.isEmulator }); + const options = buildConfig; + options.buildForDevice = !device.isEmulator; + const buildInfoFilePath = outputFilePath || this.getBuildOutputPath(device.deviceInfo.platform, platformData, options); const appIdentifier = projectData.projectId; await device.fileSystem.putFile(path.join(buildInfoFilePath, buildInfoFileName), deviceFilePath, appIdentifier); @@ -515,8 +517,8 @@ export class PlatformService extends EventEmitter implements IPlatformService { this.$logger.out("Skipping package build. No changes detected on the native side. This will be fast!"); } - if (deployInfo.deployOptions.forceInstall || shouldBuild || (await this.shouldInstall(device, deployInfo.projectData))) { - await this.installApplication(device, buildConfig, deployInfo.projectData, installPackageFile, deployInfo.outputPath); + if (deployInfo.deployOptions.forceInstall || shouldBuild || (await this.shouldInstall(device, deployInfo.projectData, buildConfig))) { + await this.installApplication(device, buildConfig, deployInfo.projectData); } else { this.$logger.out("Skipping install."); } @@ -550,12 +552,12 @@ export class PlatformService extends EventEmitter implements IPlatformService { await this.$devicesService.execute(action, this.getCanExecuteAction(platform, runOptions)); } - private getBuildOutputPath(platform: string, platformData: IPlatformData, options: IBuildForDevice): string { + private getBuildOutputPath(platform: string, platformData: IPlatformData, options: IShouldInstall): string { if (platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) { - return options.buildForDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath; + return options.buildForDevice ? platformData.getDeviceBuildOutputPath(options) : platformData.emulatorBuildOutputPath; } - return platformData.deviceBuildOutputPath; + return platformData.getDeviceBuildOutputPath(options); } private async getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise { @@ -575,7 +577,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { } } - private getBuildInfo(platform: string, platformData: IPlatformData, options: IBuildForDevice, buildOutputPath?: string): IBuildInfo { + private getBuildInfo(platform: string, platformData: IPlatformData, options: IShouldInstall, buildOutputPath?: string): IBuildInfo { buildOutputPath = buildOutputPath || this.getBuildOutputPath(platform, platformData, options); const buildInfoFile = path.join(buildOutputPath, buildInfoFileName); if (this.$fs.exists(buildInfoFile)) { @@ -765,11 +767,11 @@ export class PlatformService extends EventEmitter implements IPlatformService { } public getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage { - return this.getLatestApplicationPackage(outputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release })); + return this.getLatestApplicationPackage(outputPath || platformData.getDeviceBuildOutputPath(buildConfig), platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release })); } public getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage { - return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release })); + return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.getDeviceBuildOutputPath(buildConfig), platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release })); } private async updatePlatform(platform: string, version: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise { diff --git a/test/platform-commands.ts b/test/platform-commands.ts index fd0bf7a9d7..3e638d3ca1 100644 --- a/test/platform-commands.ts +++ b/test/platform-commands.ts @@ -35,7 +35,9 @@ class PlatformData implements IPlatformData { }; emulatorServices: Mobile.IEmulatorPlatformServices = null; projectRoot = ""; - deviceBuildOutputPath = ""; + getDeviceBuildOutputPath = (buildTypeOption: IRelease) => { + return ""; + } getValidPackageNames = (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [""]; validPackageNamesForDevice: string[] = []; frameworkFilesExtensions = [".jar", ".dat"]; diff --git a/test/stubs.ts b/test/stubs.ts index 096c196dc3..c1e26bf437 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -304,7 +304,9 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor platformProjectService: this, emulatorServices: undefined, projectRoot: "", - deviceBuildOutputPath: "", + getDeviceBuildOutputPath: (buildTypeOption: IRelease) => { + return ""; + }, getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [], frameworkFilesExtensions: [], appDestinationDirectoryPath: "", @@ -415,7 +417,9 @@ export class PlatformsDataStub extends EventEmitter implements IPlatformsData { projectRoot: "", normalizedPlatformName: "", appDestinationDirectoryPath: "", - deviceBuildOutputPath: "", + getDeviceBuildOutputPath: (buildTypeOption: IRelease) => { + return ""; + }, getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [], frameworkFilesExtensions: [], relativeToFrameworkConfigurationFilePath: "",