Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(project): validate *.rpa.json files instead of .rpa directory exi… #144

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Joba.IBM.RPA/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,5 @@ public static async Task ThrowWhenUnsuccessfulAsync(this HttpResponseMessage res

throw new HttpRequestException(builder.ToString(), null, response.StatusCode);
}

public static void CreateHidden(this DirectoryInfo dir)
{
dir.Create();
dir.Attributes |= FileAttributes.Hidden;
}
}
}
4 changes: 1 addition & 3 deletions src/Joba.IBM.RPA/Project/ProjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ public static class ProjectFactory
public static IProject Create(DirectoryInfo workingDir, string name, string? description = null)
{
var projectFile = new ProjectFile(workingDir, name);
if (projectFile.RpaDirectory.Exists)
throw new ProjectException($"A project is already configured in the '{workingDir.FullName}' directory");
projectFile.RpaDirectory.CreateHidden();
projectFile.EnsureNoProjectHasBeenCreated();

var userFile = new UserSettingsFile(projectFile.ProjectName);
var packageSourcesFile = new PackageSourcesFile(workingDir, projectFile.ProjectName);
Expand Down
11 changes: 10 additions & 1 deletion src/Joba.IBM.RPA/Project/ProjectFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private ProjectFile(FileInfo file)
internal string FullPath => file.FullName;
internal string ProjectName => file.Name.Replace(Extension, null);
internal DirectoryInfo RpaDirectory => rpaDir;
internal DirectoryInfo WorkingDirectory => file.Directory ?? throw new Exception($"The file directory of '{file}' should exist");
internal DirectoryInfo WorkingDirectory => file.Directory ?? throw new Exception($"The directory of '{file}' should exist.");

internal async Task SaveAsync(ProjectSettings projectSettings, CancellationToken cancellation)
{
Expand Down Expand Up @@ -61,6 +61,15 @@ internal async Task SaveAsync(ProjectSettings projectSettings, CancellationToken
return new ProjectFile(files[0]);
}

internal void EnsureNoProjectHasBeenCreated()
{
var projectFiles = WorkingDirectory.EnumerateFiles("*.rpa.json").ToArray();
if (projectFiles.Length > 0)
throw new ProjectException($"Another project ({projectFiles[0].Name}) is already configured in the '{WorkingDirectory.FullName}' directory.");

rpaDir.Create();
}

public override string ToString() => file.FullName;

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