Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new console commands via ConsoleMethods mixin #439

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions bridgetown-core/lib/bridgetown-core/commands/console.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
# frozen_string_literal: true

module Bridgetown
module ConsoleMethods
def site
Bridgetown::Current.site
end

def collections
site.collections
end

def reload!
Bridgetown.logger.info "Reloading site..."

I18n.reload! # make sure any locale files get read again
Bridgetown::Hooks.trigger :site, :pre_reload, site
Bridgetown::Hooks.clear_reloadable_hooks
site.plugin_manager.reload_plugin_files
site.loaders_manager.reload_loaders

ConsoleMethods.site_reset(site)
end

def self.site_reset(site)
site.reset
Bridgetown.logger.info "Reading files..."
site.read
Bridgetown.logger.info "", "done!"
Bridgetown.logger.info "Running generators..."
site.generate
Bridgetown.logger.info "", "done!"
end
end

module Commands
class Console < Thor::Group
extend Summarizable
Expand Down Expand Up @@ -37,24 +69,18 @@ def console
Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
site = Bridgetown::Site.new(configuration_with_overrides(options))

unless options[:blank]
site.reset
Bridgetown.logger.info "Reading files..."
site.read
Bridgetown.logger.info "", "done!"
Bridgetown.logger.info "Running generators..."
site.generate
Bridgetown.logger.info "", "done!"
end
ConsoleMethods.site_reset(site) unless options[:blank]

$BRIDGETOWN_SITE = site
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
eval("site = $BRIDGETOWN_SITE", workspace.binding, __FILE__, __LINE__)
Bridgetown.logger.info "Console:", "Now loaded as #{"site".cyan} variable."
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
Expand Down