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

Support minimalist installations with no config.ru or Rakefile (or anything other than Gemfile really) #942

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 16 additions & 5 deletions bridgetown-core/lib/bridgetown-core/commands/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ def build
if Bridgetown::Utils.frontend_bundler_type(config_options[:root_dir]) == :esbuild
Bridgetown::Utils.update_esbuild_autogenerated_config config_options
end
require "rake"
Rake.with_application do |rake|
rake.load_rakefile
rake["frontend:watcher"].invoke(true)
end
invoke_frontend_watcher_from_rake
end

@site = Bridgetown::Site.new(config_options)
Expand Down Expand Up @@ -112,6 +108,21 @@ def display_folder_paths(config_options)
plugins_dir = File.expand_path(config_options["plugins_dir"])
Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
end

def invoke_frontend_watcher_from_rake
require "rake"
Rake.with_application do |rake|
begin
rake.raw_load_rakefile
rescue StandardError => e
unless e.message.include?("No Rakefile found")
Bridgetown.logger.error "Error Running Rake:", "#{e.message} (#{e.class})"
e.backtrace[0..1].each { |backtrace_line| Bridgetown.logger.info backtrace_line }
end
end
rake["frontend:watcher"].invoke(true) if rake.tasks.any? { _1.name == "frontend:watcher" }
end
end
end
end
end
10 changes: 9 additions & 1 deletion bridgetown-core/lib/bridgetown-core/commands/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def start
Bridgetown::Server.new({
Host: bt_options.bind,
Port: port,
config: "config.ru",
config: rack_config_file,
}).tap do |server|
if server.serveable?
pid_tracker.create_pid_dir
Expand Down Expand Up @@ -115,6 +115,14 @@ def start
end
end
end

protected

def rack_config_file
File.exist?("config.ru") ?
"config.ru" :
File.expand_path("../rack/default_config.ru", __dir__)
end
end
end
end
15 changes: 9 additions & 6 deletions bridgetown-core/lib/bridgetown-core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ def from(user_config, starting_defaults = DEFAULTS)

def run_initializers!(context:) # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity
initializers_file = File.join(root_dir, "config", "initializers.rb")
return unless File.file?(initializers_file)
unless File.file?(initializers_file)
setup_load_paths! appending: true
return
end

load initializers_file

Expand Down Expand Up @@ -283,13 +286,13 @@ def merge_environment_specific_options!
end

def setup_load_paths!(appending: false) # rubocop:todo Metrics
unless appending
self[:root_dir] = File.expand_path(self[:root_dir])
self[:source] = File.expand_path(self[:source], self[:root_dir])
self[:destination] = File.expand_path(self[:destination], self[:root_dir])
self[:root_dir] = File.expand_path(self[:root_dir])
self[:source] = File.expand_path(self[:source], self[:root_dir])
self[:destination] = File.expand_path(self[:destination], self[:root_dir])

unless appending
autoload_paths.unshift({
path: self[:plugins_dir],
path: File.expand_path(self[:plugins_dir], self[:root_dir]),
eager: true,
})
autoload_paths.unshift({
Expand Down
14 changes: 14 additions & 0 deletions bridgetown-core/lib/bridgetown-core/rack/default_config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require "bridgetown-core/rack/boot"

Bridgetown::Rack.boot

unless defined?(RodaApp)
class RodaApp < Roda
plugin :bridgetown_server
route(&:bridgetown)
end
end

run RodaApp.freeze.app
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ def add_pid(pid, file:)

def read_pidfile(file)
File.readlines pidfile_for(file), chomp: true
rescue SystemCallError
[]
end

def remove_pidfile(file)
File.delete pidfile_for(file)
rescue SystemCallError # rubocop:disable Lint/SuppressedException
end

private
Expand Down
7 changes: 0 additions & 7 deletions bridgetown-website/config.ru

This file was deleted.

4 changes: 1 addition & 3 deletions bridgetown-website/server/roda_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
class RodaApp < Roda
plugin :bridgetown_server

route do |r|
r.bridgetown
end
route(&:bridgetown)
end