Class: Lilac::CLI::DevServer
- Inherits:
-
Object
- Object
- Lilac::CLI::DevServer
- Defined in:
- lib/lilac/cli/dev_server.rb
Overview
Long-running dev server: initial build, file watch, live reload.
1. Builds `components/*.lil + pages/*.html` → `output_dir/` once,
with the live-reload client script injected
2. Wraps `Wsv::Server` with a custom app that routes
`/__lilac/livereload` to the SSE pub/sub, everything else
to the default static-file `Wsv::App`
3. Starts the file watcher; on debounced change events,
rebuilds and notifies all SSE subscribers, which reload
their pages
Defined Under Namespace
Classes: RoutingApp
Constant Summary collapse
- DEFAULT_HOST =
"127.0.0.1"- DEFAULT_PORT =
5173
Instance Method Summary collapse
-
#initialize(config, host: DEFAULT_HOST, port: DEFAULT_PORT, out: $stdout, err: $stderr) ⇒ DevServer
constructor
A new instance of DevServer.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(config, host: DEFAULT_HOST, port: DEFAULT_PORT, out: $stdout, err: $stderr) ⇒ DevServer
Returns a new instance of DevServer.
25 26 27 28 29 30 31 32 |
# File 'lib/lilac/cli/dev_server.rb', line 25 def initialize(config, host: DEFAULT_HOST, port: DEFAULT_PORT, out: $stdout, err: $stderr) @config = config @host = host @port = port @out = out @err = err @live_reload = LiveReload.new end |
Instance Method Details
#start ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lilac/cli/dev_server.rb', line 34 def start rebuild! # Watch public/ too, so changes to vendored assets (vendor/*.js, # favicons, images) also trigger a rebuild + reload. @watcher = Watcher.new(watched_paths) { rebuild_and_notify } @watcher.start @server = build_server @out.puts @server.start ensure @watcher&.stop end |
#stop ⇒ Object
48 49 50 51 |
# File 'lib/lilac/cli/dev_server.rb', line 48 def stop @server&.stop @watcher&.stop end |