-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fernandoescolar
committed
Nov 24, 2024
1 parent
fa6e8d5
commit fedd5fe
Showing
8 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as path from "@extensions/path"; | ||
import * as fs from "@extensions/fs"; | ||
import * as xml from "@extensions/xml"; | ||
import { Solution, SolutionFolder, SolutionItem, SolutionProject, SolutionProjectType, SolutionType } from "../model"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
export class SlnxSolution extends Solution { | ||
private document: xml.XmlElement | undefined; | ||
|
||
constructor() { | ||
super(); | ||
this.type = SolutionType.Slnx; | ||
} | ||
|
||
public async load(filepath: string): Promise<void> { | ||
const content = await fs.readFile(filepath); | ||
this.document = await xml.parseToJson(content); | ||
this.fullPath = filepath; | ||
this.folderPath = path.dirname(filepath); | ||
this.name = path.basename(filepath); | ||
this.refresh(); | ||
} | ||
|
||
public refresh(): void { | ||
if (!this.document) { | ||
return; | ||
} | ||
|
||
this.items = []; | ||
if (this.document.elements.length === 1) { | ||
this.document.elements[0].elements.forEach((child: { name: string; }) => { | ||
if (child.name === 'Folder') { | ||
this.addItem(this.createFolder(child)); | ||
} else if (child.name === 'Project') { | ||
this.addItem(this.createProject(child)); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
private createProject(child: any) : SolutionItem { | ||
const project = new SolutionProject(uuidv4()); | ||
const projectPath = child.attributes.Path.replace(/\\/g, path.sep).trim(); | ||
project.fullPath = path.join(this.folderPath, projectPath); | ||
project.name = path.basename(projectPath, path.extname(projectPath)); | ||
project.type = SolutionProjectType.default; | ||
return project; | ||
} | ||
|
||
private createFolder(child: any) { | ||
const folder = new SolutionFolder(uuidv4()); | ||
folder.name = child.attributes.Name.replace(/^[\/\\]+|[\/\\]+$/g, ''); | ||
folder.fullPath = path.join(this.folderPath, folder.name); | ||
|
||
child.elements.forEach((child: { name: string; }) => { | ||
if (child.name === 'Project') { | ||
folder.addItem(this.createProject(child)) | ||
} else if (child.name === 'Folder') { | ||
folder.addItem(this.createFolder(child)); | ||
} | ||
}); | ||
|
||
return folder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters