Skip to content

Instantly share code, notes, and snippets.

@JorgeVV
Created August 23, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JorgeVV/84d5cf95ebcc25f56744f00cebcf9e60 to your computer and use it in GitHub Desktop.
Save JorgeVV/84d5cf95ebcc25f56744f00cebcf9e60 to your computer and use it in GitHub Desktop.
Suave FAKE build watcher
// 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