Skip to content

Commit 8196af4

Browse files
committed
WIP handle case of no node.js
1 parent cc55ad5 commit 8196af4

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

Editor/ShellProcess.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Diagnostics;
1+
using System;
2+
using System.Diagnostics;
23
using Debug = UnityEngine.Debug;
34

45
namespace Editor {
@@ -42,6 +43,42 @@ public static ProcessStartInfo GetStartInfoForCommand(string workingDirectory, s
4243
};
4344
return procStartInfo;
4445
}
46+
47+
public static string FindExecutableOnPath(string executable) {
48+
#if UNITY_EDITOR_WIN
49+
var proc = new Process();
50+
var startInfo = GetShellStartInfoForCommand($"where {executable}", Environment.CurrentDirectory);
51+
startInfo.RedirectStandardOutput = true;
52+
proc.StartInfo = startInfo;
53+
proc.Start();
54+
var res = proc.StandardOutput.ReadToEnd().Split("\r\n")[0];
55+
return res;
56+
#else
57+
var proc = new Process();
58+
var startInfo = GetShellStartInfoForCommand($"command -v {executable}", Environment.CurrentDirectory);
59+
startInfo.RedirectStandardOutput = true;
60+
proc.StartInfo = startInfo;
61+
proc.Start();
62+
var res = proc.StandardOutput.ReadToEnd().Split("\n")[0];
63+
return res;
64+
#endif
65+
}
66+
67+
public static string FindNodeBinPath() {
68+
#if UNITY_EDITOR_WIN
69+
// Windows is ensured to be in PATH
70+
return FindExecutableOnPath("node");
71+
#else
72+
// We can check via PATH first -
73+
var pathExecutable = FindExecutableOnPath("node");
74+
if (pathExecutable != null) {
75+
return pathExecutable;
76+
}
77+
78+
Debug.LogWarning("Node is not on your PATH");
79+
return null;
80+
#endif
81+
}
4582

4683
/// <summary>
4784
/// Gets the operating system specific ProcessStartInfo for the given command

Editor/TypescriptServices/Compiler/TypescriptCompilationService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ namespace Airship.Editor {
3232
public static class TypescriptCompilationService {
3333
private const string TsCompilerService = "Typescript Compiler Service";
3434

35+
private static string _nodePath;
36+
public static string NodePath {
37+
get {
38+
if (_nodePath == null) {
39+
var executable = ShellProcess.FindNodeBinPath().Trim();
40+
if (executable != "") {
41+
_nodePath = Path.GetDirectoryName(executable);
42+
return _nodePath;
43+
}
44+
45+
return null;
46+
}
47+
48+
return _nodePath;
49+
}
50+
}
51+
3552
/// <summary>
3653
/// True if the compiler is running in watch mode
3754
/// </summary>

Editor/TypescriptServices/TypescriptServices.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public static void OnLoad() {
4141
#endif
4242
// If a server or clone - ignore
4343
if (!IsValidEditor) return;
44+
45+
if (TypescriptCompilationService.NodePath == null) {
46+
Debug.LogWarning("[TypescriptServices] Node.js could not be found on your path, please read https://docs.airship.gg/getting-started/installing-airship for how to set up Airship correctly.");
47+
Debug.LogWarning("\tIf you already installed Node.js, restart Unity and Unity Hub and try again.");
48+
return;
49+
}
50+
4451
EditorApplication.delayCall += OnLoadDeferred;
4552

4653
EditorApplication.playModeStateChanged += PlayModeStateChanged;

0 commit comments

Comments
 (0)