Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ The first priority is to get a non-pipeline based (i.e one-off) static site gene
dotnet tool install
dotnet paket restore

# Terminal 1
dotnet run -p ./src/Feather -- -w -C example

# Terminal 2
dotnet LiveReloadServer ./example/output
```

The above command will launch a live server that reloads the browser view as your source files change.

You can use `dotnet watch` (instead of `dotnet run`) to recompile and restart the tool on source change.

```
Expand Down Expand Up @@ -81,6 +79,6 @@ $FEATHER -w .
- [x] Primitive file watcher that regenerates on source change
- [x] Tailwind CSS support in .liquid files (via `twind/shim`)
- [x] Finalize on a HTML template library ([#1](https://github.com/srid/Feather/issues/1))
- [x] Add a dev server with live-reload
- [ ] static/ files
- [ ] Deploy something useful
- [ ] Add a dev server with live-reload
3 changes: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ nuget Fluid.Core 2.0.0-beta-1013
nuget Fluid.ViewEngine 2.0.0-beta-1013
nuget Microsoft.Extensions.FileProviders.Physical
nuget SJP.FsNotify
nuget FSharp.Control.Reactive
nuget FSharp.Control.Reactive
nuget Westwind.AspnetCore.LiveReload
1 change: 1 addition & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ NUGET
System.Threading.Thread (4.3)
System.Runtime (>= 4.3)
TimeZoneConverter (3.4)
Westwind.AspNetCore.LiveReload (0.3.1)
52 changes: 50 additions & 2 deletions src/Feather.Build/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,55 @@ open System.IO
open Fluid
open Fluid.ViewEngine
open Microsoft.Extensions.FileProviders
open System.Threading
open CommandLine
open SJP.FsNotify
open FSharp.Control.Reactive
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Westwind.AspNetCore.LiveReload
open Microsoft.Extensions.Logging

/// A simple live reloading server
module LiveReload =
let private configureServices (fp: PhysicalFileProvider) (services: IServiceCollection) =
services
.AddLiveReload(System.Action<LiveReloadConfiguration>(fun cfg ->
cfg.FolderToMonitor <- fp.Root
))
let private mkStaticFileOptions(fp) =
let opts = StaticFileOptions()
opts.FileProvider <- fp
opts
let private configureApp (fp: IFileProvider) (app : IApplicationBuilder) =
app
.UseLiveReload()
.UseStaticFiles(mkStaticFileOptions fp)
let private configureLogging (builder: ILoggingBuilder) =
let filter (_provider: string) (category: string) (l : LogLevel) =
not (
// Suppress verbose requesting logging from asp.net
category.Contains "Diagnostics"
|| l < LogLevel.Information
)
builder
.AddFilter(filter)
.AddConsole()
let private configureBuilder
(fp: PhysicalFileProvider)
(builder: IWebHostBuilder) : IWebHostBuilder =
builder
.UseWebRoot(fp.Root)
.Configure(configureApp fp >> ignore)
.ConfigureServices(configureServices fp >> ignore)
.ConfigureLogging(System.Action<ILoggingBuilder>(configureLogging >> ignore))
let run (fp: PhysicalFileProvider) =
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
System.Action<IWebHostBuilder>(configureBuilder fp >> ignore))
.Build()
.RunAsync()

module Liquid =
let private mkEngineOpts(fp: IFileProvider) =
Expand Down Expand Up @@ -68,7 +113,10 @@ module CLI =
printfn "! %s" evt.Name
generateOnce(Liquid.Engine fp, x, outputPath))
watcher.Start()
Thread.Sleep(Timeout.Infinite)
use outputFp = new PhysicalFileProvider(outputPath)
async {
return! LiveReload.run outputFp |> Async.AwaitTask
} |> Async.RunSynchronously
obs.Dispose()
0 // return an integer exit code
| _ ->
Expand Down
3 changes: 2 additions & 1 deletion src/Feather.Build/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Fluid.ViewEngine
Microsoft.Extensions.FileProviders.Physical
CommandLineParser
SJP.FsNotify
FSharp.Control.Reactive
FSharp.Control.Reactive
Westwind.AspnetCore.LiveReload
1 change: 1 addition & 0 deletions src/Feather/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FSharp.Core