Class: Lilac::CLI::Subcommand::Preview

Inherits:
Base
  • Object
show all
Defined in:
lib/lilac/cli/subcommand/preview.rb

Instance Method Summary collapse

Methods inherited from Base

help_text, #initialize

Constructor Details

This class inherits a constructor from Lilac::CLI::Subcommand::Base

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lilac/cli/subcommand/preview.rb', line 11

def run
  opts = parse_opts

  # `preview` only needs the output_dir resolved; target / mrbc /
  # vendor paths are irrelevant because we're serving an already-
  # built `dist/`. Reuse `Config.load` so `lilac.config.rb` is
  # still consulted for `output_dir`.
  config = Config.load(
    root: opts[:root],
    components_dir: opts[:components],
    pages_dir: opts[:pages],
    output_dir: opts[:output],
    public_dir: opts[:public],
  )

  PreviewServer.new(
    config.output_dir,
    host: opts[:host] || PreviewServer::DEFAULT_HOST,
    port: opts[:port] || PreviewServer::DEFAULT_PORT,
    out: @out,
    err: @err,
  ).start
  0
end