mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Remove ItemGroup from sqlproj if node being removed is the last one (#12398)
* remove ItemGroup if node being removed is the only one * fix for if ItemGroup has elements with different tag names * fix for ItemGroups not at the end of the sqlproj
This commit is contained in:
@@ -170,6 +170,7 @@ export function unableToFindObject(path: string, objType: string) { return local
|
|||||||
export function deployScriptExists(scriptType: string) { return localize('deployScriptExists', "A {0} script already exists. The new script will not be included in build.", scriptType); }
|
export function deployScriptExists(scriptType: string) { return localize('deployScriptExists', "A {0} script already exists. The new script will not be included in build.", scriptType); }
|
||||||
export function notValidVariableName(name: string) { return localize('notValidVariableName', "The variable name '{0}' is not valid.", name); }
|
export function notValidVariableName(name: string) { return localize('notValidVariableName', "The variable name '{0}' is not valid.", name); }
|
||||||
export function cantAddCircularProjectReference(project: string) { return localize('cantAddCircularProjectReference', "A reference to project '{0} cannot be added. Adding this project as a reference would cause a circular dependency", project); }
|
export function cantAddCircularProjectReference(project: string) { return localize('cantAddCircularProjectReference', "A reference to project '{0} cannot be added. Adding this project as a reference would cause a circular dependency", project); }
|
||||||
|
export function unableToFindSqlCmdVariable(variableName: string) { return localize('unableToFindSqlCmdVariable', "Unable to find SQLCMD variable '{0}'", variableName); }
|
||||||
|
|
||||||
// Action types
|
// Action types
|
||||||
export const deleteAction = localize('deleteAction', 'Delete');
|
export const deleteAction = localize('deleteAction', 'Delete');
|
||||||
|
|||||||
@@ -461,31 +461,13 @@ export class Project {
|
|||||||
const preDeployNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.PreDeploy);
|
const preDeployNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.PreDeploy);
|
||||||
const postDeployNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.PostDeploy);
|
const postDeployNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.PostDeploy);
|
||||||
const noneNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.None);
|
const noneNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.None);
|
||||||
|
const nodes = [fileNodes, preDeployNodes, postDeployNodes, noneNodes];
|
||||||
|
|
||||||
for (let i = 0; i < fileNodes.length; i++) {
|
let deleted = false;
|
||||||
if (fileNodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(path)) {
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
fileNodes[i].parentNode.removeChild(fileNodes[i]);
|
deleted = this.removeNode(path, nodes[i]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < preDeployNodes.length; i++) {
|
if (deleted) {
|
||||||
if (preDeployNodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(path)) {
|
|
||||||
preDeployNodes[i].parentNode.removeChild(preDeployNodes[i]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < postDeployNodes.length; i++) {
|
|
||||||
if (postDeployNodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(path)) {
|
|
||||||
postDeployNodes[i].parentNode.removeChild(postDeployNodes[i]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < noneNodes.length; i++) {
|
|
||||||
if (noneNodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(path)) {
|
|
||||||
noneNodes[i].parentNode.removeChild(noneNodes[i]);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -493,6 +475,26 @@ export class Project {
|
|||||||
throw new Error(constants.unableToFindObject(path, constants.fileObject));
|
throw new Error(constants.unableToFindObject(path, constants.fileObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private removeNode(includeString: string, nodes: any): boolean {
|
||||||
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
|
const parent = nodes[i].parentNode;
|
||||||
|
if (nodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(includeString)) {
|
||||||
|
parent.removeChild(nodes[i]);
|
||||||
|
|
||||||
|
// delete ItemGroup if this was the only entry
|
||||||
|
// only want element nodes, not text nodes
|
||||||
|
const otherChildren = Array.from(parent.childNodes).filter((c: any) => c.childNodes);
|
||||||
|
if (otherChildren.length === 0) {
|
||||||
|
parent.parentNode.removeChild(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private addFolderToProjFile(path: string): void {
|
private addFolderToProjFile(path: string): void {
|
||||||
const newFolderNode = this.projFileXmlDoc.createElement(constants.Folder);
|
const newFolderNode = this.projFileXmlDoc.createElement(constants.Folder);
|
||||||
newFolderNode.setAttribute(constants.Include, utils.convertSlashesForSqlProj(path));
|
newFolderNode.setAttribute(constants.Include, utils.convertSlashesForSqlProj(path));
|
||||||
@@ -502,24 +504,19 @@ export class Project {
|
|||||||
|
|
||||||
private removeFolderFromProjFile(path: string): void {
|
private removeFolderFromProjFile(path: string): void {
|
||||||
const folderNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.Folder);
|
const folderNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.Folder);
|
||||||
|
const deleted = this.removeNode(path, folderNodes);
|
||||||
|
|
||||||
for (let i = 0; i < folderNodes.length; i++) {
|
if (!deleted) {
|
||||||
if (folderNodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(path)) {
|
throw new Error(constants.unableToFindObject(path, constants.folderObject));
|
||||||
folderNodes[i].parentNode.removeChild(folderNodes[i]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(constants.unableToFindObject(path, constants.folderObject));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeSqlCmdVariableFromProjFile(variableName: string): void {
|
private removeSqlCmdVariableFromProjFile(variableName: string): void {
|
||||||
const sqlCmdVariableNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable);
|
const sqlCmdVariableNodes = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable);
|
||||||
|
const deleted = this.removeNode(variableName, sqlCmdVariableNodes);
|
||||||
|
|
||||||
for (let i = 0; i < sqlCmdVariableNodes.length; i++) {
|
if (!deleted) {
|
||||||
if (sqlCmdVariableNodes[i].getAttribute(constants.Include) === variableName) {
|
throw new Error(constants.unableToFindSqlCmdVariable(variableName));
|
||||||
sqlCmdVariableNodes[i].parentNode.removeChild(sqlCmdVariableNodes[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user