mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Swap create new project api for sql projects (#21971)
This commit is contained in:
@@ -603,6 +603,10 @@ export namespace SavePublishProfileRequest {
|
|||||||
|
|
||||||
// ------------------------------- < Sql Projects > ------------------------------------
|
// ------------------------------- < Sql Projects > ------------------------------------
|
||||||
|
|
||||||
|
export namespace NewSqlProjectRequest {
|
||||||
|
export const type = new RequestType<NewSqlProjectParams, azdata.ResultStatus, void, void>('sqlProjects/newProject');
|
||||||
|
}
|
||||||
|
|
||||||
export namespace OpenSqlProjectRequest {
|
export namespace OpenSqlProjectRequest {
|
||||||
export const type = new RequestType<SqlProjectParams, azdata.ResultStatus, void, void>('sqlProjects/openProject');
|
export const type = new RequestType<SqlProjectParams, azdata.ResultStatus, void, void>('sqlProjects/openProject');
|
||||||
}
|
}
|
||||||
@@ -615,6 +619,12 @@ export interface SqlProjectParams {
|
|||||||
projectUri: string;
|
projectUri: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NewSqlProjectParams extends SqlProjectParams {
|
||||||
|
sqlProjectType: mssql.ProjectType,
|
||||||
|
databaseSchemaProvider: string,
|
||||||
|
buildSdkVersion?: string
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------- </ Sql Projects > -----------------------------------
|
// ------------------------------- </ Sql Projects > -----------------------------------
|
||||||
|
|
||||||
// ------------------------------- <CMS> ----------------------------------------
|
// ------------------------------- <CMS> ----------------------------------------
|
||||||
|
|||||||
6
extensions/mssql/src/mssql.d.ts
vendored
6
extensions/mssql/src/mssql.d.ts
vendored
@@ -315,10 +315,16 @@ declare module 'mssql' {
|
|||||||
//#region --- Sql Projects
|
//#region --- Sql Projects
|
||||||
|
|
||||||
export interface ISqlProjectsService {
|
export interface ISqlProjectsService {
|
||||||
|
newProject(projectUri: string, sqlProjectType: ProjectType, databaseSchemaProvider: string, buildSdkVersion?: string): Promise<azdata.ResultStatus>;
|
||||||
openProject(projectUri: string): Promise<azdata.ResultStatus>;
|
openProject(projectUri: string): Promise<azdata.ResultStatus>;
|
||||||
getCrossPlatformCompatiblityRequest(projectUri: string): Promise<GetCrossPlatformCompatiblityResult>;
|
getCrossPlatformCompatiblityRequest(projectUri: string): Promise<GetCrossPlatformCompatiblityResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const enum ProjectType {
|
||||||
|
SdkStyle = 0,
|
||||||
|
LegacyStyle = 1
|
||||||
|
}
|
||||||
|
|
||||||
export interface GetCrossPlatformCompatiblityResult extends azdata.ResultStatus {
|
export interface GetCrossPlatformCompatiblityResult extends azdata.ResultStatus {
|
||||||
isCrossPlatformCompatible: boolean;
|
isCrossPlatformCompatible: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,16 @@ export class SqlProjectsService implements mssql.ISqlProjectsService {
|
|||||||
context.registerService(constants.SqlProjectsService, this);
|
context.registerService(constants.SqlProjectsService, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async newProject(projectUri: string, sqlProjectType: mssql.ProjectType, databaseSchemaProvider: string, buildSdkVersion?: string): Promise<azdata.ResultStatus> {
|
||||||
|
const params: contracts.NewSqlProjectParams = { projectUri, sqlProjectType, databaseSchemaProvider, buildSdkVersion };
|
||||||
|
try {
|
||||||
|
const result = await this.client.sendRequest(contracts.NewSqlProjectRequest.type, params);
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
this.client.logFailedRequest(contracts.NewSqlProjectRequest.type, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async openProject(projectUri: string): Promise<azdata.ResultStatus> {
|
public async openProject(projectUri: string): Promise<azdata.ResultStatus> {
|
||||||
const params: contracts.SqlProjectParams = { projectUri };
|
const params: contracts.SqlProjectParams = { projectUri };
|
||||||
|
|||||||
@@ -183,14 +183,7 @@ export class ProjectsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const targetPlatform = creationParams.targetPlatform ? constants.targetPlatformToVersion.get(creationParams.targetPlatform)! : constants.defaultDSP;
|
const targetPlatform = creationParams.targetPlatform ? constants.targetPlatformToVersion.get(creationParams.targetPlatform)! : constants.defaultDSP;
|
||||||
|
const sdkStyle = creationParams.sdkStyle ? mssql.ProjectType.SdkStyle : mssql.ProjectType.LegacyStyle;
|
||||||
const macroDict: Record<string, string> = {
|
|
||||||
'PROJECT_NAME': creationParams.newProjName,
|
|
||||||
'PROJECT_GUID': creationParams.projectGuid ?? UUID.generateUuid().toUpperCase(),
|
|
||||||
'PROJECT_DSP': targetPlatform
|
|
||||||
};
|
|
||||||
|
|
||||||
let newProjFileContents = creationParams.sdkStyle ? templates.macroExpansion(templates.newSdkSqlProjectTemplate, macroDict) : templates.macroExpansion(templates.newSqlProjectTemplate, macroDict);
|
|
||||||
|
|
||||||
let newProjFileName = creationParams.newProjName;
|
let newProjFileName = creationParams.newProjName;
|
||||||
|
|
||||||
@@ -204,9 +197,8 @@ export class ProjectsController {
|
|||||||
throw new Error(constants.projectAlreadyExists(newProjFileName, path.parse(newProjFilePath).dir));
|
throw new Error(constants.projectAlreadyExists(newProjFileName, path.parse(newProjFilePath).dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
const projectFolderPath = path.dirname(newProjFilePath);
|
const sqlProjectsService = await utils.getSqlProjectsService();
|
||||||
await fs.mkdir(projectFolderPath, { recursive: true });
|
await sqlProjectsService.newProject(newProjFilePath, sdkStyle, targetPlatform);
|
||||||
await fs.writeFile(newProjFilePath, newProjFileContents);
|
|
||||||
|
|
||||||
await this.addTemplateFiles(newProjFilePath, creationParams.projectTypeId);
|
await this.addTemplateFiles(newProjFilePath, creationParams.projectTypeId);
|
||||||
|
|
||||||
|
|||||||
@@ -54,23 +54,6 @@ describe('ProjectsController', function (): void {
|
|||||||
|
|
||||||
describe('project controller operations', function (): void {
|
describe('project controller operations', function (): void {
|
||||||
describe('Project file operations and prompting', function (): void {
|
describe('Project file operations and prompting', function (): void {
|
||||||
it('Should create new sqlproj file with correct values', async function (): Promise<void> {
|
|
||||||
const projController = new ProjectsController(testContext.outputChannel);
|
|
||||||
const projFileDir = path.join(testUtils.generateBaseFolderName(), `TestProject_${new Date().getTime()}`);
|
|
||||||
|
|
||||||
const projFilePath = await projController.createNewProject({
|
|
||||||
newProjName: 'TestProjectName',
|
|
||||||
folderUri: vscode.Uri.file(projFileDir),
|
|
||||||
projectTypeId: constants.emptySqlDatabaseProjectTypeId,
|
|
||||||
projectGuid: 'BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575',
|
|
||||||
sdkStyle: false
|
|
||||||
});
|
|
||||||
|
|
||||||
let projFileText = (await fs.readFile(projFilePath)).toString();
|
|
||||||
|
|
||||||
should(projFileText).equal(baselines.newProjectFileBaseline);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should create new sqlproj file with correct specified target platform', async function (): Promise<void> {
|
it('Should create new sqlproj file with correct specified target platform', async function (): Promise<void> {
|
||||||
const projController = new ProjectsController(testContext.outputChannel);
|
const projController = new ProjectsController(testContext.outputChannel);
|
||||||
const projFileDir = path.join(testUtils.generateBaseFolderName(), `TestProject_${new Date().getTime()}`);
|
const projFileDir = path.join(testUtils.generateBaseFolderName(), `TestProject_${new Date().getTime()}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user