Prompts user for desired action when autorest is not installed (#17305)

* Giving user option to install autorest globally or run via npx

* Adds message for when no files are generated (no models in spec)

* Adding test

* Reinstating the rest of the test suite

* PR feedback

* Fixing tests to stub new prompt when test runner doesn't have autorest installed

* PR feedback

* fix typo

* fix typo
This commit is contained in:
Benjin Dubishar
2021-10-15 13:26:58 -07:00
committed by GitHub
parent 7b66acd58b
commit 901b90317c
5 changed files with 62 additions and 14 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { DoNotAskAgain, Install, nodeButNotAutorestFound, nodeNotFound } from '../common/constants';
import { DoNotAskAgain, Install, nodeButNotAutorestFound, nodeNotFound, nodeButNotAutorestFoundPrompt, runViaNpx, installGlobally } from '../common/constants';
import * as utils from '../common/utils';
import * as semver from 'semver';
import { DBProjectConfigurationKey } from './netcoreTool';
@@ -48,7 +48,15 @@ export class AutorestHelper extends ShellExecutionHelper {
if (await utils.detectCommandInstallation(npxCommand)) {
this._outputChannel.appendLine(nodeButNotAutorestFound);
return `${npxCommand} ${autorestCommand}`;
const response = await vscode.window.showInformationMessage(nodeButNotAutorestFoundPrompt, installGlobally, runViaNpx);
if (response === installGlobally) {
await this.runStreamedCommand('npm install autorest -g', this._outputChannel);
return autorestCommand;
} else if (response === runViaNpx) {
return `${npxCommand} ${autorestCommand}`;
}
}
return undefined;
@@ -63,7 +71,7 @@ export class AutorestHelper extends ShellExecutionHelper {
public async generateAutorestFiles(specPath: string, outputFolder: string): Promise<string | undefined> {
const commandExecutable = await this.detectInstallation();
if (commandExecutable === undefined) {
if (!commandExecutable) {
// unable to find autorest or npx
if (vscode.workspace.getConfiguration(DBProjectConfigurationKey)[nodejsDoNotAskAgainKey] !== true) {