Skip to content

Commit

Permalink
Add VS Code task to re-run and update
Browse files Browse the repository at this point in the history
fixes #1987
  • Loading branch information
ErikEJ committed Oct 31, 2023
1 parent 464b055 commit 6e4e80b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/GUI/RevEng.Shared/Cli/VsCode/Input.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace RevEng.Common.Cli.VsCode
{
public class Input
{
public string type { get; set; }
public string id { get; set; }
public string description { get; set; }
public string @default { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/GUI/RevEng.Shared/Cli/VsCode/Presentation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace RevEng.Common.Cli.VsCode
{
public class Presentation
{
public string reveal { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/GUI/RevEng.Shared/Cli/VsCode/TaskItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace RevEng.Common.Cli.VsCode
{
internal class TaskItem
{
public string label { get; set; }
public string command { get; set; }
public string type { get; set; }
public List<string> args { get; set; }
public string group { get; set; }
public Presentation presentation { get; set; }
public string problemMatcher { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/GUI/RevEng.Shared/Cli/VsCode/VsCodeTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace RevEng.Common.Cli.VsCode
{
internal class VsCodeTask
{
public string version { get; set; }
public List<TaskItem> tasks { get; set; }
public List<Input> inputs { get; set; }
}
}
83 changes: 83 additions & 0 deletions src/GUI/RevEng.Shared/Cli/VsCode/VsCodeTaskHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.IO;
using System.Text;
using System.Text.Json;

namespace RevEng.Common.Cli.VsCode
{
public static class VsCodeTaskHelper
{
public static void GenerateTaskPayload(string projectPath, int version, string redactedConnectionString)
{
var path = Path.Combine(projectPath, ".vscode");

if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}

path = Path.Combine(path, "tasks.json");

if (File.Exists(path))
{
return;
}

var vsCodeTask = new VsCodeTask
{
version = "2.0.0",
tasks = new System.Collections.Generic.List<TaskItem>
{
new TaskItem
{
label = "EF Core Power Tools: Reverse Engineer",
command = "efcpt",
type = "shell",
args = new System.Collections.Generic.List<string>
{
"${input:connection}",
"mssql",
},
group = "none",
presentation = new Presentation
{
reveal = "always",
},
problemMatcher = "$msCompile",
},
new TaskItem
{
label = "EF Core Power Tools: Update",
command = "dotnet",
type = "shell",
args = new System.Collections.Generic.List<string>
{
"tool",
"update",
"-g",
"--version",
$"{version}.0.*-*",
},
group = "none",
presentation = new Presentation
{
reveal = "always",
},
problemMatcher = "$msCompile",
},
},
inputs = new System.Collections.Generic.List<Input>
{
new Input
{
type = "promptString",
id = "connection",
description = "Enter the ADO.NET connection string to use",
@default = redactedConnectionString,
},
},
};

File.WriteAllText(path, JsonSerializer.Serialize(vsCodeTask, new JsonSerializerOptions { WriteIndented = true }), Encoding.UTF8);
}
}
}
1 change: 1 addition & 0 deletions src/GUI/RevEng.Shared/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Design", "CA1002:Do not expose generic lists", Justification = "Not useful")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Json")]
3 changes: 3 additions & 0 deletions src/GUI/efcpt.7/HostedServices/ScaffoldHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ErikEJ.EFCorePowerTools.Services;
using RevEng.Common;
using RevEng.Common.Cli;
using RevEng.Common.Cli.VsCode;
using RevEng.Core;
using Spectre.Console;

Expand Down Expand Up @@ -101,6 +102,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

var redactedConnectionString = new ConnectionStringResolver(commandOptions.ConnectionString).Redact();

VsCodeTaskHelper.GenerateTaskPayload(commandOptions.ProjectPath, Constants.Version, redactedConnectionString);

var readmePath = Providers.CreateReadme(commandOptions, Constants.CodeGeneration, redactedConnectionString);
var fileUri = new Uri(new Uri("file://"), readmePath);

Expand Down

0 comments on commit 6e4e80b

Please sign in to comment.