Skip to content

Commit 12bbc0c

Browse files
committed
fix(project): validate *.rpa.json files instead of .rpa directory existence
Signed-off-by: JobaDiniz <[email protected]>
1 parent a4ff18d commit 12bbc0c

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/Joba.IBM.RPA/Extensions.cs

-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,5 @@ public static async Task ThrowWhenUnsuccessfulAsync(this HttpResponseMessage res
3838

3939
throw new HttpRequestException(builder.ToString(), null, response.StatusCode);
4040
}
41-
42-
public static void CreateHidden(this DirectoryInfo dir)
43-
{
44-
dir.Create();
45-
dir.Attributes |= FileAttributes.Hidden;
46-
}
4741
}
4842
}

src/Joba.IBM.RPA/Project/ProjectFactory.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ public static class ProjectFactory
55
public static IProject Create(DirectoryInfo workingDir, string name, string? description = null)
66
{
77
var projectFile = new ProjectFile(workingDir, name);
8-
if (projectFile.RpaDirectory.Exists)
9-
throw new ProjectException($"A project is already configured in the '{workingDir.FullName}' directory");
10-
projectFile.RpaDirectory.CreateHidden();
8+
projectFile.EnsureNoProjectHasBeenCreated();
119

1210
var userFile = new UserSettingsFile(projectFile.ProjectName);
1311
var packageSourcesFile = new PackageSourcesFile(workingDir, projectFile.ProjectName);

src/Joba.IBM.RPA/Project/ProjectFile.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private ProjectFile(FileInfo file)
2323
internal string FullPath => file.FullName;
2424
internal string ProjectName => file.Name.Replace(Extension, null);
2525
internal DirectoryInfo RpaDirectory => rpaDir;
26-
internal DirectoryInfo WorkingDirectory => file.Directory ?? throw new Exception($"The file directory of '{file}' should exist");
26+
internal DirectoryInfo WorkingDirectory => file.Directory ?? throw new Exception($"The directory of '{file}' should exist.");
2727

2828
internal async Task SaveAsync(ProjectSettings projectSettings, CancellationToken cancellation)
2929
{
@@ -61,6 +61,15 @@ internal async Task SaveAsync(ProjectSettings projectSettings, CancellationToken
6161
return new ProjectFile(files[0]);
6262
}
6363

64+
internal void EnsureNoProjectHasBeenCreated()
65+
{
66+
var projectFiles = WorkingDirectory.EnumerateFiles("*.rpa.json").ToArray();
67+
if (projectFiles.Length > 0)
68+
throw new ProjectException($"Another project ({projectFiles[0].Name}) is already configured in the '{WorkingDirectory.FullName}' directory.");
69+
70+
rpaDir.Create();
71+
}
72+
6473
public override string ToString() => file.FullName;
6574

6675
private string GetDebuggerDisplay() => $"[{ProjectName}] {ToString()}";

0 commit comments

Comments
 (0)