Class: Bridgetown::Commands::Console

Inherits:
Thor::Group
  • Object
show all
Extended by:
Summarizable
Includes:
ConfigurationOverridable
Defined in:
lib/bridgetown-core/commands/console.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Summarizable

summary

Methods included from ConfigurationOverridable

#configuration_with_overrides, included

Class Method Details



45
46
47
# File 'lib/bridgetown-core/commands/console.rb', line 45

def self.banner
  "bridgetown console [options]"
end

Instance Method Details

#consoleObject



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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/bridgetown-core/commands/console.rb', line 69

def console
  require "irb"
  require "irb/ext/save-history"
  require "amazing_print" unless options[:"bypass-ap"]

  Bridgetown.logger.adjust_verbosity(options)

  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta} " \
                                      "(codename \"#{Bridgetown::CODE_NAME.yellow}\") " \
                                      "consoleā€¦"
  Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan

  config_options = configuration_with_overrides(options)
  if options[:"server-config"]
    require "puma"
    require "bridgetown-core/rack/boot"
    Bridgetown::Rack.boot
  else
    config_options.run_initializers! context: :console
  end
  site = Bridgetown::Site.new(config_options)

  ConsoleMethods.site_reset(site) unless options[:blank]

  IRB::ExtendCommandBundle.include ConsoleMethods
  IRB.setup(nil)
  workspace = IRB::WorkSpace.new
  irb = IRB::Irb.new(workspace)
  IRB.conf[:IRB_RC]&.call(irb.context)
  IRB.conf[:MAIN_CONTEXT] = irb.context
  Bridgetown.logger.info "Console:", "Your site is now available as #{"site".cyan}"
  Bridgetown.logger.info "",
                         "You can also access #{"collections".cyan} or perform a " \
                         "#{"reload!".cyan}"

  trap("SIGINT") do
    irb.signal_handle
  end

  begin
    catch(:IRB_EXIT) do
      unless options[:"bypass-ap"]
        AmazingPrint.defaults = {
          indent: 2,
        }
        AmazingPrint.irb!
      end
      irb.eval_input
    end
  ensure
    IRB.conf[:AT_EXIT].each(&:call)
  end
end