From 6e1bc58035c4585c08419082b1ca0b856af8c4f8 Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Wed, 11 Jan 2017 12:57:49 +0200 Subject: [PATCH] Fix options validation for 'tns prepare', add validation for 'tns livesync', fix .name to .uuid in provision checks --- lib/commands/build.ts | 4 +++- lib/commands/debug.ts | 29 +++++++++++++++++++++++------ lib/commands/livesync.ts | 10 +++++----- lib/commands/prepare.ts | 4 +++- lib/commands/run.ts | 4 +++- lib/definitions/platform.d.ts | 4 +++- lib/services/ios-project-service.ts | 2 +- lib/services/platform-service.ts | 18 +++++++++++++++--- package.json | 2 +- test/debug.ts | 6 ++++++ 10 files changed, 63 insertions(+), 20 deletions(-) diff --git a/lib/commands/build.ts b/lib/commands/build.ts index ecafd19f2f..cd0ee95dfd 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -30,7 +30,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand { } public canExecute(args: string[]): IFuture { - return this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS); + return (() => { + return args.length === 0 && this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS).wait(); + }).future()(); } } $injector.registerCommand("build|ios", BuildIosCommand); diff --git a/lib/commands/debug.ts b/lib/commands/debug.ts index 8b6639f6cb..70e3edb9f7 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -7,8 +7,9 @@ private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, private $config: IConfiguration, private $usbLiveSyncService: ILiveSyncService, - private $platformService: IPlatformService, - protected $options: IOptions) { } + protected $platformService: IPlatformService, + protected $options: IOptions, + protected $platformsData: IPlatformsData) { } execute(args: string[]): IFuture { if (this.$options.start) { @@ -67,8 +68,16 @@ export class DebugIOSCommand extends DebugPlatformCommand { $config: IConfiguration, $usbLiveSyncService: ILiveSyncService, $platformService: IPlatformService, - $options: IOptions) { - super($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options); + $options: IOptions, + $platformsData: IPlatformsData) { + + super($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData); + } + + canExecute(args: string[]): IFuture { + return (() => { + return super.canExecute(args).wait() && this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS).wait(); + }).future()(); } } $injector.registerCommand("debug|ios", DebugIOSCommand); @@ -83,8 +92,16 @@ export class DebugAndroidCommand extends DebugPlatformCommand { $config: IConfiguration, $usbLiveSyncService: ILiveSyncService, $platformService: IPlatformService, - $options: IOptions) { - super($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options); + $options: IOptions, + $platformsData: IPlatformsData) { + + super($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData); + } + + canExecute(args: string[]): IFuture { + return (() => { + return super.canExecute(args).wait() && this.$platformService.validateOptions(this.$platformsData.availablePlatforms.Android).wait(); + }).future()(); } } $injector.registerCommand("debug|android", DebugAndroidCommand); diff --git a/lib/commands/livesync.ts b/lib/commands/livesync.ts index 073a5e6d0f..fd5da9b505 100644 --- a/lib/commands/livesync.ts +++ b/lib/commands/livesync.ts @@ -13,16 +13,16 @@ export class LivesyncCommand implements ICommand { public canExecute(args: string[]): IFuture { return (() => { - if(args.length >= 2) { + if (args.length >= 2) { this.$errors.fail("Invalid number of arguments."); } let platform = args[0]; - if(platform) { - return _.includes(this.$mobileHelper.platformNames, this.$mobileHelper.normalizePlatformName(platform)); + if (platform) { + return _.includes(this.$mobileHelper.platformNames, this.$mobileHelper.normalizePlatformName(platform)) && this.$platformService.validateOptions(args[0]).wait(); + } else { + return this.$platformService.validateOptions().wait(); } - - return true; }).future()(); } diff --git a/lib/commands/prepare.ts b/lib/commands/prepare.ts index fcac356ab1..0a2b568b85 100644 --- a/lib/commands/prepare.ts +++ b/lib/commands/prepare.ts @@ -10,7 +10,9 @@ export class PrepareCommand implements ICommand { } public canExecute(args: string[]): IFuture { - return this.$platformService.validateOptions(args[0]); + return (() => { + return this.$platformCommandParameter.validate(args[0]).wait() && this.$platformService.validateOptions(args[0]).wait(); + }).future()(); } allowedParameters = [this.$platformCommandParameter]; diff --git a/lib/commands/run.ts b/lib/commands/run.ts index e4d336c0da..fe8edb7409 100644 --- a/lib/commands/run.ts +++ b/lib/commands/run.ts @@ -28,7 +28,9 @@ export class RunIosCommand extends RunCommandBase implements ICommand { } public canExecute(args: string[]): IFuture { - return this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS); + return (() => { + return args.length === 0 && this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS).wait(); + }).future()(); } } $injector.registerCommand("run|ios", RunIosCommand); diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index 137c63a920..a586db5126 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -78,8 +78,10 @@ interface IPlatformService { /** * Gets first chance to validate the options provided as command line arguments. + * If no platform is provided or a falsy (null, undefined, "", false...) platform is provided, + * the options will be validated for all available platforms. */ - validateOptions(platform: string): IFuture; + validateOptions(platform?: string): IFuture; /** * Executes prepare, build and installOnPlatform when necessary to ensure that the latest version of the app is installed on specified platform. diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index df32e3dbb9..5876d8342f 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -348,7 +348,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ if (signing && signing.style === "Manual") { for(let config in signing.configurations) { let options = signing.configurations[config]; - if (options.name !== this.$options.provision && options.name !== this.$options.provision) { + if (options.name !== this.$options.provision && options.uuid !== this.$options.provision) { shouldUpdateXcode = true; break; } diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 957cbce941..0464c597bf 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -227,10 +227,22 @@ export class PlatformService implements IPlatformService { }).future()(); } - public validateOptions(platform: string): IFuture { + public validateOptions(platform?: string): IFuture { return (() => { - let platformData = this.$platformsData.getPlatformData(platform); - return platformData.platformProjectService.validateOptions().wait(); + if (platform) { + platform = this.$mobileHelper.normalizePlatformName(platform); + this.$logger.trace("Validate options for platform: " + platform); + let platformData = this.$platformsData.getPlatformData(platform); + return platformData.platformProjectService.validateOptions().wait(); + } else { + let valid = true; + for (let availablePlatform in this.$platformsData.availablePlatforms) { + this.$logger.trace("Validate options for platform: " + availablePlatform); + let platformData = this.$platformsData.getPlatformData(availablePlatform); + valid = valid && platformData.platformProjectService.validateOptions().wait(); + } + return valid; + } }).future()(); } diff --git a/package.json b/package.json index a201cc88ee..61fb3dbd73 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "mute-stream": "0.0.5", "open": "0.0.5", "osenv": "0.1.3", - "pbxproj-dom": "^1.0.7", + "pbxproj-dom": "1.0.7", "plist": "1.1.0", "plist-merge-patch": "0.0.9", "plistlib": "0.2.1", diff --git a/test/debug.ts b/test/debug.ts index b41732c113..b987c26154 100644 --- a/test/debug.ts +++ b/test/debug.ts @@ -48,6 +48,12 @@ function createTestInjector(): IInjector { testInjector.register("adb", AndroidDebugBridge); testInjector.register("androidDebugBridgeResultHandler", AndroidDebugBridgeResultHandler); testInjector.register("platformService", stubs.PlatformServiceStub); + testInjector.register("platformsData", { + availablePlatforms: { + Android: "Android", + iOS: "iOS" + } + }); return testInjector; }