bridgetown-core 1.2.0.beta5 → 1.3.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7db2117b99eb2b2943920e6cbfe4267b2a668842de44e360df645da6554ea877
4
- data.tar.gz: b8e3652ab12db38512546612a74df6939bd841166d9cfae371aa75d6ae8d8265
3
+ metadata.gz: 9176399e9b750178476e2d57edb346989426407d5d40e8958c5be3901626f77f
4
+ data.tar.gz: a5130e5511c64acba6e6ee619a7529b49415e1c25b3e056cf4e709c4d78361da
5
5
  SHA512:
6
- metadata.gz: 446f796d17a209b19afdb9d8f349d1e5197d7f5600598bc21be3c23c73df7d10c125379d739bd608322d404365ca37b4a37cbe9b38fa8bdd22a97c84c41bee7c
7
- data.tar.gz: 89293450447e8acb5718cdcdc782124699faa138c559474c5df66609715163fca809d4ed477cf5ee75b905f62e0bcbd540f62a46841b8c58fede225670ae429b
6
+ metadata.gz: 849bff55f1997483ce24f67536daec7bdd53ff016d7e4ab8937b0184892680eb59f159d3a3d26c22fbc63ef63486ddd1b793943cd21fead6c281f0d2d9698f69
7
+ data.tar.gz: e5c317edb3ae4e232cd2a56c885b44af5375d7daeff71f385e620d402cbe57c68cf32fdc6eb13508bb92e3e8dff254cf53e59f56790631692eee092c6eaa0463
@@ -31,27 +31,25 @@ Gem::Specification.new do |s|
31
31
 
32
32
  s.required_ruby_version = ">= 2.7.0"
33
33
 
34
- s.add_runtime_dependency("activemodel", [">= 6.0", "< 8.0"])
35
- s.add_runtime_dependency("activesupport", [">= 6.0", "< 8.0"])
36
- s.add_runtime_dependency("addressable", "~> 2.4")
37
- s.add_runtime_dependency("amazing_print", "~> 1.2")
38
- s.add_runtime_dependency("colorator", "~> 1.0")
39
- s.add_runtime_dependency("erubi", "~> 1.9")
40
- s.add_runtime_dependency("faraday", "~> 1.0")
41
- s.add_runtime_dependency("faraday_middleware", "~> 1.0")
42
- s.add_runtime_dependency("hash_with_dot_access", "~> 1.2")
43
- s.add_runtime_dependency("i18n", "~> 1.0")
44
- s.add_runtime_dependency("kramdown", "~> 2.1")
45
- s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
46
- s.add_runtime_dependency("liquid", "~> 5.0")
47
- s.add_runtime_dependency("listen", "~> 3.0")
48
- s.add_runtime_dependency("rake", ">= 13.0")
49
- s.add_runtime_dependency("roda", "~> 3.46")
50
- s.add_runtime_dependency("rouge", "~> 3.0")
51
- s.add_runtime_dependency("serbea", "~> 1.0")
52
- s.add_runtime_dependency("terminal-table", "~> 1.8")
53
- s.add_runtime_dependency("thor", "~> 1.1")
54
- s.add_runtime_dependency("tilt", "~> 2.0")
55
- s.add_runtime_dependency("webrick", "~> 1.7")
56
- s.add_runtime_dependency("zeitwerk", "~> 2.5")
34
+ s.add_runtime_dependency("activemodel", [">= 6.0", "< 8.0"])
35
+ s.add_runtime_dependency("activesupport", [">= 6.0", "< 8.0"])
36
+ s.add_runtime_dependency("addressable", "~> 2.4")
37
+ s.add_runtime_dependency("amazing_print", "~> 1.2")
38
+ s.add_runtime_dependency("colorator", "~> 1.0")
39
+ s.add_runtime_dependency("erubi", "~> 1.9")
40
+ s.add_runtime_dependency("faraday", "~> 2.0")
41
+ s.add_runtime_dependency("faraday-follow_redirects", "~> 0.3")
42
+ s.add_runtime_dependency("hash_with_dot_access", "~> 1.2")
43
+ s.add_runtime_dependency("i18n", "~> 1.0")
44
+ s.add_runtime_dependency("kramdown", "~> 2.1")
45
+ s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
46
+ s.add_runtime_dependency("liquid", "~> 5.0")
47
+ s.add_runtime_dependency("listen", "~> 3.0")
48
+ s.add_runtime_dependency("rake", ">= 13.0")
49
+ s.add_runtime_dependency("roda", "~> 3.46")
50
+ s.add_runtime_dependency("rouge", "~> 3.0")
51
+ s.add_runtime_dependency("serbea", "~> 1.0")
52
+ s.add_runtime_dependency("thor", "~> 1.1")
53
+ s.add_runtime_dependency("tilt", "~> 2.0")
54
+ s.add_runtime_dependency("zeitwerk", "~> 2.5")
57
55
  end
@@ -282,7 +282,7 @@ module Bridgetown
282
282
  if model_is_multi_locale?(model, model_relative_path)
283
283
  # If the model specifies a locales key, use that to determine the
284
284
  # the locale of each resource, otherwise fall back to `site.config.available_locales`
285
- locales = model.locales || site.config.available_locales
285
+ locales = model.attributes[:locales] || site.config.available_locales
286
286
 
287
287
  locales.each do |locale|
288
288
  model.locale = locale.to_sym
@@ -80,6 +80,8 @@ module Bridgetown
80
80
  after_install new_site_path, args.join(" "), options
81
81
  rescue ArgumentError => e
82
82
  say_status :alert, e.message, :red
83
+ ensure
84
+ self.class.created_site_dir = nil # reset afterwards, otherwise hanging tmp dirs in test
83
85
  end
84
86
 
85
87
  protected
@@ -126,7 +126,7 @@ module Bridgetown
126
126
  Layouts, you'd run:\n
127
127
  bridgetown plugins cd SamplePlugin/Layouts
128
128
  DOC
129
- desc "cd <origin/dir>", "Open folder (content, layouts, etc.) within the plugin origin"
129
+ desc "cd <origin/dir>", "Open content folder within the plugin origin"
130
130
 
131
131
  # This is super useful if you want to copy files out of plugins to override.
132
132
  #
@@ -177,38 +177,43 @@ module Bridgetown
177
177
  end
178
178
  end
179
179
 
180
- desc "new NAME", "Create a new plugin NAME by cloning the sample plugin repo"
180
+ desc "new NAME", "Create a new plugin NAME (snake_case_name_preferred)"
181
181
  def new(name)
182
182
  folder_name = name.underscore
183
183
  module_name = folder_name.camelize
184
184
 
185
- run "git clone -b v1.2-initializer https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
186
- new_gemspec = "#{name}.gemspec"
185
+ run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
186
+ new_gemspec = "#{folder_name}.gemspec"
187
187
 
188
188
  inside name do # rubocop:todo Metrics/BlockLength
189
189
  destroy_existing_repo
190
190
  initialize_new_repo
191
191
 
192
- FileUtils.mv "bridgetown-sample-plugin.gemspec", new_gemspec.to_s
192
+ FileUtils.mv "sample_plugin.gemspec", new_gemspec
193
193
  gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
194
194
  gsub_file new_gemspec, "bridgetown-sample-plugin", name
195
- gsub_file new_gemspec, "sample-plugin", name
195
+ gsub_file new_gemspec, "sample_plugin", folder_name
196
196
  gsub_file new_gemspec, "SamplePlugin", module_name
197
197
 
198
198
  gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
199
199
  gsub_file "package.json", "bridgetown-sample-plugin", name
200
+ gsub_file "package.json", "sample_plugin", folder_name
200
201
 
201
202
  FileUtils.mv "lib/sample_plugin.rb", "lib/#{folder_name}.rb"
202
- gsub_file "lib/#{name}.rb", "sample_plugin", folder_name
203
- gsub_file "lib/#{name}.rb", "SamplePlugin", module_name
203
+ gsub_file "lib/#{folder_name}.rb", "sample_plugin", folder_name
204
+ gsub_file "lib/#{folder_name}.rb", "SamplePlugin", module_name
204
205
 
205
206
  FileUtils.mv "lib/sample_plugin", "lib/#{folder_name}"
206
- gsub_file "lib/#{name}/builder.rb", "SamplePlugin", module_name
207
- gsub_file "lib/#{name}/version.rb", "SamplePlugin", module_name
207
+ gsub_file "lib/#{folder_name}/builder.rb", "SamplePlugin", module_name
208
+ gsub_file "lib/#{folder_name}/builder.rb", "sample_plugin", folder_name
209
+ gsub_file "lib/#{folder_name}/version.rb", "SamplePlugin", module_name
208
210
 
209
211
  FileUtils.mv "test/test_sample_plugin.rb", "test/test_#{folder_name}.rb"
210
212
  gsub_file "test/test_#{folder_name}.rb", "SamplePlugin", module_name
211
- gsub_file "test/helper.rb", "sample-plugin", name
213
+ gsub_file "test/test_#{folder_name}.rb", "sample plugin", module_name
214
+ gsub_file "test/helper.rb", "sample_plugin", folder_name
215
+ gsub_file "test/fixtures/src/index.html", "sample_plugin", folder_name
216
+ gsub_file "test/fixtures/config/initializers.rb", "sample_plugin", folder_name
212
217
 
213
218
  FileUtils.mv "components/sample_plugin", "components/#{folder_name}"
214
219
  FileUtils.mv "content/sample_plugin", "content/#{folder_name}"
@@ -220,14 +225,15 @@ module Bridgetown
220
225
 
221
226
  gsub_file "components/#{folder_name}/plugin_component.rb", "SamplePlugin", module_name
222
227
 
223
- gsub_file "frontend/javascript/index.js", "bridgetown-sample-plugin", name
228
+ gsub_file "frontend/javascript/index.js", "sample_plugin", folder_name
224
229
  gsub_file "frontend/javascript/index.js", "SamplePlugin", module_name
230
+ gsub_file "frontend/styles/index.css", "sample_plugin", folder_name
225
231
  end
226
232
  say ""
227
233
  say_status "Done!", "Have fun writing your new #{name} plugin :)"
228
234
  say_status "Remember:", "Don't forget to rename the SamplePlugin" \
229
235
  " code identifiers and paths to your own" \
230
- " indentifer, as well as update your README" \
236
+ " identifier, as well as update your README" \
231
237
  " and CHANGELOG files as necessary."
232
238
  end
233
239
 
@@ -9,9 +9,9 @@ module Bridgetown
9
9
 
10
10
  YAML_HEADER = %r!\A---\s*\n!.freeze
11
11
  YAML_BLOCK = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m.freeze
12
- RUBY_HEADER = %r!\A[~`#\-]{3,}(?:ruby|<%|{%)\s*\n!.freeze
12
+ RUBY_HEADER = %r!\A[~`#-]{3,}(?:ruby|<%|{%)\s*\n!.freeze
13
13
  RUBY_BLOCK =
14
- %r!#{RUBY_HEADER.source}(.*?\n?)^((?:%>|%})?[~`#\-]{3,}\s*$\n?)!m.freeze
14
+ %r!#{RUBY_HEADER.source}(.*?\n?)^((?:%>|%})?[~`#-]{3,}\s*$\n?)!m.freeze
15
15
 
16
16
  def read_front_matter(file_path) # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
17
17
  file_contents = File.read(
@@ -49,7 +49,7 @@ module Bridgetown
49
49
  priority: Bridgetown::Hooks::DEFAULT_PRIORITY,
50
50
  &block
51
51
  )
52
- Bridgetown::Hooks.register_one(owner, event, priority: priority, &block)
52
+ Bridgetown::Hooks.register_one(owner, event, priority: priority, reloadable: false, &block)
53
53
  end
54
54
 
55
55
  def source_manifest(**kwargs)
@@ -72,6 +72,10 @@ module Bridgetown
72
72
  @scope.roda_initializers << block
73
73
  end
74
74
 
75
+ def timezone(tz) # rubocop:disable Naming/MethodParameterName
76
+ Bridgetown.set_timezone(tz)
77
+ end
78
+
75
79
  def method_missing(key, *value, &block) # rubocop:disable Style/MissingRespondToMissing
76
80
  return get(key) if value.empty? && block.nil?
77
81
 
@@ -132,7 +136,7 @@ module Bridgetown
132
136
 
133
137
  if require_initializer
134
138
  init_file_name = File.join(@scope.root_dir, "config", "#{name}.rb")
135
- require(init_file_name) if File.exist?(init_file_name)
139
+ load(init_file_name) if File.exist?(init_file_name)
136
140
  end
137
141
 
138
142
  @scope.initializers[name.to_sym]
@@ -134,7 +134,7 @@ module Bridgetown
134
134
  initializers_file = File.join(root_dir, "config", "initializers.rb")
135
135
  return unless File.file?(initializers_file)
136
136
 
137
- require initializers_file
137
+ load initializers_file
138
138
 
139
139
  return unless initializers # no initializers have been set up
140
140
 
@@ -31,7 +31,7 @@ create_builder "purgecss.rb" do
31
31
  manifest = JSON.parse(File.read(manifest_file))
32
32
 
33
33
  if Bridgetown::Utils.frontend_bundler_type == :esbuild
34
- css_file = manifest["styles/index.css"].split("/").last
34
+ css_file = (manifest["styles/index.css"] || manifest["styles/index.scss"]).split("/").last
35
35
  css_path = ["output", "_bridgetown", "static", css_file].join("/")
36
36
  else
37
37
  css_file = manifest["main.css"].split("/").last
@@ -15,10 +15,13 @@ module Bridgetown
15
15
  InvalidURLError = Class.new(FatalException)
16
16
  InvalidConfigurationError = Class.new(FatalException)
17
17
 
18
- def self.print_build_error(exc, trace: false, logger: Bridgetown.logger)
18
+ def self.print_build_error(exc, trace: false, logger: Bridgetown.logger, server: false) # rubocop:disable Metrics
19
19
  logger.error "Exception raised:", exc.class.to_s.bold
20
20
  logger.error exc.message.reset_ansi
21
21
 
22
+ build_errors_file = Bridgetown.build_errors_path if !server && Bridgetown::Current.site
23
+ build_errors_data = "#{exc.class}: #{exc.message}"
24
+
22
25
  trace_args = ["-t", "--trace"]
23
26
  print_trace_msg = true
24
27
  traces = if trace || ARGV.find { |arg| trace_args.include?(arg) }
@@ -29,6 +32,12 @@ module Bridgetown
29
32
  end
30
33
  traces.each_with_index do |backtrace_line, index|
31
34
  logger.error "#{index + 1}:", backtrace_line.reset_ansi
35
+ build_errors_data << "\n#{backtrace_line}" if index < 2
36
+ end
37
+
38
+ if build_errors_file
39
+ FileUtils.mkdir_p(File.dirname(build_errors_file))
40
+ File.write(build_errors_file, build_errors_data, mode: "w")
32
41
  end
33
42
 
34
43
  return unless print_trace_msg
@@ -17,7 +17,9 @@ module Bridgetown
17
17
  private
18
18
 
19
19
  def tabulate(data)
20
- require "terminal-table"
20
+ unless defined?(Terminal::Table)
21
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail "terminal-table"
22
+ end
21
23
 
22
24
  header = data.shift
23
25
  footer = data.pop
@@ -7,9 +7,9 @@ module Bridgetown
7
7
  include Bridgetown::Utils::RubyFrontMatterDSL
8
8
 
9
9
  YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m.freeze
10
- RUBY_FRONT_MATTER_HEADER = %r!\A[~`#\-]{3,}(?:ruby|<%|{%)\s*\n!.freeze
10
+ RUBY_FRONT_MATTER_HEADER = %r!\A[~`#-]{3,}(?:ruby|<%|{%)\s*\n!.freeze
11
11
  RUBY_FRONT_MATTER_REGEXP =
12
- %r!#{RUBY_FRONT_MATTER_HEADER.source}(.*?\n?)^((?:%>|%})?[~`#\-]{3,}\s*$\n?)!m.freeze
12
+ %r!#{RUBY_FRONT_MATTER_HEADER.source}(.*?\n?)^((?:%>|%})?[~`#-]{3,}\s*$\n?)!m.freeze
13
13
 
14
14
  # @return [String]
15
15
  attr_accessor :content
@@ -8,12 +8,22 @@ require "roda/plugins/public"
8
8
  Bridgetown::Current.preloaded_configuration ||= Bridgetown.configuration
9
9
 
10
10
  require_relative "logger"
11
- require_relative "roda"
12
11
  require_relative "routes"
13
12
  require_relative "static_indexes"
14
13
 
15
14
  module Bridgetown
16
15
  module Rack
16
+ class Roda < ::Roda
17
+ def self.inherited(klass)
18
+ Bridgetown::Deprecator.deprecation_message(
19
+ "The `Bridgetown::Rack::Roda' class will be removed in favor of using the " \
20
+ "`bridgetown_server' plugin in a future version"
21
+ )
22
+ super
23
+ klass.plugin :bridgetown_server
24
+ end
25
+ end
26
+
17
27
  class << self
18
28
  # @return [Bridgetown::Utils::LoadersManager]
19
29
  attr_accessor :loaders_manager
@@ -56,6 +66,8 @@ module Bridgetown
56
66
  loader.reload
57
67
  loader.eager_load
58
68
  Bridgetown::Rack::Routes.reload_subclasses
69
+ rescue SyntaxError => e
70
+ Bridgetown::Errors.print_build_error(e)
59
71
  end.start
60
72
  end
61
73
  end
@@ -20,6 +20,37 @@ module Bridgetown
20
20
  }.freeze
21
21
 
22
22
  class << self
23
+ # rubocop:disable Bridgetown/NoPutsAllowed, Metrics/MethodLength
24
+ def print_routes
25
+ # TODO: this needs to be fully documented
26
+ routes = begin
27
+ JSON.parse(
28
+ File.read(
29
+ File.join(Bridgetown::Current.preloaded_configuration.root_dir, ".routes.json")
30
+ )
31
+ )
32
+ rescue StandardError
33
+ []
34
+ end
35
+ puts
36
+ puts "Routes:"
37
+ puts "======="
38
+ if routes.blank?
39
+ puts "No routes found. Have you commented all of your routes?"
40
+ puts "Documentation: https://github.com/jeremyevans/roda-route_list#basic-usage-"
41
+ end
42
+
43
+ routes.each do |route|
44
+ puts [
45
+ route["methods"]&.join("|") || "GET",
46
+ route["path"],
47
+ route["file"] ? "\n File: #{route["file"]}" : nil,
48
+ ].compact.join(" ")
49
+ end
50
+ puts
51
+ end
52
+ # rubocop:enable Bridgetown/NoPutsAllowed, Metrics/MethodLength
53
+
23
54
  # @return [Hash<String, Class(Routes)>]
24
55
  attr_accessor :tracked_subclasses
25
56
 
@@ -80,7 +111,7 @@ module Bridgetown
80
111
  # Initialize a new Routes instance and execute the route as part of the
81
112
  # Roda app request cycle
82
113
  #
83
- # @param roda_app [Bridgetown::Rack::Roda]
114
+ # @param roda_app [Roda]
84
115
  def merge(roda_app)
85
116
  return unless router_block
86
117
 
@@ -90,7 +121,7 @@ module Bridgetown
90
121
  # Start the Roda app request cycle. There are two different code paths
91
122
  # depending on if there's a site `base_path` configured
92
123
  #
93
- # @param roda_app [Bridgetown::Rack::Roda]
124
+ # @param roda_app [Roda]
94
125
  # @return [void]
95
126
  def start!(roda_app)
96
127
  if Bridgetown::Current.preloaded_configuration.base_path == "/"
@@ -112,7 +143,7 @@ module Bridgetown
112
143
  # run through all the Routes blocks. If the file-based router plugin
113
144
  # is available, kick off that request process next.
114
145
  #
115
- # @param roda_app [Bridgetown::Rack::Roda]
146
+ # @param roda_app [Roda]
116
147
  # @return [void]
117
148
  def load_all_routes(roda_app)
118
149
  roda_app.request.public
@@ -127,11 +158,12 @@ module Bridgetown
127
158
  end
128
159
  end
129
160
 
130
- # @param app [Bridgetown::Rack::Roda]
131
- def setup_live_reload(app) # rubocop:disable Metrics/AbcSize
161
+ # @param app [Roda]
162
+ def setup_live_reload(app) # rubocop:disable Metrics
132
163
  sleep_interval = 0.2
133
164
  file_to_check = File.join(Bridgetown::Current.preloaded_configuration.destination,
134
165
  "index.html")
166
+ errors_file = Bridgetown.build_errors_path
135
167
 
136
168
  app.request.get "_bridgetown/live_reload" do
137
169
  app.response["Content-Type"] = "text/event-stream"
@@ -146,6 +178,8 @@ module Bridgetown
146
178
  if @_mod < new_mod
147
179
  out << "data: reloaded!\n\n"
148
180
  break
181
+ elsif File.exist?(errors_file)
182
+ out << "event: builderror\ndata: #{File.read(errors_file).to_json}\n\n"
149
183
  else
150
184
  out << "data: #{new_mod}\n\n"
151
185
  end
@@ -157,7 +191,7 @@ module Bridgetown
157
191
  end
158
192
  end
159
193
 
160
- # @param roda_app [Bridgetown::Rack::Roda]
194
+ # @param roda_app [Roda]
161
195
  def initialize(roda_app)
162
196
  @_roda_app = roda_app
163
197
  end
@@ -11,13 +11,13 @@ module Bridgetown
11
11
 
12
12
  def read
13
13
  layout_entries.each do |layout_file|
14
- @layouts[layout_name(layout_file)] = \
14
+ @layouts[layout_name(layout_file)] =
15
15
  Layout.new(site, layout_directory, layout_file)
16
16
  end
17
17
 
18
18
  site.config.source_manifests.filter_map(&:layouts).each do |plugin_layouts|
19
19
  layout_entries(plugin_layouts).each do |layout_file|
20
- @layouts[layout_name(layout_file)] ||= \
20
+ @layouts[layout_name(layout_file)] ||=
21
21
  Layout.new(site, plugin_layouts, layout_file, from_plugin: true)
22
22
  end
23
23
  end
@@ -13,6 +13,8 @@ module Bridgetown
13
13
  @config = config
14
14
  @loaders = {}
15
15
  @root_dir = config.root_dir
16
+
17
+ FileUtils.rm_f(Bridgetown.build_errors_path)
16
18
  end
17
19
 
18
20
  def unload_loaders
@@ -75,6 +77,8 @@ module Bridgetown
75
77
  end
76
78
 
77
79
  def reload_loaders
80
+ FileUtils.rm_f(Bridgetown.build_errors_path)
81
+
78
82
  @loaders.each do |load_path, loader|
79
83
  next unless reloading_enabled?(load_path)
80
84
 
@@ -466,6 +466,7 @@ module Bridgetown
466
466
  function startReloadConnection() {
467
467
  const evtSource = new EventSource("#{site.base_path(strip_slash_only: true)}/_bridgetown/live_reload")
468
468
  evtSource.onmessage = event => {
469
+ if (document.querySelector("#bridgetown-build-error")) document.querySelector("#bridgetown-build-error").close()
469
470
  if (event.data == "reloaded!") {
470
471
  location.reload()
471
472
  } else {
@@ -477,6 +478,23 @@ module Bridgetown
477
478
  }
478
479
  }
479
480
  }
481
+ evtSource.addEventListener("builderror", event => {
482
+ let dialog = document.querySelector("#bridgetown-build-error")
483
+ if (!dialog) {
484
+ dialog = document.createElement("dialog")
485
+ dialog.id = "bridgetown-build-error"
486
+ dialog.style.borderColor = "red"
487
+ dialog.style.fontSize = "110%"
488
+ dialog.innerHTML = `
489
+ <p style="color:red">There was an error when building the site:</p>
490
+ <output><pre></pre></output>
491
+ <p><small>Check your Bridgetown logs for further details.</small></p>
492
+ `
493
+ document.body.appendChild(dialog)
494
+ dialog.showModal()
495
+ }
496
+ dialog.querySelector("pre").textContent = JSON.parse(event.data)
497
+ })
480
498
  evtSource.onerror = event => {
481
499
  if (evtSource.readyState === 2) {
482
500
  // reconnect with new object
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "1.2.0.beta5"
5
- CODE_NAME = "Bonny Slope"
4
+ VERSION = "1.3.0.beta1"
5
+ CODE_NAME = "Kelly Butte"
6
6
  end
@@ -106,7 +106,7 @@ module Bridgetown
106
106
  end
107
107
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".bold.green} in less than " \
108
108
  "#{(Time.now - time).ceil(2)} seconds."
109
- rescue StandardError => e
109
+ rescue StandardError, SyntaxError => e
110
110
  Bridgetown::Errors.print_build_error(e, trace: options[:trace])
111
111
  end
112
112
  Bridgetown.logger.info ""
@@ -136,6 +136,8 @@ module Bridgetown
136
136
  end
137
137
  alias_method :env, :environment
138
138
 
139
+ # Set up the Bridgetown execution environment before attempting to load any
140
+ # plugins or gems prior to a site build
139
141
  def begin!
140
142
  ENV["RACK_ENV"] ||= environment
141
143
 
@@ -178,6 +180,38 @@ module Bridgetown
178
180
  end
179
181
  end
180
182
 
183
+ # Initialize a preflight configuration object, copying initializers and
184
+ # source manifests from a previous standard configuration if necessary.
185
+ # Typically only needed in test suites to reset before a new test.
186
+ #
187
+ # @return [Bridgetown::Configuration::Preflight]
188
+ def reset_configuration! # rubocop:disable Metrics/AbcSize
189
+ if Bridgetown::Current.preloaded_configuration.nil?
190
+ return Bridgetown::Current.preloaded_configuration =
191
+ Bridgetown::Configuration::Preflight.new
192
+ end
193
+
194
+ return unless Bridgetown::Current.preloaded_configuration.is_a?(Bridgetown::Configuration)
195
+
196
+ previous_config = Bridgetown::Current.preloaded_configuration
197
+ new_config = Bridgetown::Configuration::Preflight.new
198
+ new_config.initializers = previous_config.initializers
199
+ new_config.source_manifests = previous_config.source_manifests
200
+ if new_config.initializers
201
+ new_config.initializers.delete(:init)
202
+ new_config.initializers.select! do |_k, initializer|
203
+ next false if initializer.block.source_location[0].start_with?(
204
+ File.join(previous_config.root_dir, "config")
205
+ )
206
+
207
+ initializer.completed = false
208
+ true
209
+ end
210
+ end
211
+
212
+ Bridgetown::Current.preloaded_configuration = new_config
213
+ end
214
+
181
215
  def initializer(name, prepend: false, replace: false, &block) # rubocop:todo Metrics
182
216
  unless Bridgetown::Current.preloaded_configuration
183
217
  raise "The `#{name}' initializer in #{block.source_location[0]} was called " \
@@ -276,6 +310,14 @@ module Bridgetown
276
310
  def set_timezone(timezone)
277
311
  ENV["TZ"] = timezone
278
312
  end
313
+
314
+ # Get the current TZ environment variable
315
+ #
316
+ # @return [String]
317
+ def timezone
318
+ ENV["TZ"]
319
+ end
320
+
279
321
  # rubocop:enable Naming/AccessorMethodName
280
322
 
281
323
  # Fetch the logger instance for this Bridgetown process.
@@ -335,6 +377,18 @@ module Bridgetown
335
377
  File.join(base_directory, clean_path)
336
378
  end
337
379
  end
380
+
381
+ # When there's a build error, error details will be logged to a file which the dev server
382
+ # can read and pass along to the browser.
383
+ #
384
+ # @return [String] the path to the cached errors file
385
+ def build_errors_path
386
+ File.join(
387
+ (Bridgetown::Current.site&.config || Bridgetown::Current.preloaded_configuration).root_dir,
388
+ ".bridgetown-cache",
389
+ "build_errors.txt"
390
+ )
391
+ end
338
392
  end
339
393
  end
340
394