Creating a new database project, project items

* can create, open, and close sqlproj files
* can add sql objects to projects
This commit is contained in:
Benjin Dubishar
2020-04-17 14:09:59 -07:00
committed by GitHub
parent 05526bbaca
commit b3492e3f57
34 changed files with 1782 additions and 94 deletions

View File

@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as constants from '../common/constants';
import * as templates from './templates';
export class ProjectScriptType {
type: string;
friendlyName: string;
templateScript: string;
constructor(type: string, friendlyName: string, templateScript: string) {
this.type = type;
this.friendlyName = friendlyName;
this.templateScript = templateScript;
}
}
export const script: string = 'script';
export const table: string = 'table';
export const view: string = 'view';
export const storedProcedure: string = 'storedProcedure';
export const folder: string = 'folder';
export const projectScriptTypes: ProjectScriptType[] = [
new ProjectScriptType(script, constants.scriptFriendlyName, templates.newSqlScriptTemplate),
new ProjectScriptType(table, constants.tableFriendlyName, templates.newSqlTableTemplate),
new ProjectScriptType(view, constants.viewFriendlyName, templates.newSqlViewTemplate),
new ProjectScriptType(storedProcedure, constants.storedProcedureFriendlyName, templates.newSqlStoredProcedureTemplate),
];
export const projectScriptTypeMap: Record<string, ProjectScriptType> = {};
for (const scriptType of projectScriptTypes) {
if (Object.keys(projectScriptTypeMap).find(s => s === scriptType.type.toLocaleLowerCase() || s === scriptType.friendlyName.toLocaleLowerCase())) {
throw new Error(`Script type map already contains ${scriptType.type} or its friendlyName.`);
}
projectScriptTypeMap[scriptType.type.toLocaleLowerCase()] = scriptType;
projectScriptTypeMap[scriptType.friendlyName.toLocaleLowerCase()] = scriptType;
}

View File

@@ -0,0 +1,30 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import { promises as fs } from 'fs';
// Project templates
export let newSqlProjectTemplate: string;
// Script templates
export let newSqlScriptTemplate: string;
export let newSqlTableTemplate: string;
export let newSqlViewTemplate: string;
export let newSqlStoredProcedureTemplate: string;
export async function loadTemplates(templateFolderPath: string) {
newSqlProjectTemplate = await loadTemplate(templateFolderPath, 'newSqlProjectTemplate.xml');
newSqlScriptTemplate = await loadTemplate(templateFolderPath, 'newTsqlScriptTemplate.sql');
newSqlTableTemplate = await loadTemplate(templateFolderPath, 'newTsqlTableTemplate.sql');
newSqlViewTemplate = await loadTemplate(templateFolderPath, 'newTsqlViewTemplate.sql');
newSqlStoredProcedureTemplate = await loadTemplate(templateFolderPath, 'newTsqlStoredProcedureTemplate.sql');
}
async function loadTemplate(templateFolderPath: string, fileName: string): Promise<string> {
return (await fs.readFile(path.join(templateFolderPath, fileName))).toString();
}