Class: Bridgetown::Commands::Start
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Bridgetown::Commands::Start
- Extended by:
- BuildOptions, Summarizable
- Includes:
- ConfigurationOverridable
- Defined in:
- lib/bridgetown-core/commands/start.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#start ⇒ Object
rubocop:todo Metrics/PerceivedComplexity.
Methods included from BuildOptions
Methods included from Summarizable
Methods included from ConfigurationOverridable
#configuration_with_overrides, included
Class Method Details
.banner ⇒ Object
23 24 25 |
# File 'lib/bridgetown-core/commands/start.rb', line 23 def self. "bridgetown start [options]" end |
Instance Method Details
#start ⇒ Object
rubocop:todo Metrics/PerceivedComplexity
28 29 30 31 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bridgetown-core/commands/start.rb', line 28 def start # rubocop:todo Metrics/PerceivedComplexity Bridgetown.logger.writer.enable_prefix Bridgetown::Commands::Build. sleep 0.25 begin require("puma/detect") rescue LoadError raise "** Puma server gem not found. Check your Gemfile and Bundler env? **" end = Thor::CoreExt::HashWithIndifferentAccess.new(self.) [:using_puma] = true # Load Bridgetown configuration into thread memory = configuration_with_overrides() # Set a local site URL in the config if one is not available if Bridgetown.env.development? && !["url"] scheme = .bind&.split("://")&.first == "ssl" ? "https" : "http" port = .bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000 .url = "#{scheme}://localhost:#{port}" end puma_pid = Process.fork do require "puma/cli" Puma::Runner.class_eval do def output_header(mode) log "* Puma version: #{Puma::Const::PUMA_VERSION} (#{ruby_engine}) (\"#{Puma::Const::CODE_NAME}\")" # rubocop:disable Layout/LineLength if mode == "cluster" log "* Cluster Master PID: #{Process.pid}" else log "* PID: #{Process.pid}" end end end puma_args = [] if [:bind] puma_args << "--bind" puma_args << [:bind] end cli = Puma::CLI.new puma_args cli.launcher.events.on_stopped do Bridgetown::Hooks.trigger :site, :server_shutdown end cli.run end begin Signal.trap("TERM") do Process.kill "SIGINT", puma_pid sleep 0.5 # let it breathe exit 0 # this runs the ensure block below end Process.setproctitle("bridgetown #{Bridgetown::VERSION} [#{File.basename(Dir.pwd)}]") build_args = ["-w"] + ARGV.reject { |arg| arg == "start" } Bridgetown::Commands::Build.start(build_args) rescue StandardError => e Process.kill "SIGINT", puma_pid sleep 0.5 raise e ensure # Shut down webpack, browsersync, etc. if they're running Bridgetown::Utils::Aux.kill_processes end sleep 0.5 # finish cleaning up end |