Skip to content

Commit

Permalink
Add InstallNPMPackages command handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
allisterb committed Nov 21, 2024
1 parent d73234a commit e7923ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Stratis.VS.StratisEVM/SolidityCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.VisualStudio.Threading;

using Stratis.DevEx;
using static Microsoft.VisualStudio.ProjectSystem.VS.HResult.Ole;

namespace Stratis.VS.StratisEVM
{
Expand Down Expand Up @@ -84,5 +85,21 @@ public static async Task CompileFileAsync(string file, string workspaceDir)
}
}
}

public static async Task InstallNPMPackagesAsync(string projectDir)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
VSUtil.ShowLogOutputWindowPane(ServiceProvider.GlobalProvider, "Stratis EVM");
VSUtil.LogInfo("Stratis EVM", string.Format("Installing NPM dependencies in project directory {0}...", projectDir));
await TaskScheduler.Default;
var output = await RunCmdAsync("cmd.exe", "/c npm install", projectDir);
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (CheckRunCmdError(output))
{
VSUtil.LogError("Stratis EVM", "Could not install NPM dependencies: " + GetRunCmdError(output));
return;
}
VSUtil.LogInfo("Stratis EVM", ((string)output["stdout"]).Trim());
}
}
}
13 changes: 11 additions & 2 deletions src/Stratis.VS.StratisEVM/SolidityProjectMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private SolidityProjectMenuCommands(AsyncPackage package, OleMenuCommandService
menuItem.ParametersDescription = "$";
commandService.AddCommand(menuItem);
menuCommandID = new CommandID(CommandSet, InstallPackagesCommandId);
menuItem = new OleMenuCommand(CompileFile, menuCommandID)
menuItem = new OleMenuCommand(InstallNPMPackages, menuCommandID)
{
Supported = false
};
Expand Down Expand Up @@ -89,8 +89,17 @@ private async Task CompileFileAsync()
await SolidityCompiler.CompileFileAsync(file, dir);
}

private async Task InstallNPMPackagesAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)await ServiceProvider.GetServiceAsync(typeof(EnvDTE.DTE));
var dir = Path.GetDirectoryName(dte.SelectedItems.Item(1).ProjectItem.ContainingProject.FileName);
await SolidityCompiler.InstallNPMPackagesAsync(dir);
}

#pragma warning disable VSTHRD110, CS4014
private void CompileFile(object sender, EventArgs e) => CompileFileAsync();
#pragma warning restore VSTHRD110, CS4014
private void InstallNPMPackages(object sender, EventArgs e) => InstallNPMPackagesAsync();
#pragma warning restore VSTHRD110, CS4014
}
}

0 comments on commit e7923ef

Please sign in to comment.