Skip to content

Commit

Permalink
big refactor in solutions (to allow slnx #309)
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandoescolar committed Nov 23, 2024
1 parent c966009 commit fc17c92
Show file tree
Hide file tree
Showing 70 changed files with 476 additions and 330 deletions.
4 changes: 2 additions & 2 deletions src/SolutionTreeItemCollection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SolutionExplorerProvider } from "@SolutionExplorerProvider";
import { SolutionFile } from "@core/Solutions";
import { SolutionFactory } from "@core/Solutions";
import { TreeItem, TreeItemFactory } from "@tree";


Expand Down Expand Up @@ -28,7 +28,7 @@ export class SolutionTreeItemCollection {
}

public async addSolution(solutionPath: string, rootPath: string, solutionProvider: SolutionExplorerProvider): Promise<void> {
const solution = await SolutionFile.parse(solutionPath);
const solution = await SolutionFactory.load(solutionPath);
const item = await TreeItemFactory.createFromSolution(solutionProvider, solution, rootPath);
if (!this.children) {
this.children = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class AddExistingProject extends CustomTerminalAction {
export class DotNetAddExistingProject extends CustomTerminalAction {
constructor(private readonly solutionPath: string, private readonly projectPath: string) {
super({
name: "addExistingProjectToSolution",
parameters: { solutionPath, projectPath },
workingFolder: AddExistingProject.getWorkingPath(solutionPath)
workingFolder: DotNetAddExistingProject.getWorkingPath(solutionPath)
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TerminalCommand } from "@extensions/defaultTerminalCommands";
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class AddPackageReference extends CustomTerminalAction {
export class DotNetAddPackageReference extends CustomTerminalAction {
constructor(private readonly projectPath: string, private readonly packageId: string, packageVersion?: string) {
super({
name: AddPackageReference.getTerminalCommand(projectPath, packageId, packageVersion),
name: DotNetAddPackageReference.getTerminalCommand(projectPath, packageId, packageVersion),
parameters: { projectPath, packageId, packageVersion: packageVersion || "" },
workingFolder: AddPackageReference.getWorkingPath(projectPath)
workingFolder: DotNetAddPackageReference.getWorkingPath(projectPath)
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class AddProjectReference extends CustomTerminalAction {
export class DotNetAddProjectReference extends CustomTerminalAction {
constructor(private readonly projectPath: string, private readonly referencedProjectPath: string) {
super({
name: "addProjectReferenceToProject",
parameters: { projectPath, referencedProjectPath },
workingFolder: AddProjectReference.getWorkingPath(projectPath)
workingFolder: DotNetAddProjectReference.getWorkingPath(projectPath)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/Build.ts → src/actions/DotNetBuild.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Build extends CustomTerminalAction {
export class DotNetBuild extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "build",
parameters: { projectPath },
workingFolder: Build.getWorkingPath(projectPath)
workingFolder: DotNetBuild.getWorkingPath(projectPath)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/Clean.ts → src/actions/DotNetClean.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Clean extends CustomTerminalAction {
export class DotNetClean extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "clean",
parameters: { projectPath },
workingFolder: Clean.getWorkingPath(projectPath)
workingFolder: DotNetClean.getWorkingPath(projectPath)
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class CreateProject extends CustomTerminalAction {
export class DotNetCreateProject extends CustomTerminalAction {
constructor(projectType: string, language: string, private readonly projectName: string, folderName: string, workingFolder: string) {
super({
name: "createProject",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class CreateSolution extends CustomTerminalAction {
export class DotNetNewSln extends CustomTerminalAction {
constructor(private readonly solutionName: string, workingFolder: string) {
super({
name: "createSolution",
Expand Down
4 changes: 2 additions & 2 deletions src/actions/Pack.ts → src/actions/DotNetPack.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Pack extends CustomTerminalAction {
export class DotNetPack extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "pack",
parameters: { projectPath },
workingFolder: Pack.getWorkingPath(projectPath)
workingFolder: DotNetPack.getWorkingPath(projectPath)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/Publish.ts → src/actions/DotNetPublish.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Publish extends CustomTerminalAction {
export class DotNetPublish extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "publish",
parameters: { projectPath },
workingFolder: Publish.getWorkingPath(projectPath)
workingFolder: DotNetPublish.getWorkingPath(projectPath)
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class RemoveExistingProject extends CustomTerminalAction {
export class DotNetRemoveExistingProject extends CustomTerminalAction {
constructor(private readonly solutionPath: string, private readonly projectPath: string) {
super({
name: "removeProjectFromSolution",
parameters: { solutionPath, projectPath },
workingFolder: RemoveExistingProject.getWorkingPath(solutionPath)
workingFolder: DotNetRemoveExistingProject.getWorkingPath(solutionPath)
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class RemovePackageReference extends CustomTerminalAction {
export class DotNetRemovePackageReference extends CustomTerminalAction {
constructor(private readonly projectPath: string, private readonly packageId: string) {
super({
name: "removePackageReferenceFromProject",
parameters: { projectPath, packageId },
workingFolder: RemovePackageReference.getWorkingPath(projectPath)
workingFolder: DotNetRemovePackageReference.getWorkingPath(projectPath)
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class RemoveProjectReference extends CustomTerminalAction {
export class DotNetRemoveProjectReference extends CustomTerminalAction {
constructor(private readonly projectPath: string, private readonly referencedProjectPath: string) {
super({
name: "removeProjectReferenceFromProject",
parameters: { projectPath, referencedProjectPath },
workingFolder: RemoveProjectReference.getWorkingPath(projectPath)
workingFolder: DotNetRemoveProjectReference.getWorkingPath(projectPath)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/Restore.ts → src/actions/DotNetRestore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Restore extends CustomTerminalAction {
export class DotNetRestore extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "restore",
parameters: { projectPath },
workingFolder: Restore.getWorkingPath(projectPath)
workingFolder: DotNetRestore.getWorkingPath(projectPath)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/Run.ts → src/actions/DotNetRun.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Run extends CustomTerminalAction {
export class DotNetRun extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "run",
parameters: { projectPath },
workingFolder: Run.getWorkingPath(projectPath)
workingFolder: DotNetRun.getWorkingPath(projectPath)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/Test.ts → src/actions/DotNetTest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Test extends CustomTerminalAction {
export class DotNetTest extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "test",
parameters: { projectPath },
workingFolder: Test.getWorkingPath(projectPath)
workingFolder: DotNetTest.getWorkingPath(projectPath)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/Watch.ts → src/actions/DotNetWatch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomTerminalAction } from "./base/CustomTerminalAction";

export class Watch extends CustomTerminalAction {
export class DotNetWatch extends CustomTerminalAction {
constructor(private readonly projectPath: string) {
super({
name: "watch",
parameters: { projectPath },
workingFolder: Watch.getWorkingPath(projectPath)
workingFolder: DotNetWatch.getWorkingPath(projectPath)
});
}

Expand Down
12 changes: 0 additions & 12 deletions src/actions/MoveProject.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import * as path from "@extensions/path";
import * as fs from "@extensions/fs";
import * as dialogs from "@extensions/dialogs";
import { Action, ActionContext } from "./base/Action";
import { ProjectInSolution, SolutionFile } from "@core/Solutions";
import { SolutionItem, Solution } from "@core/Solutions";

type CopyFileOptions = "Yes" | "Skip" | "Cancel";

export class AddSolutionFile implements Action {
constructor(private readonly solution: SolutionFile, private readonly projectInSolution: ProjectInSolution, private filePath: string) {
export class SlnAddSolutionFile implements Action {
constructor(private readonly solution: Solution, private readonly solutionItem: SolutionItem, private filePath: string) {
}

public toString(): string {
return `Add file ${this.filePath} to folder ${this.projectInSolution.projectName} in solution ${this.solution.name}`;
return `Add file ${this.filePath} to folder ${this.solutionItem.name} in solution ${this.solution.name}`;
}

public async execute(context: ActionContext): Promise<void> {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class AddSolutionFile implements Action {
const lines: string[] = data.split('\n');
let projectLineIndexStart = -1, lineIndex = -1, hasSection = false;
lines.some((line, index, arr) => {
if (projectLineIndexStart < 0 && line.trim().startsWith('Project(') && line.indexOf('"' + this.projectInSolution.projectGuid + '"') > 0) {
if (projectLineIndexStart < 0 && line.trim().startsWith('Project(') && line.indexOf('"' + this.solutionItem.id + '"') > 0) {
projectLineIndexStart = index;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { v4 as uuidv4 } from "uuid";
import * as fs from "@extensions/fs";
import { ProjectInSolution, SolutionFile, SolutionProjectType } from "@core/Solutions";
import { SolutionItem, Solution, SolutionFolder } from "@core/Solutions";
import { Action, ActionContext } from "./base/Action";

export class CreateSolutionFolder implements Action {
constructor(private readonly solution: SolutionFile, private readonly folderName: string, private readonly projectInSolution?: ProjectInSolution) {
export class SlnCreateSolutionFolder implements Action {
constructor(private readonly solution: Solution, private readonly folderName: string, private readonly parentItem?: SolutionItem) {
}

public toString(): string {
Expand All @@ -14,12 +14,12 @@ export class CreateSolutionFolder implements Action {
public async execute(context: ActionContext): Promise<void> {
if (context.cancelled) { return; }

if (!this.projectInSolution) {
if (this.solution.projects.findIndex(p => p.projectName === this.folderName && p.projectType === SolutionProjectType.solutionFolder && !p.parentProjectGuid) >= 0) {
if (!this.parentItem) {
if (this.solution.getFolders().some(p => p.name === this.folderName)) {
throw new Error('Can not create solution folder, the folder already exists');
}
} else {
if (this.solution.projects.findIndex(p => p.projectName === this.folderName && p.projectType === SolutionProjectType.solutionFolder && p.parentProjectGuid === this.projectInSolution?.projectGuid) >= 0) {
if (this.parentItem instanceof SolutionFolder && this.parentItem.getFolders().some(p => p.name === this.folderName)) {
throw new Error('Can not create solution folder, the folder already exists');
}
}
Expand All @@ -38,12 +38,12 @@ export class CreateSolutionFolder implements Action {

return false;
});
if (this.projectInSolution && done) {
if (this.parentItem && done) {
let endGlobalIndex: number = -1;
done = lines.some((line, index, arr) => {
if (this.projectInSolution && line.trim() === 'GlobalSection(NestedProjects) = preSolution') {
if (this.parentItem && line.trim() === 'GlobalSection(NestedProjects) = preSolution') {
lines.splice(index + 1, 0,
' {' + guid + '} = ' + this.projectInSolution.projectGuid + '\r'
' {' + guid + '} = ' + this.parentItem.id + '\r'
);
return true;
}
Expand All @@ -58,7 +58,7 @@ export class CreateSolutionFolder implements Action {
if (!done && endGlobalIndex > 0) {
lines.splice(endGlobalIndex, 0,
' GlobalSection(NestedProjects) = preSolution\r',
' {' + guid + '} = ' + this.projectInSolution.projectGuid + '\r',
' {' + guid + '} = ' + this.parentItem.id + '\r',
' EndGlobalSection\r');
done = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as path from "@extensions/path";
import * as fs from "@extensions/fs";
import { Action, ActionContext } from "./base/Action";
import { ProjectInSolution, SolutionFile } from "@core/Solutions";
import { SolutionItem, Solution } from "@core/Solutions";

export class DeleteSolutionFile implements Action {
constructor(private readonly solution: SolutionFile, private readonly projectInSolution: ProjectInSolution, private filePath: string) {
export class SlnDeleteSolutionFile implements Action {
constructor(private readonly solution: Solution, private readonly solutionItem: SolutionItem, private filePath: string) {
}

public toString(): string {
return `Delete file ${this.filePath} from folder ${this.projectInSolution.projectName} in solution ${this.solution.name}`;
return `Delete file ${this.filePath} from folder ${this.solutionItem.name} in solution ${this.solution.name}`;
}

public async execute(context: ActionContext): Promise<void> {
Expand All @@ -26,7 +26,7 @@ export class DeleteSolutionFile implements Action {
let lines: string[] = data.split('\n');
let lineIndex = -1, projectLineIndexStart = -1, projectLineIndexEnd = -1, hasSection = false;
lines.some((line, index, arr) => {
if (projectLineIndexStart < 0 && line.trim().startsWith('Project(') && line.indexOf('"' + this.projectInSolution.projectGuid + '"') > 0) {
if (projectLineIndexStart < 0 && line.trim().startsWith('Project(') && line.indexOf('"' + this.solutionItem.id + '"') > 0) {
projectLineIndexStart = index;
}

Expand Down
Loading

0 comments on commit fc17c92

Please sign in to comment.