-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (54 loc) · 1.99 KB
/
Program.cs
File metadata and controls
62 lines (54 loc) · 1.99 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
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using CliWrap;
namespace PackedPrettier;
internal class Program
{
static Task<int> Main(string[] args)
{
var prettierCLi = GetPlatformPrettier(AppContext.BaseDirectory);
return ExecutePrettierAsync(prettierCLi, args.Length > 0 ? args : new[] { "--help" });
}
private static async Task<int> ExecutePrettierAsync(string prettierCLi, string[] args)
{
var stdOut = Console.OpenStandardOutput();
var stdErr = Console.OpenStandardError();
var stdIn = Console.OpenStandardInput();
var result = await Cli.Wrap(prettierCLi)
.WithArguments(args)
.WithValidation(CommandResultValidation.None)
.WithStandardOutputPipe(PipeTarget.ToStream(stdOut))
.WithStandardErrorPipe(PipeTarget.ToStream(stdErr))
.WithStandardInputPipe(PipeSource.FromStream(stdIn, true))
.ExecuteAsync()
.ConfigureAwait(false);
return result.ExitCode;
}
private static string GetPlatformPrettier(string baseDirectory)
{
if (!Environment.Is64BitOperatingSystem)
{
throw new PlatformNotSupportedException(
"Only 64bit operating systems are supported."
);
}
switch (Environment.OSVersion.Platform)
{
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.Win32NT:
case PlatformID.WinCE:
return Path.Join(baseDirectory, "packed", "win-x64", "prettier.exe");
case PlatformID.Unix:
return Path.Join(baseDirectory, "packed", "linux-x64", "prettier");
case PlatformID.Xbox:
case PlatformID.MacOSX:
default:
throw new PlatformNotSupportedException(
$"Platform {Environment.OSVersion.Platform} is not supported."
);
}
}
}