-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommands.cs
More file actions
53 lines (47 loc) · 1.79 KB
/
Copy pathCommands.cs
File metadata and controls
53 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Olive;
namespace MSharp.Build
{
class Commands
{
static Dictionary<string, FileInfo> Exes = new Dictionary<string, FileInfo>();
public static FileInfo Chocolaty => FindExe("choco");
public static FileInfo Yarn => FindExe("yarn");
public static FileInfo NodeJs => FindExe("npm");
public static FileInfo TypeScript => FindExe("tsc");
public static FileInfo WebPack => FindExe("webpack");
public static FileInfo DotNet => FindExe("dotnet");
public static FileInfo APT => FindExe("apt");
public static FileInfo APT_GET => FindExe("apt-get");
public static FileInfo Where
{
get
{
if (Runtime.IsWindows())
return System32("WHERE.exe").ExistsOrThrow();
else if (Runtime.IsLinux())
return "/usr/bin/whereis".AsFile();
throw new NotSupportedException(Runtime.OS.ToString());
}
}
public static FileInfo FindExe(string fileInPathEnv)
{
if (!Exes.ContainsKey(fileInPathEnv))
{
var output = Where.Execute(fileInPathEnv, configuration: x => x.StartInfo.WorkingDirectory = string.Empty);
Exes.Add(fileInPathEnv, output.Trim().ToLines().Select(x => x.AsFile()).First(x => x.Extension.HasValue()));
}
return Exes[fileInPathEnv];
}
public static FileInfo Powershell => FindExe("powershell");
static FileInfo System32(string relative)
{
return Environment.SpecialFolder.Windows
.GetFile(Path.Combine("System32", relative))
.ExistsOrThrow();
}
}
}