bridgetown-core 1.0.0.alpha6 → 1.0.0.alpha7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +1 -2
  3. data/lib/bridgetown-core/cache.rb +1 -1
  4. data/lib/bridgetown-core/collection.rb +1 -1
  5. data/lib/bridgetown-core/commands/configure.rb +7 -0
  6. data/lib/bridgetown-core/commands/new.rb +1 -0
  7. data/lib/bridgetown-core/component.rb +2 -2
  8. data/lib/bridgetown-core/concerns/front_matter_importer.rb +1 -1
  9. data/lib/bridgetown-core/concerns/site/configurable.rb +6 -3
  10. data/lib/bridgetown-core/concerns/site/extensible.rb +2 -1
  11. data/lib/bridgetown-core/concerns/site/ssr.rb +38 -16
  12. data/lib/bridgetown-core/configuration.rb +77 -46
  13. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
  14. data/lib/bridgetown-core/configurations/cypress/cypress.json +4 -0
  15. data/lib/bridgetown-core/configurations/cypress/cypress_dir/fixtures/example.json +5 -0
  16. data/lib/bridgetown-core/configurations/cypress/cypress_dir/integration/navbar.spec.js +17 -0
  17. data/lib/bridgetown-core/configurations/cypress/cypress_dir/plugins/index.js +21 -0
  18. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/commands.js +25 -0
  19. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/index.js +20 -0
  20. data/lib/bridgetown-core/configurations/cypress/cypress_tasks +33 -0
  21. data/lib/bridgetown-core/configurations/cypress.rb +13 -0
  22. data/lib/bridgetown-core/configurations/minitesting.rb +19 -15
  23. data/lib/bridgetown-core/configurations/netlify.rb +2 -4
  24. data/lib/bridgetown-core/configurations/purgecss.rb +2 -2
  25. data/lib/bridgetown-core/configurations/render/render.yaml.erb +26 -0
  26. data/lib/bridgetown-core/configurations/render.rb +6 -0
  27. data/lib/bridgetown-core/configurations/tailwindcss.rb +3 -5
  28. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  29. data/lib/bridgetown-core/core_ext/psych.rb +1 -5
  30. data/lib/bridgetown-core/frontmatter_defaults.rb +2 -2
  31. data/lib/bridgetown-core/liquid_renderer.rb +1 -1
  32. data/lib/bridgetown-core/model/base.rb +23 -26
  33. data/lib/bridgetown-core/model/builder_origin.rb +8 -6
  34. data/lib/bridgetown-core/model/origin.rb +10 -1
  35. data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
  36. data/lib/bridgetown-core/plugin_manager.rb +7 -34
  37. data/lib/bridgetown-core/rack/boot.rb +46 -23
  38. data/lib/bridgetown-core/rack/roda.rb +2 -1
  39. data/lib/bridgetown-core/rack/routes.rb +2 -2
  40. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  41. data/lib/bridgetown-core/readers/plugin_content_reader.rb +1 -1
  42. data/lib/bridgetown-core/renderer.rb +2 -2
  43. data/lib/bridgetown-core/resource/base.rb +3 -3
  44. data/lib/bridgetown-core/resource/relations.rb +1 -1
  45. data/lib/bridgetown-core/resource/taxonomy_term.rb +2 -2
  46. data/lib/bridgetown-core/resource/taxonomy_type.rb +2 -2
  47. data/lib/bridgetown-core/ruby_template_view.rb +2 -2
  48. data/lib/bridgetown-core/site.rb +15 -5
  49. data/lib/bridgetown-core/utils/loaders_manager.rb +72 -0
  50. data/lib/bridgetown-core/utils.rb +13 -14
  51. data/lib/bridgetown-core/version.rb +1 -1
  52. data/lib/bridgetown-core/watcher.rb +16 -7
  53. data/lib/bridgetown-core/yaml_parser.rb +1 -5
  54. data/lib/site_template/README.md +1 -1
  55. data/lib/site_template/Rakefile +3 -3
  56. metadata +16 -5
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Utils
5
+ class LoadersManager
6
+ attr_accessor :config
7
+
8
+ attr_reader :loaders, :root_dir
9
+
10
+ # @param config [Bridgetown::Configuration]
11
+ # @param root_dir [String] root of the current site
12
+ def initialize(config, root_dir = Dir.pwd)
13
+ @config = config
14
+ @loaders = {}
15
+ @root_dir = root_dir
16
+ end
17
+
18
+ def unload_loaders
19
+ return if @loaders.keys.empty?
20
+
21
+ @loaders.each do |_path, loader|
22
+ loader.unload
23
+ end
24
+ @loaders = {}
25
+ end
26
+
27
+ def reloading_enabled?(load_path)
28
+ load_path.start_with?(root_dir) && ENV["BRIDGETOWN_ENV"] != "production"
29
+ end
30
+
31
+ def setup_loaders(autoload_paths = []) # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
32
+ (autoload_paths.presence || config.autoload_paths).each do |load_path|
33
+ if @loaders.key?(load_path)
34
+ raise "Zeitwerk loader already added for `#{load_path}'. Please check your config"
35
+ end
36
+
37
+ next unless Dir.exist? load_path
38
+
39
+ loader = Zeitwerk::Loader.new
40
+ begin
41
+ loader.push_dir(load_path)
42
+ rescue Zeitwerk::Error
43
+ next
44
+ end
45
+ loader.enable_reloading if reloading_enabled?(load_path)
46
+ loader.ignore(File.join(load_path, "**", "*.js.rb"))
47
+ config.autoloader_collapsed_paths.each do |collapsed_path|
48
+ next unless collapsed_path.starts_with?(load_path)
49
+
50
+ loader.collapse(collapsed_path)
51
+ end
52
+ Bridgetown::Hooks.trigger :loader, :pre_setup, loader, load_path
53
+ loader.setup
54
+ loader.eager_load if config.eager_load_paths.include?(load_path)
55
+ Bridgetown::Hooks.trigger :loader, :post_setup, loader, load_path
56
+ @loaders[load_path] = loader
57
+ end
58
+ end
59
+
60
+ def reload_loaders
61
+ @loaders.each do |load_path, loader|
62
+ next unless reloading_enabled?(load_path)
63
+
64
+ Bridgetown::Hooks.trigger :loader, :pre_reload, loader, load_path
65
+ loader.reload
66
+ loader.eager_load if config.eager_load_paths.include?(load_path)
67
+ Bridgetown::Hooks.trigger :loader, :post_reload, loader, load_path
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -5,6 +5,7 @@ module Bridgetown
5
5
  extend self
6
6
  autoload :Ansi, "bridgetown-core/utils/ansi"
7
7
  autoload :Aux, "bridgetown-core/utils/aux"
8
+ autoload :LoadersManager, "bridgetown-core/utils/loaders_manager"
8
9
  autoload :RequireGems, "bridgetown-core/utils/require_gems"
9
10
  autoload :RubyExec, "bridgetown-core/utils/ruby_exec"
10
11
  autoload :RubyFrontMatter, "bridgetown-core/utils/ruby_front_matter"
@@ -120,15 +121,11 @@ module Bridgetown
120
121
  # @return [Boolean] if the YAML front matter is present.
121
122
  # rubocop: disable Naming/PredicateName
122
123
  def has_yaml_header?(file)
123
- File.open(file, "rb", &:readline).match? Bridgetown::FrontMatterImporter::YAML_HEADER
124
- rescue EOFError
125
- false
124
+ File.open(file, "rb", &:gets)&.match?(Bridgetown::FrontMatterImporter::YAML_HEADER) || false
126
125
  end
127
126
 
128
127
  def has_rbfm_header?(file)
129
- File.open(file, "rb", &:readline).match? Bridgetown::FrontMatterImporter::RUBY_HEADER
130
- rescue EOFError
131
- false
128
+ File.open(file, "rb", &:gets)&.match?(Bridgetown::FrontMatterImporter::RUBY_HEADER) || false
132
129
  end
133
130
 
134
131
  # Determine whether the given content string contains Liquid Tags or Vaiables
@@ -354,7 +351,7 @@ module Bridgetown
354
351
  # @raise [WebpackAssetError] if unable to find css or js in the manifest
355
352
  # file
356
353
  def parse_webpack_manifest_file(site, asset_type)
357
- return log_webpack_asset_error("Webpack manifest") if site.frontend_manifest.nil?
354
+ return log_webpack_asset_error(site, "Webpack manifest") if site.frontend_manifest.nil?
358
355
 
359
356
  asset_path = if %w(js css).include?(asset_type)
360
357
  site.frontend_manifest["main.#{asset_type}"]
@@ -364,7 +361,7 @@ module Bridgetown
364
361
  end&.last
365
362
  end
366
363
 
367
- return log_webpack_asset_error(asset_type) if asset_path.nil?
364
+ return log_webpack_asset_error(site, asset_type) if asset_path.nil?
368
365
 
369
366
  static_frontend_path site, ["js", asset_path]
370
367
  end
@@ -379,12 +376,14 @@ module Bridgetown
379
376
  Addressable::URI.parse(path_parts.join("/")).normalize.to_s
380
377
  end
381
378
 
382
- def log_webpack_asset_error(asset_type)
383
- Bridgetown.logger.warn(
384
- "Webpack:",
385
- "There was an error parsing your #{asset_type} file. \
386
- Please check your #{asset_type} file for any errors."
387
- )
379
+ def log_webpack_asset_error(site, asset_type)
380
+ site.data[:__webpack_asset_errors] ||= {}
381
+ site.data[:__webpack_asset_errors][asset_type] ||=
382
+ Bridgetown.logger.warn(
383
+ "Webpack:",
384
+ "There was an error parsing your #{asset_type} file. \
385
+ Please check your #{asset_type} file for any errors."
386
+ )
388
387
 
389
388
  "MISSING_WEBPACK_MANIFEST_FILE"
390
389
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "1.0.0.alpha6"
4
+ VERSION = "1.0.0.alpha7"
5
5
  CODE_NAME = "Pearl"
6
6
  end
@@ -41,10 +41,12 @@ module Bridgetown
41
41
  Dir.exist?(path)
42
42
  end
43
43
 
44
+ paths_to_watch = (plugin_paths_to_watch + options.autoload_paths).uniq
45
+
44
46
  Listen.to(
45
47
  options["source"],
46
48
  webpack_path,
47
- *plugin_paths_to_watch,
49
+ *paths_to_watch,
48
50
  ignore: listen_ignore_paths(options),
49
51
  force_polling: options["force_polling"],
50
52
  &listen_handler(site, options)
@@ -57,10 +59,12 @@ module Bridgetown
57
59
  c = modified + added + removed
58
60
  n = c.length
59
61
 
60
- Bridgetown.logger.info "Regenerating…"
61
- Bridgetown.logger.info "", "#{n} file(s) changed at #{t.strftime("%Y-%m-%d %H:%M:%S")}"
62
+ unless site.ssr?
63
+ Bridgetown.logger.info "Regenerating…"
64
+ Bridgetown.logger.info "", "#{n} file(s) changed at #{t.strftime("%Y-%m-%d %H:%M:%S")}"
65
+ c.each { |path| Bridgetown.logger.info "", path["#{site.root_dir}/".length..] }
66
+ end
62
67
 
63
- c.each { |path| Bridgetown.logger.info "", path["#{site.root_dir}/".length..-1] }
64
68
  process(site, t, options)
65
69
  end
66
70
  end
@@ -101,7 +105,7 @@ module Bridgetown
101
105
  source = Pathname.new(options["source"]).expand_path
102
106
  paths = to_exclude(options)
103
107
 
104
- paths.map do |p|
108
+ paths.filter_map do |p|
105
109
  absolute_path = Pathname.new(normalize_encoding(p, options["source"].encoding)).expand_path
106
110
  next unless absolute_path.exist?
107
111
 
@@ -116,20 +120,25 @@ module Bridgetown
116
120
  rescue ArgumentError
117
121
  # Could not find a relative path
118
122
  end
119
- end.compact + [%r!^\.bridgetown-metadata!]
123
+ end + [%r!^\.bridgetown-metadata!]
120
124
  end
121
125
 
122
126
  def sleep_forever
123
127
  loop { sleep 1000 }
124
128
  end
125
129
 
130
+ # @param site [Bridgetown::Site]
126
131
  def process(site, time, options)
127
132
  begin
128
133
  I18n.reload! # make sure any locale files get read again
134
+ Bridgetown::Current.site = site # needed in SSR mode apparently
129
135
  Bridgetown::Hooks.trigger :site, :pre_reload, site
130
136
  Bridgetown::Hooks.clear_reloadable_hooks
131
137
  site.plugin_manager.reload_plugin_files
132
- site.plugin_manager.reload_component_loaders
138
+ site.loaders_manager.reload_loaders
139
+
140
+ return site.ssr_reload if site.ssr?
141
+
133
142
  site.process
134
143
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
135
144
  " #{(Time.now - time).ceil(2)} seconds."
@@ -11,11 +11,7 @@ module Bridgetown
11
11
  end
12
12
 
13
13
  def load(yaml)
14
- if RUBY_VERSION.start_with?("2.5")
15
- YAML.safe_load yaml, PERMITTED_CLASSES
16
- else
17
- YAML.safe_load yaml, permitted_classes: PERMITTED_CLASSES
18
- end
14
+ YAML.safe_load yaml, permitted_classes: PERMITTED_CLASSES
19
15
  end
20
16
  end
21
17
  end
@@ -16,7 +16,7 @@ Welcome to your new Bridgetown website! You can update this README file to provi
16
16
  - [GCC](https://gcc.gnu.org/install/)
17
17
  - [Make](https://www.gnu.org/software/make/)
18
18
  - [Ruby](https://www.ruby-lang.org/en/downloads/)
19
- - `>= 2.5`
19
+ - `>= 2.7`
20
20
  - [Bridgetown Gem](https://rubygems.org/gems/bridgetown)
21
21
  - `gem install bridgetown -N`
22
22
  - [Node](https://nodejs.org)
@@ -2,6 +2,9 @@ require "bridgetown"
2
2
 
3
3
  Bridgetown.load_tasks
4
4
 
5
+ # Run rake without specifying any command to execute a deploy build by default.
6
+ task default: :deploy
7
+
5
8
  #
6
9
  # Standard set of tasks, which you can customize if you wish:
7
10
  #
@@ -44,6 +47,3 @@ end
44
47
  # say_status :rake, "I'm a Rake tast =) #{site.config.url}"
45
48
  # end
46
49
  # end
47
-
48
- # Run rake without specifying any command to execute a deploy build by default.
49
- task default: :deploy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha6
4
+ version: 1.0.0.alpha7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-26 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -390,11 +390,21 @@ files:
390
390
  - lib/bridgetown-core/configurations/.keep
391
391
  - lib/bridgetown-core/configurations/bt-postcss.rb
392
392
  - lib/bridgetown-core/configurations/bt-postcss/postcss.config.js
393
+ - lib/bridgetown-core/configurations/cypress.rb
394
+ - lib/bridgetown-core/configurations/cypress/cypress.json
395
+ - lib/bridgetown-core/configurations/cypress/cypress_dir/fixtures/example.json
396
+ - lib/bridgetown-core/configurations/cypress/cypress_dir/integration/navbar.spec.js
397
+ - lib/bridgetown-core/configurations/cypress/cypress_dir/plugins/index.js
398
+ - lib/bridgetown-core/configurations/cypress/cypress_dir/support/commands.js
399
+ - lib/bridgetown-core/configurations/cypress/cypress_dir/support/index.js
400
+ - lib/bridgetown-core/configurations/cypress/cypress_tasks
393
401
  - lib/bridgetown-core/configurations/minitesting.rb
394
402
  - lib/bridgetown-core/configurations/netlify.rb
395
403
  - lib/bridgetown-core/configurations/netlify/netlify.sh
396
404
  - lib/bridgetown-core/configurations/netlify/netlify.toml
397
405
  - lib/bridgetown-core/configurations/purgecss.rb
406
+ - lib/bridgetown-core/configurations/render.rb
407
+ - lib/bridgetown-core/configurations/render/render.yaml.erb
398
408
  - lib/bridgetown-core/configurations/stimulus.rb
399
409
  - lib/bridgetown-core/configurations/swup.rb
400
410
  - lib/bridgetown-core/configurations/tailwindcss.rb
@@ -488,6 +498,7 @@ files:
488
498
  - lib/bridgetown-core/utils.rb
489
499
  - lib/bridgetown-core/utils/ansi.rb
490
500
  - lib/bridgetown-core/utils/aux.rb
501
+ - lib/bridgetown-core/utils/loaders_manager.rb
491
502
  - lib/bridgetown-core/utils/require_gems.rb
492
503
  - lib/bridgetown-core/utils/ruby_exec.rb
493
504
  - lib/bridgetown-core/utils/ruby_front_matter.rb
@@ -542,12 +553,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
542
553
  requirements:
543
554
  - - ">="
544
555
  - !ruby/object:Gem::Version
545
- version: 2.5.0
556
+ version: 2.7.0
546
557
  required_rubygems_version: !ruby/object:Gem::Requirement
547
558
  requirements:
548
- - - ">="
559
+ - - ">"
549
560
  - !ruby/object:Gem::Version
550
- version: 2.7.0
561
+ version: 1.3.1
551
562
  requirements: []
552
563
  rubygems_version: 3.1.4
553
564
  signing_key: