Class: Mlo::Jekyll::BrowserSync::Command
- Inherits:
-
Jekyll::Command
- Object
- Jekyll::Command
- Mlo::Jekyll::BrowserSync::Command
- Defined in:
- lib/jekyll-browsersync/command.rb
Class Method Summary collapse
Class Method Details
.init_with_program(prog) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jekyll-browsersync/command.rb', line 10 def self.init_with_program(prog) prog.command(:browsersync) do |c| c.syntax "browsersync [options]" c.description "Serve the site using Browsersync" .each { |opt| c.option(*opt) } (c) c.action { |args, | process(args, ) } end end |
.options ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/jekyll-browsersync/command.rb', line 23 def self. [ ["host", "-H", "--host [HOST]", "Host to bind to"], ["port", "-P", "--port [PORT]", "Port to listen on"], ["open", "-o", "--open", "Launch your site in a browser"], ["browsersync", "-e", "--cli [PATH]", "Path to browsersync CLI"], ] end |
.process(args = [], options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jekyll-browsersync/command.rb', line 32 def self.process(args = [], = {}) config = () config["serving"] = true config["watch"] = true unless config.key?("watch") cli = config["browsersync"] || self.browsersync() args << "--server #{config["destination"]}" args << "--files #{config["destination"]}" args << "--port #{config["port"]}" args << "--host #{config["host"]}" args << "--no-open" unless config["open"] cmd = "#{cli} start #{args.join(" ")}" if `#{cli} --version 2>/dev/null`.empty? raise "Unable to locate browser-sync binary." end ::Jekyll::Commands::Build.process(config) PTY.spawn(cmd) do |stdout, stdin, pid| trap("INT") { Process.kill "INT", pid } begin stdout.each { |line| ::Jekyll.logger.info(line.rstrip) } rescue end end end |