mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 09:35:39 -05:00
Feature/project build (#10332)
* initial build command execution * adding tests * Clean up test names * update SqltoolsService release in ADS for Build * Updating as per PR comments * updating yarn lock * Adding one more test for command run * Test fixes
This commit is contained in:
93
extensions/sql-database-projects/src/tools/buildHelper.ts
Normal file
93
extensions/sql-database-projects/src/tools/buildHelper.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { promises as fs, existsSync } from 'fs';
|
||||
import * as utils from '../common/utils';
|
||||
import { mssqlNotFound } from '../common/constants';
|
||||
|
||||
const buildDirectory = 'BuildDirectory';
|
||||
const buildFiles: string[] = [
|
||||
'Microsoft.Data.SqlClient.dll',
|
||||
'Microsoft.Data.Tools.Schema.Sql.dll',
|
||||
'Microsoft.Data.Tools.Schema.Tasks.Sql.dll',
|
||||
'Microsoft.Data.Tools.Utilities.dll',
|
||||
'Microsoft.SqlServer.Dac.dll',
|
||||
'Microsoft.SqlServer.Dac.Extensions.dll',
|
||||
'Microsoft.SqlServer.TransactSql.ScriptDom.dll',
|
||||
'Microsoft.SqlServer.Types.dll',
|
||||
'System.ComponentModel.Composition.dll',
|
||||
'Microsoft.Data.Tools.Schema.SqlTasks.targets'
|
||||
];
|
||||
|
||||
export class BuildHelper {
|
||||
|
||||
private extensionDir: string;
|
||||
private extensionBuildDir: string;
|
||||
private initialized: boolean = false;
|
||||
|
||||
constructor() {
|
||||
this.extensionDir = vscode.extensions.getExtension('Microsoft.sql-database-projects')?.extensionPath ?? '';
|
||||
this.extensionBuildDir = path.join(this.extensionDir, buildDirectory);
|
||||
}
|
||||
|
||||
// create build dlls directory
|
||||
// this should not be required. temporary solution for issue #10273
|
||||
public async createBuildDirFolder(): Promise<void> {
|
||||
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!existsSync(this.extensionBuildDir)) {
|
||||
await fs.mkdir(this.extensionBuildDir);
|
||||
}
|
||||
|
||||
const buildfilesPath = await this.getBuildDirPathFromMssqlTools();
|
||||
|
||||
buildFiles.forEach(async (fileName) => {
|
||||
if (existsSync(path.join(buildfilesPath, fileName))) {
|
||||
await fs.copyFile(path.join(buildfilesPath, fileName), path.join(this.extensionBuildDir, fileName));
|
||||
}
|
||||
});
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
// get mssql sqltoolsservice path
|
||||
private async getBuildDirPathFromMssqlTools(): Promise<string> {
|
||||
const mssqlConfigDir = path.join(this.extensionDir, '..', 'mssql');
|
||||
|
||||
if (existsSync(path.join(mssqlConfigDir, 'config.json'))) {
|
||||
const rawConfig = await fs.readFile(path.join(mssqlConfigDir, 'config.json'));
|
||||
const config = JSON.parse(rawConfig.toString());
|
||||
const installDir = config.installDirectory?.replace('{#version#}', config.version).replace('{#platform#}', this.getPlatform());
|
||||
if (installDir) {
|
||||
return path.join(mssqlConfigDir, installDir);
|
||||
}
|
||||
}
|
||||
throw new Error(mssqlNotFound(mssqlConfigDir));
|
||||
}
|
||||
|
||||
private getPlatform(): string {
|
||||
return os.platform() === 'win32' ? 'Windows' :
|
||||
os.platform() === 'darwin' ? 'OSX' :
|
||||
os.platform() === 'linux' ? 'Linux' :
|
||||
'';
|
||||
}
|
||||
|
||||
public get extensionBuildDirPath(): string {
|
||||
return this.extensionBuildDir;
|
||||
}
|
||||
|
||||
public constructBuildArguments(projectPath: string, buildDirPath: string): string {
|
||||
projectPath = utils.getSafePath(projectPath);
|
||||
buildDirPath = utils.getSafePath(buildDirPath);
|
||||
return ` build ${projectPath} /p:NetCoreBuild=true /p:NETCoreTargetsPath=${buildDirPath}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user