Suave FAKE build watcher
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
// include Fake libs | |
#r "./packages/FAKE/tools/FakeLib.dll" | |
open Fake | |
open Fake.ProcessHelper | |
// Directories | |
[<Literal>] | |
let BuildDir = "./build/" | |
[<Literal>] | |
let DeployDir = "./deploy/" | |
// version info | |
[<Literal>] | |
let Version = "0.1" // or retrieve from CI server | |
// Filesets | |
let appReferences = | |
!! "/**/*.csproj" | |
++ "/**/*.fsproj" | |
let kill _ = | |
do Async.CancelDefaultToken () | |
killAllCreatedProcesses () | |
let clean _ = do CleanDirs [BuildDir; DeployDir] | |
let build _ = | |
// compile all projects below src/app/ | |
MSBuildDebug BuildDir "Build" appReferences | |
|> Log "AppBuild-Output: " | |
let run _ = | |
do traceFAKE "About to run process. Press 'Q' to quit it once started." | |
async { | |
return! asyncShellExec { | |
Program = BuildDir @@ "Main.exe" // Change exe name. | |
WorkingDirectory = __SOURCE_DIRECTORY__ | |
CommandLine = System.String.Empty | |
Args = [] | |
} | |
} |> Async.Ignore |> Async.Start | |
// Targets | |
do Target "Clean" clean | |
Target "Build" build | |
Target "Deploy" (fun _ -> | |
!! (BuildDir + "/**/*.*") | |
-- "*.zip" | |
|> Zip BuildDir (DeployDir + "ApplicationName." + Version + ".zip") | |
) | |
Target "Watch" (fun _ -> | |
use watcher = !! "src/**/*.fs" |> WatchChanges (fun changes -> | |
do tracefn "%A" changes | |
|> kill | |
// |> clean | |
|> build | |
|> run | |
) | |
do kill () | |
|> run | |
let readChar () = (System.Console.ReadKey true).KeyChar | |
let rec loop = function | |
| 'q' | 'Q' -> do watcher.Dispose () | |
| _ -> loop (readChar ()) | |
readChar () |> loop | |
) | |
// Build order | |
"Clean" | |
==> "Build" | |
==> "Watch" <=> "Deploy" | |
// start build | |
do RunTargetOrDefault "Build" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment