Skip to content

Commit

Permalink
Pass WATCH define in case of watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Cieslak committed Apr 24, 2020
1 parent b0c5a02 commit b8fffa9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Fornax/Fornax.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let createFileWatcher dir handler =
fileSystemWatcher.Deleted.Add handler

/// Adding handler to trigger websocket/live refresh
let contentChangedHandler _ =
let contentChangedHandler _ =
signalContentChanged.Trigger(Choice<unit,Error>.Choice1Of2 ())
signalContentChanged.Trigger(Choice<unit,Error>.Choice1Of2 ())
fileSystemWatcher.Created.Add contentChangedHandler
Expand Down Expand Up @@ -152,7 +152,7 @@ let main argv =
0
| Some Build ->
try
do generateFolder cwd
do generateFolder cwd false
0
with
| FornaxGeneratorException message ->
Expand All @@ -167,7 +167,7 @@ let main argv =

let guardedGenerate () =
try
generateFolder cwd
do generateFolder cwd true
with
| FornaxGeneratorException message ->
printfn "%s%s%s" message Environment.NewLine waitingForChangesMessage
Expand Down
17 changes: 9 additions & 8 deletions src/Fornax/Generator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module EvaluatorHelpers =

let private sbOut = StringBuilder()
let private sbErr = StringBuilder()
let internal fsi () =
let internal fsi (isWatch: bool) =
let refs =
ProjectSystem.FSIRefs.getRefs ()
|> List.map (fun n -> sprintf "-r:%s" n)
Expand All @@ -29,8 +29,9 @@ module EvaluatorHelpers =
let argv = [|
yield! refs
yield "--noframework"
yield "/temp/fsi.exe";
yield "--define:FORNAX"|]
if isWatch then yield "--define:WATCH"
yield "--define:FORNAX"
yield "/temp/fsi.exe"; |]
FsiEvaluationSession.Create(fsiConfig, argv, inStream, outStream, errStream)
with
| ex ->
Expand Down Expand Up @@ -180,12 +181,12 @@ module GeneratorEvaluator =
|> Option.bind (tryUnbox<string>)
|> function
| Some s -> Ok (Encoding.UTF8.GetBytes s)
| None ->
| None ->
result
|> Option.bind (tryUnbox<byte[]>)
|> function
| Some bytes -> Ok bytes
| None ->
| None ->
sprintf "HTML generator %s couldn't be compiled" generatorPath |> Error)

///`generatorPath` - absolute path to `.fsx` file containing the generator
Expand All @@ -200,7 +201,7 @@ module GeneratorEvaluator =
result
|> Option.bind (tryUnbox<(string * string) list>)
|> function
| Some files -> Ok (files |> List.map (fun (o, r) -> o, Encoding.UTF8.GetBytes r))
| Some files -> Ok (files |> List.map (fun (o, r) -> o, Encoding.UTF8.GetBytes r))
| None ->
result
|> Option.bind (tryUnbox<(string * byte[]) list>)
Expand Down Expand Up @@ -421,7 +422,7 @@ module Logger =
let errorfn str = Printf.kprintf (fun s -> use c = consoleColor ConsoleColor.Red in printfn "%s" s) str

///`projectRoot` - path to the root of website
let generateFolder (projectRoot : string) =
let generateFolder (projectRoot : string) (isWatch: bool) =

let relative toPath fromPath =
let toUri = Uri(toPath)
Expand All @@ -432,7 +433,7 @@ let generateFolder (projectRoot : string) =
if projectRoot.EndsWith (string Path.DirectorySeparatorChar) then projectRoot
else projectRoot + (string Path.DirectorySeparatorChar)

use fsi = EvaluatorHelpers.fsi ()
use fsi = EvaluatorHelpers.fsi (isWatch)
let sc = SiteContents ()
let config =
let configPath = Path.Combine(projectRoot, "config.fsx")
Expand Down

0 comments on commit b8fffa9

Please sign in to comment.