Adds autorest-based SQL Project generation to SQL Database Projects extension (#17078)

* Initial changes

* checkpoint

* Constructing project with post deployment script

* Correcting to intentionally read from cached list of projects

* Adding activation event, fixing fresh workspace bug

* Convert netcoreTool and autorestHelper to share a helper class for streamed command

* Include npm package version to force update

* test checkpoint

* Unit tests

* Added contextual quickpicks for autorest dialogs

* Adding projectController test

* Added projectController test, some refactoring for testability

* Merge branch 'main' into benjin/autorest

* Fixing 'which' import

* PR feedback

* Fixing tests

* Adding additional information for when project provider tests fail

* Hopefully fixing failing tests (unable to repro locally)

* Adding Generate Project item to workspace menu

* PR feedback
This commit is contained in:
Benjin Dubishar
2021-09-16 20:38:40 -07:00
committed by GitHub
parent 0cf1abc7c2
commit 08e15bce99
18 changed files with 586 additions and 85 deletions

View File

@@ -13,6 +13,7 @@ const localize = nls.loadMessageBundle();
export const dataSourcesFileName = 'datasources.json';
export const sqlprojExtension = '.sqlproj';
export const sqlFileExtension = '.sql';
export const yamlFileExtension = '.yaml';
export const schemaCompareExtensionId = 'microsoft.schema-compare';
export const master = 'master';
export const masterDacpac = 'master.dacpac';
@@ -306,10 +307,12 @@ export const postDeployScriptFriendlyName = localize('postDeployScriptFriendlyNa
export const NetCoreInstallationConfirmation: string = localize('sqlDatabaseProjects.NetCoreInstallationConfirmation', "The .NET Core SDK cannot be located. Project build will not work. Please install .NET Core SDK version 3.1 or update the .NET Core SDK location in settings if already installed.");
export function NetCoreSupportedVersionInstallationConfirmation(installedVersion: string) { return localize('sqlDatabaseProjects.NetCoreSupportedVersionInstallationConfirmation', "Currently installed .NET Core SDK version is {0}, which is not supported. Project build will not work. Please install .NET Core SDK version 3.1 or update the .NET Core SDK supported version location in settings if already installed.", installedVersion); }
export const UpdateNetCoreLocation: string = localize('sqlDatabaseProjects.UpdateNetCoreLocation', "Update Location");
export const InstallNetCore: string = localize('sqlDatabaseProjects.InstallNetCore', "Install");
export const DoNotAskAgain: string = localize('sqlDatabaseProjects.doNotAskAgain', "Don't Ask Again");
export const projectsOutputChannel = localize('sqlDatabaseProjects.outputChannel', "Database Projects");
// Prompt buttons
export const Install: string = localize('sqlDatabaseProjects.Install', "Install");
export const DoNotAskAgain: string = localize('sqlDatabaseProjects.doNotAskAgain', "Don't Ask Again");
// SqlProj file XML names
export const ItemGroup = 'ItemGroup';
export const Build = 'Build';
@@ -408,6 +411,14 @@ export enum DatabaseProjectItemType {
dataSourceRoot = 'databaseProject.itemType.dataSourceRoot',
}
// AutoRest
export const autorestPostDeploymentScriptName = 'PostDeploymentScript.sql';
export const nodeButNotAutorestFound = localize('nodeButNotAutorestFound', "Autorest tool not found in system path, but found Node.js. Running via npx. Please execute 'npm install autorest -g' to install permanently.");
export const nodeNotFound = localize('nodeNotFound', "Neither autorest nor Node.js (npx) found in system path. Please install Node.js for autorest generation to work.");
export const selectSpecFile = localize('selectSpecFile', "Select OpenAPI/Swagger spec file");
export const generatingProjectFailed = localize('generatingProjectFailed', "Generating project via AutoRest failed");
export function multipleMostDeploymentScripts(count: number) { return localize('multipleMostDeploymentScripts', "Unexpected number of {0} files: {1}", autorestPostDeploymentScriptName, count); }
// System dbs
export const systemDbs = ['master', 'msdb', 'tempdb', 'model'];

View File

@@ -12,10 +12,11 @@ import * as glob from 'fast-glob';
import * as dataworkspace from 'dataworkspace';
import * as mssql from '../../../mssql';
import * as vscodeMssql from 'vscode-mssql';
import { promises as fs } from 'fs';
import { Project } from '../models/project';
import * as childProcess from 'child_process';
import * as fse from 'fs-extra';
import * as which from 'which';
import { promises as fs } from 'fs';
import { Project } from '../models/project';
export interface ValidationResult {
errorMessage: string;
@@ -489,6 +490,23 @@ export async function retry<T>(
return undefined;
}
/**
* Detects whether the specified command-line command is available on the current machine
*/
export async function detectCommandInstallation(command: string): Promise<boolean> {
try {
const found = await which(command);
if (found) {
return true;
}
} catch (err) {
console.log(getErrorMessage(err));
}
return false;
}
/**
* Gets all the projects of the specified extension in the folder
* @param folder