Skip to content

Commit

Permalink
Try to install npm dependencies if not present before build.
Browse files Browse the repository at this point in the history
  • Loading branch information
allisterb committed Dec 11, 2024
1 parent 604ffa2 commit 4ab63e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/Stratis.VS.SolidityProjectBuildTasks/CompileContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Text;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand All @@ -30,8 +31,26 @@ public class CompileContracts : Task

public override bool Execute()
{
if (!File.Exists(Path.Combine(ProjectDir, "node_modules", "solc", "solc.js")))
{
Log.LogMessage(MessageImportance.High, "Installing NPM dependencies in project directory {0}...", ProjectDir);

var npmoutput = RunCmd("cmd.exe", "/c npm install", ProjectDir);
if (CheckRunCmdError(npmoutput))
{
Log.LogError("Could not install NPM dependencies: " + GetRunCmdError(npmoutput));
}
else
{
Log.LogMessage(MessageImportance.High, ((string)npmoutput["stdout"]).Trim());
}
}
var solcpath = File.Exists(Path.Combine(ProjectDir, "node_modules", "solc", "solc.js")) ? Path.Combine(ProjectDir, "node_modules", "solc", "solc.js") :
Path.Combine(ExtDir, "node_modules", "solc", "solc.js");
if (!File.Exists(Path.Combine(ProjectDir, "node_modules", "solc", "solc.js")))
{
Log.LogWarning("solc compiler not present in project node_modules directory. Falling back to embedded compiler.");
}
var cmdline = "node \"" + solcpath + "\" --standard-json --base-path=\"" + ProjectDir + "\"" + " --include-path=\"" + Path.Combine(ProjectDir, "node_modules") + "\"";
var sources = Contracts.ToDictionary(k => k.GetMetadata("Filename"), v => new Source() { Urls = new[] { Path.Combine(v.GetMetadata("RelativeDir"), v.ItemSpec) } });

Expand Down Expand Up @@ -174,7 +193,7 @@ public override bool Execute()
{
if (cs.evm.bytecode._object != null)
{
File.WriteAllBytes(Path.Combine(outputdir, c.Key + ".bin"), FromHexString(c.Value.Values.First().evm.bytecode._object));
File.WriteAllText(Path.Combine(outputdir, c.Key + ".bin"), c.Value.Values.First().evm.bytecode._object);
}
if (!string.IsNullOrEmpty(cs.evm.bytecode.opcodes))
{
Expand Down Expand Up @@ -282,9 +301,9 @@ protected bool InstallSolidityLanguageServer()

protected bool InstallNethereumGeneratorToolIfNotPresent()
{
Log.LogMessage(MessageImportance.High, $"Installing .NET tool manifest...");
if (!File.Exists(Path.Combine(ProjectDir, ".config", "dotnet-tools.json")))
{
Log.LogMessage(MessageImportance.High, $"Installing .NET tool manifest...");
if (!CheckRunCmdOutput(RunCmd("cmd.exe", "/c dotnet new tool-manifest", ProjectDir), "was created successfully"))
{
Log.LogError("Could not install .NET tools manifest in " + ProjectDir);
Expand Down
5 changes: 2 additions & 3 deletions src/Stratis.VS.StratisEVM/SolidityLanguageSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"solidity.telemetry": false,
"solidity.maxNumberOfProblems": 1,
"solidity.enabledAsYouTypeCompilationErrorCheck": true,
"solidity.defaultCompiler": "embedded",
"solidity.compileUsingRemoteVersion": "latest",
"solidity.linter": "solhint"
"solidity.defaultCompiler": "localNodeModule",
"solidity.linter": "solhint"
}

0 comments on commit 4ab63e7

Please sign in to comment.