Class: Rackula::Command::Generate
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Rackula::Command::Generate
- Defined in:
- lib/rackula/command/generate.rb
Overview
Server setup commands.
Instance Method Summary collapse
- #copy_and_fetch(port, root) ⇒ Object
- #invoke(parent) ⇒ Object
- #run(address, root) ⇒ Object
- #serve(endpoint, root) ⇒ Object
Instance Method Details
#copy_and_fetch(port, root) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rackula/command/generate.rb', line 47 def copy_and_fetch(port, root) output_path = root + @options[:output_path] if output_path.exist? if @options[:force] # Delete any existing stuff: FileUtils.rm_rf(output_path.to_s) else # puts "Failing due to error..." raise Samovar::Failure.new("Output path already exists!") end end # Copy all public assets: asset_pattern = root + @options[:public] + '*' Dir.glob(asset_pattern.to_s).each do |path| FileUtils.cp_r(path, output_path) end # Generate HTML pages: system!("wget", "--mirror", "--recursive", "--continue", "--convert-links", "--adjust-extension", "--no-host-directories", "--directory-prefix", output_path.to_s, "http://localhost:#{port}") end |
#invoke(parent) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rackula/command/generate.rb', line 97 def invoke(parent) Async::Reactor.run do endpoint = Async::IO::Endpoint.tcp("localhost", 0, reuse_port: true) # We bind to a socket to generate a temporary port: endpoint.bind do |socket| run(socket.local_address, Pathname.new(parent.root)) end end end |
#run(address, root) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rackula/command/generate.rb', line 85 def run(address, root) endpoint = Async::IO::Endpoint.tcp("localhost", address.ip_port, reuse_port: true) puts "Setting up container to serve site on port #{address.ip_port}..." container = serve(endpoint, root) # puts "Copy and fetch site to static..." copy_and_fetch(address.ip_port, root) ensure container.stop if container end |
#serve(endpoint, root) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rackula/command/generate.rb', line 70 def serve(endpoint, root) container_class = Async::Container::Threaded config_path = root + @options[:config] app, = Rack::Builder.parse_file(config_path.to_s) container = container_class.new(concurrency: @options[:concurrency]) do server = Falcon::Server.new(app, [ endpoint ]) server.run end end |