Skip to content

Instantly share code, notes, and snippets.

@RNGKing
Last active October 2, 2024 22:55
Show Gist options
  • Save RNGKing/241f6ecda25c44bfa9b360fc416b7e1a to your computer and use it in GitHub Desktop.
Save RNGKing/241f6ecda25c44bfa9b360fc416b7e1a to your computer and use it in GitHub Desktop.
simplified build script that executes the gleam_dotnet evnvironment variable with args
#!/usr/bin/env -S dotnet fsi
open System
open System.Diagnostics
open System.Threading.Tasks
type CommandResult =
{ ExitCode: int
StandardOutput: string
StandardError: string }
let executeTask path args =
async{
printfn "We are trying to execute gleam dotnet"
let! ct = Async.CancellationToken
let startInfo = ProcessStartInfo()
startInfo.FileName <- path
startInfo.RedirectStandardOutput <- true
startInfo.RedirectStandardError <- true
startInfo.UseShellExecute <- false
startInfo.CreateNoWindow <- true
for arg in args do
startInfo.ArgumentList.Add(arg)
use p = new Process()
p.StartInfo <- startInfo
p.Start() |> ignore
let outTask =
Task.WhenAll([|
p.StandardOutput.ReadToEndAsync(ct);
p.StandardError.ReadToEndAsync(ct) |])
do! p.WaitForExitAsync(ct) |> Async.AwaitTask
let! out = outTask |> Async.AwaitTask
return
{ ExitCode = p.ExitCode
StandardOutput = out.[0]
StandardError = out.[1]}
}
let execute_gleam_build path args =
let execute_result = executeTask path args |> Async.RunSynchronously
if execute_result.ExitCode = 0 then
printfn "%s" execute_result.StandardOutput
else
eprintfn "%s" execute_result.StandardError
Environment.Exit(execute_result.ExitCode)
let args : string array = fsi.CommandLineArgs |> Array.tail
let dotnet_gleam = Environment.GetEnvironmentVariable("GLEAM_DOTNET")
match dotnet_gleam with
| null -> printfn "No environement variable of the name: DOTNET_GLEAM found"
| _ -> execute_gleam_build dotnet_gleam args
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment