Uses dotnet tools from nixpkgs instead of nuget. New deps handling produces a lot of lockfiles. Added runtimeid to avoid hash missmatch
129 lines
3.9 KiB
Forth
129 lines
3.9 KiB
Forth
module Helpers
|
|
|
|
open Fake.Core
|
|
|
|
let initializeContext () =
|
|
let execContext = Context.FakeExecutionContext.Create false "build.fsx" [ ]
|
|
Context.setExecutionContext (Context.RuntimeContext.Fake execContext)
|
|
|
|
module Proc =
|
|
module Parallel =
|
|
open System
|
|
|
|
let locker = obj()
|
|
|
|
let colors =
|
|
[| ConsoleColor.Blue
|
|
ConsoleColor.Yellow
|
|
ConsoleColor.Magenta
|
|
ConsoleColor.Cyan
|
|
ConsoleColor.DarkBlue
|
|
ConsoleColor.DarkYellow
|
|
ConsoleColor.DarkMagenta
|
|
ConsoleColor.DarkCyan |]
|
|
|
|
let print color (colored: string) (line: string) =
|
|
lock locker
|
|
(fun () ->
|
|
let currentColor = Console.ForegroundColor
|
|
Console.ForegroundColor <- color
|
|
Console.Write colored
|
|
Console.ForegroundColor <- currentColor
|
|
Console.WriteLine line)
|
|
|
|
let onStdout index name (line: string) =
|
|
let color = colors.[index % colors.Length]
|
|
if isNull line then
|
|
print color $"{name}: --- END ---" ""
|
|
else if String.isNotNullOrEmpty line then
|
|
print color $"{name}: " line
|
|
|
|
let onStderr name (line: string) =
|
|
let color = ConsoleColor.Red
|
|
if isNull line |> not then
|
|
print color $"{name}: " line
|
|
|
|
let redirect (index, (name, createProcess)) =
|
|
createProcess
|
|
|> CreateProcess.redirectOutputIfNotRedirected
|
|
|> CreateProcess.withOutputEvents (onStdout index name) (onStderr name)
|
|
|
|
let printStarting indexed =
|
|
for (index, (name, c: CreateProcess<_>)) in indexed do
|
|
let color = colors.[index % colors.Length]
|
|
let wd =
|
|
c.WorkingDirectory
|
|
|> Option.defaultValue ""
|
|
let exe = c.Command.Executable
|
|
let args = c.Command.Arguments.ToStartInfo
|
|
print color $"{name}: {wd}> {exe} {args}" ""
|
|
|
|
let run cs =
|
|
cs
|
|
|> Seq.toArray
|
|
|> Array.indexed
|
|
|> fun x -> printStarting x; x
|
|
|> Array.map redirect
|
|
|> Array.Parallel.map Proc.run
|
|
|
|
let createProcess exe arg dir =
|
|
CreateProcess.fromRawCommandLine exe arg
|
|
|> CreateProcess.withWorkingDirectory dir
|
|
|> CreateProcess.ensureExitCode
|
|
|
|
let dotnet = createProcess "dotnet"
|
|
|
|
// NOTE: Uses dotnet-tools from nixpkgs
|
|
let fable = createProcess "fable"
|
|
let fantomas = createProcess "fantomas"
|
|
|
|
let bun =
|
|
let bunPath =
|
|
match ProcessUtils.tryFindFileOnPath "bun" with
|
|
| Some path -> path
|
|
| None ->
|
|
"bun was not found in path. Please install it and make sure it's available from your path. " +
|
|
"See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info"
|
|
|> failwith
|
|
|
|
createProcess bunPath
|
|
|
|
let bunx = createProcess "bunx"
|
|
|
|
type BundleMode =
|
|
| Prod
|
|
| Devel
|
|
| Watch
|
|
with
|
|
override this.ToString() =
|
|
match this with
|
|
| Prod -> "production"
|
|
| Devel -> "development"
|
|
| Watch -> "watch"
|
|
|
|
let viteCmd (m: BundleMode) outDir =
|
|
match m with
|
|
| Prod -> $"vite build -c ../../vite.config.js -m {m} --emptyOutDir --outDir {outDir}/public"
|
|
| Devel -> $"vite build -c ../../vite.config.js -m {m} --minify false --sourcemap true --emptyOutDir --outDir {outDir}/public"
|
|
| Watch -> "vite -c ../../vite.config.js"
|
|
|
|
let run proc arg dir =
|
|
proc arg dir
|
|
|> Proc.run
|
|
|> ignore
|
|
|
|
let runParallel processes =
|
|
processes
|
|
|> Proc.Parallel.run
|
|
|> ignore
|
|
|
|
let runOrDefault args =
|
|
try
|
|
match args with
|
|
| [| target |] -> Target.runOrDefault target
|
|
| _ ->
|
|
Target.runOrDefault "Run"
|
|
0
|
|
with e ->
|
|
printfn "%A" e
|
|
1 |