Browse Source

add npm stuff for linux/macos

pull/438/head
JT 10 months ago
parent
commit
0325fe01a6
  1. 81
      StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs
  2. 2
      StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs

81
StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using Avalonia.Controls;
using DynamicData;
using FluentAvalonia.UI.Controls;
using NLog;
using StabilityMatrix.Avalonia.Languages;
@ -32,10 +33,13 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
private DirectoryPath PythonDir => AssetsDir.JoinDir("Python310");
public bool IsPythonInstalled => PythonDir.JoinFile(PyRunner.RelativePythonDllPath).Exists;
private DirectoryPath PortableGitInstallDir => HomeDir + "PortableGit";
public string GitBinPath => PortableGitInstallDir + "bin";
private DirectoryPath NodeDir => AssetsDir.JoinDir("nodejs");
private string NpmPath => Path.Combine(NodeDir, "bin", "npm");
private bool IsNodeInstalled => File.Exists(NpmPath);
// Cached store of whether or not git is installed
private bool? isGitInstalled;
@ -231,23 +235,80 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
return ProcessRunner.RunBashCommand(args.Prepend("git").ToArray(), workingDirectory ?? "");
}
[UnsupportedOSPlatform("Linux")]
[UnsupportedOSPlatform("macOS")]
public Task InstallTkinterIfNecessary(IProgress<ProgressReport>? progress = null)
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
public async Task RunNpm(ProcessArgs args, string? workingDirectory = null)
{
throw new PlatformNotSupportedException();
var command = args.Prepend(NpmPath);
var result = await ProcessRunner.RunBashCommand(command.ToArray(), workingDirectory ?? "");
if (result.ExitCode != 0)
{
Logger.Error(
"npm command [{Command}] failed with exit code " + "{ExitCode}:\n{StdOut}\n{StdErr}",
command,
result.ExitCode,
result.StandardOutput,
result.StandardError
);
throw new ProcessException(
$"npm command [{command}] failed with exit code"
+ $" {result.ExitCode}:\n{result.StandardOutput}\n{result.StandardError}"
);
}
}
[UnsupportedOSPlatform("Linux")]
[UnsupportedOSPlatform("macOS")]
public Task RunNpm(ProcessArgs args, string? workingDirectory = null)
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
public async Task InstallNodeIfNecessary(IProgress<ProgressReport>? progress = null)
{
throw new PlatformNotSupportedException();
if (IsNodeInstalled)
{
Logger.Info("node already installed");
return;
}
Logger.Info("Downloading node");
var downloadUrl = Compat.IsMacOS
? "https://nodejs.org/dist/v20.11.0/node-v20.11.0-darwin-arm64.tar.gz"
: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-linux-x64.tar.xz";
var nodeDownloadPath = Compat.IsMacOS
? Path.Combine(AssetsDir, "nodejs.tar.gz")
: Path.Combine(AssetsDir, "nodejs.tar.xz");
await downloadService.DownloadToFileAsync(downloadUrl, nodeDownloadPath, progress: progress);
Logger.Info("Installing node");
progress?.Report(
new ProgressReport(
progress: 0.5f,
isIndeterminate: true,
type: ProgressType.Generic,
message: "Installing prerequisites..."
)
);
// unzip
await ArchiveHelper.Extract(nodeDownloadPath, AssetsDir, progress);
var nodeDir = Compat.IsMacOS
? AssetsDir.JoinDir("node-v20.11.0-darwin-arm64")
: AssetsDir.JoinDir("node-v20.11.0-linux-x64");
Directory.Move(nodeDir, NodeDir);
progress?.Report(
new ProgressReport(progress: 1f, message: "Node install complete", type: ProgressType.Generic)
);
File.Delete(nodeDownloadPath);
}
[UnsupportedOSPlatform("Linux")]
[UnsupportedOSPlatform("macOS")]
public Task InstallNodeIfNecessary(IProgress<ProgressReport>? progress = null)
public Task InstallTkinterIfNecessary(IProgress<ProgressReport>? progress = null)
{
throw new PlatformNotSupportedException();
}

2
StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs

@ -26,7 +26,7 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
private const string VcRedistDownloadUrl = "https://aka.ms/vs/16/release/vc_redist.x64.exe";
private const string TkinterDownloadUrl =
"https://cdn.lykos.ai/tkinter-cpython-embedded-3.10.11-win-x64.zip";
private const string NodeDownloadUrl = "https://cdn.lykos.ai/nodejs.zip";
private const string NodeDownloadUrl = "https://nodejs.org/dist/v20.11.0/node-v20.11.0-win-x64.zip";
private string HomeDir => settingsManager.LibraryDir;

Loading…
Cancel
Save