diff --git a/src/Accelerate/Accelerate.csproj b/src/Accelerate/Accelerate.csproj index 2056524..f1cbfc6 100644 --- a/src/Accelerate/Accelerate.csproj +++ b/src/Accelerate/Accelerate.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Accelerate/Campaign.cs b/src/Accelerate/Campaign.cs index d6c2f1f..708aae1 100644 --- a/src/Accelerate/Campaign.cs +++ b/src/Accelerate/Campaign.cs @@ -6,6 +6,8 @@ public sealed class Campaign public const string ReposFileName = "repos.json"; + public const string VisualStudioCodeWorkspaceFileName = "campaign.code-workspace"; + private readonly IGitCommand _gitCommand; private readonly IShellCommand _shellCommand; @@ -89,6 +91,9 @@ public async Task CloneAsync(CancellationToken ct = default) { throw new AccelerateException(AccelerateErrorCode.GitCommandExecutionFailed); } + + var visualStudioCodeWorkspaceJson = JsonSerializer.Serialize(new VisualStudioCodeWorkspace(this, _repositories)); + await File.WriteAllTextAsync(VisualStudioCodeWorkspaceFileName, visualStudioCodeWorkspaceJson, ct); } public async Task CommitAsync(string message, CancellationToken ct = default) @@ -192,4 +197,30 @@ public async Task ForeachAsync(IEnumerable command, CancellationToken ct throw new AccelerateException(AccelerateErrorCode.GitCommandExecutionFailed); } } + + private sealed class VisualStudioCodeWorkspace + { + public VisualStudioCodeWorkspace(Campaign campaign, IEnumerable repositories) + { + Folders = repositories.Select(repository => new VisualStudioCodeFolder(repository.Url.Segments.Last(), Path.GetFullPath(Path.Combine(campaign.WorkingDirectoryPath, repository.WorkingDirectoryPath)))).ToImmutableList(); + } + + [JsonPropertyName("folders")] + public IReadOnlyList Folders { get; } + } + + private sealed class VisualStudioCodeFolder + { + public VisualStudioCodeFolder(string name, string path) + { + Name = name; + Path = path; + } + + [JsonPropertyName("name")] + public string Name { get; } + + [JsonPropertyName("path")] + public string Path { get; } + } } \ No newline at end of file diff --git a/tests/Accelerate.Tests/Workflow/WorkflowTest.cs b/tests/Accelerate.Tests/Workflow/WorkflowTest.cs index bf7ea80..44378cd 100644 --- a/tests/Accelerate.Tests/Workflow/WorkflowTest.cs +++ b/tests/Accelerate.Tests/Workflow/WorkflowTest.cs @@ -54,6 +54,7 @@ await cmd.DisposeAsync() // Then Assert.True(File.Exists(Campaign.ReadmeFileName)); Assert.True(File.Exists(Campaign.ReposFileName)); + Assert.True(File.Exists(Campaign.VisualStudioCodeWorkspaceFileName)); Assert.Equivalent(typeof(IGitCommand).GetMethods().Select(methodInfo => methodInfo.Name), _actualCmds); Assert.Equivalent(typeof(IShellCommand).GetMethods().Select(methodInfo => methodInfo.Name), _actualCmds); }