From 7c9dc96dce40d5f10b6385862e6f778287f6c6c5 Mon Sep 17 00:00:00 2001 From: fatme Date: Tue, 28 Aug 2018 13:31:01 +0300 Subject: [PATCH 1/4] Fix arguments to printWarnings --- declarations.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/declarations.d.ts b/declarations.d.ts index d7fa4280..10088d87 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -1372,7 +1372,7 @@ interface IDoctorService { * @param configOptions: defines if the result should be tracked by Analytics * @returns {Promise} */ - printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string }): Promise; + printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string, options?: IOptions }): Promise; /** * Runs the setup script on host machine * @returns {Promise} From 4b9af463f7508b53f37b20d4b92615079680363b Mon Sep 17 00:00:00 2001 From: fatme Date: Thu, 30 Aug 2018 10:38:01 +0300 Subject: [PATCH 2/4] Add suppressCommandHelp to canExecute method --- definitions/commands.d.ts | 25 ++++++++++++++++++++++++- services/commands-service.ts | 18 ++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/definitions/commands.d.ts b/definitions/commands.d.ts index 3a19dddd..7f5d5ffa 100644 --- a/definitions/commands.d.ts +++ b/definitions/commands.d.ts @@ -10,7 +10,7 @@ interface ICommand extends ICommandOptions { // One possible case where you can use this method is when you have two commandParameters, neither of them is mandatory, // but at least one of them is required. Used in prop|add, prop|set, etc. commands as their logic is complicated and // default validation in CommandsService is not applicable. - canExecute?(args: string[]): Promise; + canExecute?(args: string[]): Promise; completionData?: string[]; dashedOptions?: IDictionary; isHierarchicalCommand?: boolean; @@ -23,6 +23,29 @@ interface ICommand extends ICommandOptions { postCommandAction?(args: string[]): Promise; } +interface ICommandBase extends ICommand { + canExecuteCommandBase(platform: string, options?: ICanExecuteCommandOptions): Promise; +} + +interface ICanExecuteCommandOutput { + canExecute: boolean; + /** + * In case when canExecute method returns false, the help of the command is printed. + * In case when canExecute method returns false and suppressCommandHelp is true, the command's help will not be printed. + */ + suppressCommandHelp?: boolean; +} + +interface ICanExecuteCommandOptions { + validateOptions?: boolean; + notConfiguredEnvOptions?: INotConfiguredEnvOptions; +} + +interface INotConfiguredEnvOptions { + hideSyncToPreviewAppOption?: boolean; + hideCloudBuildOption?: boolean; +} + interface IDynamicCommand extends ICommand { } interface ISimilarCommand { diff --git a/services/commands-service.ts b/services/commands-service.ts index a9bbdc70..70c30c62 100644 --- a/services/commands-service.ts +++ b/services/commands-service.ts @@ -105,13 +105,13 @@ export class CommandsService implements ICommandsService { return this.$helpService.showCommandLineHelp({ commandName: this.beautifyCommandName(commandName), commandArguments }); } - private async executeCommandAction(commandName: string, commandArguments: string[], action: (_commandName: string, _commandArguments: string[]) => Promise): Promise { + private async executeCommandAction(commandName: string, commandArguments: string[], action: (_commandName: string, _commandArguments: string[]) => Promise): Promise { return this.$errors.beginCommand( () => action.apply(this, [commandName, commandArguments]), () => this.printHelp(commandName, commandArguments)); } - private async tryExecuteCommandAction(commandName: string, commandArguments: string[]): Promise { + private async tryExecuteCommandAction(commandName: string, commandArguments: string[]): Promise { const command = this.$injector.resolveCommand(commandName); if (!command || (command && !command.isHierarchicalCommand)) { this.$options.validateOptions(command ? command.dashedOptions : null); @@ -125,19 +125,25 @@ export class CommandsService implements ICommandsService { } public async tryExecuteCommand(commandName: string, commandArguments: string[]): Promise { - if (await this.executeCommandAction(commandName, commandArguments, this.tryExecuteCommandAction)) { + const canExecuteResult: any = await this.executeCommandAction(commandName, commandArguments, this.tryExecuteCommandAction); + const canExecute = typeof canExecuteResult === "object" ? canExecuteResult.canExecute : canExecuteResult; + const suppressCommandHelp = typeof canExecuteResult === "object" ? canExecuteResult.suppressCommandHelp : false; + + if (canExecute) { await this.executeCommandAction(commandName, commandArguments, this.executeCommandUnchecked); } else { // If canExecuteCommand returns false, the command cannot be executed or there's no such command at all. const command = this.$injector.resolveCommand(commandName); if (command) { - // If command cannot be executed we should print its help. - await this.printHelp(commandName, commandArguments); + if (!suppressCommandHelp) { + // If command cannot be executed we should print its help. + await this.printHelp(commandName, commandArguments); + } } } } - private async canExecuteCommand(commandName: string, commandArguments: string[], isDynamicCommand?: boolean): Promise { + private async canExecuteCommand(commandName: string, commandArguments: string[], isDynamicCommand?: boolean): Promise { const command = this.$injector.resolveCommand(commandName); const beautifiedName = helpers.stringReplaceAll(commandName, "|", " "); if (command) { From 65df95e57a020900c63c44f945fa9797e08d2094 Mon Sep 17 00:00:00 2001 From: fatme Date: Mon, 10 Sep 2018 17:16:06 +0300 Subject: [PATCH 3/4] Start device detection interval when `tns run` command is executed. We need this in order to handle the case when `tns run --bundle` command is executed and the last connected Android device gets disconnected. In this case we need to receive DEVICE_LOST event for the android device. Currently this was impossible because all connected android devices are checked only once - at the beginning of the execution of the command. --- mobile/mobile-core/devices-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mobile/mobile-core/devices-service.ts b/mobile/mobile-core/devices-service.ts index c8f9571d..f47f6fcd 100644 --- a/mobile/mobile-core/devices-service.ts +++ b/mobile/mobile-core/devices-service.ts @@ -558,19 +558,19 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi if (platform && deviceOption) { this._platform = this.getPlatform(deviceInitOpts.platform); - await this.detectCurrentlyAttachedDevices(deviceInitOpts); + await this.startLookingForDevices(deviceInitOpts); this._device = await this.getDevice(deviceOption); if (this._device.deviceInfo.platform !== this._platform) { this.$errors.fail(constants.ERROR_CANNOT_RESOLVE_DEVICE); } this.$logger.warn("Your application will be deployed only on the device specified by the provided index or identifier."); } else if (!platform && deviceOption) { - await this.detectCurrentlyAttachedDevices(deviceInitOpts); + await this.startLookingForDevices(deviceInitOpts); this._device = await this.getDevice(deviceOption); this._platform = this._device.deviceInfo.platform; } else if (platform && !deviceOption) { this._platform = this.getPlatform(platform); - await this.detectCurrentlyAttachedDevices(deviceInitOpts); + await this.startLookingForDevices(deviceInitOpts); } else { // platform and deviceId are not specified if (deviceInitOpts.skipInferPlatform) { @@ -581,7 +581,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi await this.startLookingForDevices(deviceInitOpts); } } else { - await this.detectCurrentlyAttachedDevices(deviceInitOpts); + await this.startLookingForDevices(deviceInitOpts); const devices = this.getDeviceInstances(); const platforms = _(devices) From f24ceea0a540ea8a0eef2ec5f900c9b54c973d6b Mon Sep 17 00:00:00 2001 From: fatme Date: Tue, 11 Sep 2018 09:34:27 +0300 Subject: [PATCH 4/4] Remove unneeded interface & fix lint errors --- declarations.d.ts | 2 +- definitions/commands.d.ts | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/declarations.d.ts b/declarations.d.ts index 10088d87..07ac17e9 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -1372,7 +1372,7 @@ interface IDoctorService { * @param configOptions: defines if the result should be tracked by Analytics * @returns {Promise} */ - printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string, options?: IOptions }): Promise; + printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string, options?: ICommonOptions }): Promise; /** * Runs the setup script on host machine * @returns {Promise} diff --git a/definitions/commands.d.ts b/definitions/commands.d.ts index 7f5d5ffa..b6cfc6fc 100644 --- a/definitions/commands.d.ts +++ b/definitions/commands.d.ts @@ -23,10 +23,6 @@ interface ICommand extends ICommandOptions { postCommandAction?(args: string[]): Promise; } -interface ICommandBase extends ICommand { - canExecuteCommandBase(platform: string, options?: ICanExecuteCommandOptions): Promise; -} - interface ICanExecuteCommandOutput { canExecute: boolean; /**