-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
291 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
open Fake | ||
open Fake.Core | ||
open Fake.IO | ||
open Fake.IO.FileSystemOperators | ||
open System.IO.Compression | ||
|
||
open BuildHelpers | ||
|
||
initializeContext() | ||
|
||
module Paths = | ||
let private publishDir = Path.getFullName "publish" | ||
let private srcDir = Path.getFullName "src" | ||
let projectSrc = srcDir </> "Funcaster" | ||
let projectPublish = publishDir </> "Funcaster" | ||
|
||
// Targets | ||
let clean proj = [ proj </> "bin"; proj </> "obj" ] |> Shell.cleanDirs | ||
let ensureDevFilesDeleted proj = | ||
[ | ||
proj </> "appsettings.development.json" | ||
proj </> "local.settings.json" | ||
] |> File.deleteAll | ||
|
||
let publish srcDir publishDir = | ||
clean srcDir | ||
publishDir |> Directory.delete | ||
Tools.dotnet $"publish -c Release -o \"%s{publishDir}\"" srcDir | ||
publishDir |> ensureDevFilesDeleted | ||
|
||
Target.create "Run" (fun _ -> | ||
Tools.dotnet "watch msbuild /t:RunFunctions" Paths.projectSrc | ||
) | ||
|
||
Target.create "Publish" (fun _ -> | ||
publish Paths.projectSrc Paths.projectPublish | ||
let zipFile = Paths.projectPublish + ".zip" | ||
File.delete zipFile | ||
ZipFile.CreateFromDirectory(Paths.projectPublish, zipFile) | ||
) | ||
|
||
let dependencies = [] // For future use | ||
|
||
[<EntryPoint>] | ||
let main args = runOrDefault args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="BuildHelpers.fs" /> | ||
<Compile Include="Build.fs" /> | ||
</ItemGroup> | ||
<Import Project=".paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
module BuildHelpers | ||
|
||
open Fake.Core | ||
open Fake.DotNet | ||
|
||
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 | ||
|
||
module Tools = | ||
let private findTool tool winTool = | ||
let tool = if Environment.isUnix then tool else winTool | ||
match ProcessUtils.tryFindFileOnPath tool with | ||
| Some t -> t | ||
| _ -> | ||
let errorMsg = | ||
tool + " was not found in path. " + | ||
"Please install it and make sure it's available from your path. " | ||
failwith errorMsg | ||
|
||
let private runTool (cmd:string) args workingDir = | ||
let arguments = args |> String.split ' ' |> Arguments.OfArgs | ||
Command.RawCommand (cmd, arguments) | ||
|> CreateProcess.fromCommand | ||
|> CreateProcess.withWorkingDirectory workingDir | ||
|> CreateProcess.ensureExitCode | ||
|> Proc.run | ||
|> ignore | ||
|
||
let dotnet cmd workingDir = | ||
let result = | ||
DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd "" | ||
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.