diff --git a/lib/commands/update-platform.ts b/lib/commands/update-platform.ts index fa2c2bbd53..635027631b 100644 --- a/lib/commands/update-platform.ts +++ b/lib/commands/update-platform.ts @@ -17,7 +17,7 @@ export class UpdatePlatformCommand implements ICommand { this.$errors.fail("No platform specified. Please specify platforms to update."); } - _.each(args, arg => this.$platformService.validatePlatformInstalled(arg.split("@")[0])); + _.each(args, arg => this.$platformService.validatePlatform(arg.split("@")[0])); return true; }).future()(); diff --git a/lib/platform-command-param.ts b/lib/platform-command-param.ts index 1e5389d7fc..ff480fca23 100644 --- a/lib/platform-command-param.ts +++ b/lib/platform-command-param.ts @@ -6,7 +6,7 @@ export class PlatformCommandParameter implements ICommandParameter { mandatory = true; validate(value: string): IFuture { return (() => { - this.$platformService.validatePlatformInstalled(value); + this.$platformService.validatePlatform(value); return true; }).future()(); } diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 19876bba19..e1bbcdc5b9 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -146,6 +146,7 @@ export class PlatformService implements IPlatformService { this.validatePlatform(platform); platform = platform.toLowerCase(); + this.ensurePlatformInstalled(platform).wait(); var platformData = this.$platformsData.getPlatformData(platform); let appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); @@ -233,13 +234,13 @@ export class PlatformService implements IPlatformService { public updatePlatforms(platforms: string[]): IFuture { return (() => { - _.each(platforms, platform => { - var parts = platform.split("@"); - platform = parts[0].toLowerCase(); - var version = parts[1]; - - this.validatePlatformInstalled(platform); - this.updatePlatform(platform, version).wait(); + _.each(platforms, platformParam => { + let [platform, version] = platformParam.split("@"); + if(this.isPlatformInstalled(platform).wait()) { + this.updatePlatform(platform, version).wait(); + } else { + this.addPlatform(platformParam).wait(); + } }); }).future()(); } @@ -247,7 +248,7 @@ export class PlatformService implements IPlatformService { public deployOnDevice(platform: string): IFuture { return (() => { platform = platform.toLowerCase(); - + this.ensurePlatformInstalled(platform).wait(); var platformData = this.$platformsData.getPlatformData(platform); var cachedDeviceOption = this.$options.forDevice; @@ -276,7 +277,7 @@ export class PlatformService implements IPlatformService { public deployOnEmulator(platform: string): IFuture { return (() => { - this.validatePlatformInstalled(platform); + this.ensurePlatformInstalled(platform).wait(); platform = platform.toLowerCase(); var platformData = this.$platformsData.getPlatformData(platform); @@ -333,7 +334,15 @@ export class PlatformService implements IPlatformService { } }).future()(); } - + + private ensurePlatformInstalled(platform: string): IFuture { + return (() => { + if(!this.isPlatformInstalled(platform).wait()) { + this.addPlatform(platform).wait(); + } + }).future()(); + } + private isPlatformInstalled(platform: string): IFuture { return this.$fs.exists(path.join(this.$projectData.platformsDir, platform.toLowerCase())); } diff --git a/test/platform-service.ts b/test/platform-service.ts index 7429a1416b..4a5c195654 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -227,7 +227,11 @@ describe('Platform Service Tests', () => { appResourcesDestinationDirectoryPath: appResourcesFolderPath, normalizedPlatformName: "iOS", platformProjectService: { - prepareProject: () => Future.fromResult() + prepareProject: () => Future.fromResult(), + validate: () => Future.fromResult(), + createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(), + interpolateData: (projectRoot: string) => Future.fromResult(), + afterCreateProject: (projectRoot: string) => Future.fromResult() } } }; @@ -281,7 +285,11 @@ describe('Platform Service Tests', () => { appResourcesDestinationDirectoryPath: appResourcesFolderPath, normalizedPlatformName: "Android", platformProjectService: { - prepareProject: () => Future.fromResult() + prepareProject: () => Future.fromResult(), + validate: () => Future.fromResult(), + createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(), + interpolateData: (projectRoot: string) => Future.fromResult(), + afterCreateProject: (projectRoot: string) => Future.fromResult() } } };