bridgetown-core 2.0.0.beta2 ā†’ 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/bridgetown-core.gemspec +43 -42
  4. data/lib/bridgetown-core/cache.rb +3 -19
  5. data/lib/bridgetown-core/cleaner.rb +17 -19
  6. data/lib/bridgetown-core/collection.rb +6 -5
  7. data/lib/bridgetown-core/commands/base.rb +7 -0
  8. data/lib/bridgetown-core/commands/build.rb +35 -22
  9. data/lib/bridgetown-core/commands/concerns/actions.rb +4 -0
  10. data/lib/bridgetown-core/commands/console.rb +0 -1
  11. data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +7 -6
  12. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +14 -13
  13. data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
  14. data/lib/bridgetown-core/commands/esbuild/update.rb +17 -3
  15. data/lib/bridgetown-core/commands/esbuild.rb +1 -1
  16. data/lib/bridgetown-core/commands/start.rb +12 -2
  17. data/lib/bridgetown-core/component.rb +1 -1
  18. data/lib/bridgetown-core/concerns/intuitive_expectations.rb +67 -0
  19. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  20. data/lib/bridgetown-core/concerns/publishable.rb +2 -0
  21. data/lib/bridgetown-core/concerns/site/content.rb +4 -1
  22. data/lib/bridgetown-core/concerns/site/extensible.rb +6 -1
  23. data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +33 -18
  24. data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
  25. data/lib/bridgetown-core/concerns/site/processable.rb +2 -0
  26. data/lib/bridgetown-core/concerns/site/renderable.rb +3 -0
  27. data/lib/bridgetown-core/concerns/site/ssr.rb +1 -2
  28. data/lib/bridgetown-core/concerns/site/writable.rb +1 -0
  29. data/lib/bridgetown-core/concerns/viewable.rb +46 -0
  30. data/lib/bridgetown-core/configuration.rb +29 -23
  31. data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +5 -5
  32. data/lib/bridgetown-core/configurations/minitesting.rb +24 -64
  33. data/lib/bridgetown-core/converter.rb +2 -7
  34. data/lib/bridgetown-core/converters/erb_templates.rb +11 -7
  35. data/lib/bridgetown-core/converters/identity.rb +3 -11
  36. data/lib/bridgetown-core/converters/liquid_templates.rb +3 -5
  37. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  38. data/lib/bridgetown-core/converters/markdown.rb +11 -14
  39. data/lib/bridgetown-core/converters/serbea_templates.rb +10 -8
  40. data/lib/bridgetown-core/drops/drop.rb +29 -42
  41. data/lib/bridgetown-core/drops/resource_drop.rb +3 -12
  42. data/lib/bridgetown-core/errors.rb +2 -8
  43. data/lib/bridgetown-core/filters/condition_helpers.rb +6 -9
  44. data/lib/bridgetown-core/filters/date_filters.rb +22 -35
  45. data/lib/bridgetown-core/filters/grouping_filters.rb +11 -11
  46. data/lib/bridgetown-core/filters.rb +53 -72
  47. data/lib/bridgetown-core/front_matter/defaults.rb +14 -19
  48. data/lib/bridgetown-core/generated_page.rb +6 -6
  49. data/lib/bridgetown-core/generators/prototype_generator.rb +0 -2
  50. data/lib/bridgetown-core/helpers.rb +2 -2
  51. data/lib/bridgetown-core/hooks.rb +0 -1
  52. data/lib/bridgetown-core/layout.rb +3 -4
  53. data/lib/bridgetown-core/liquid_extensions.rb +3 -5
  54. data/lib/bridgetown-core/log_adapter.rb +37 -56
  55. data/lib/bridgetown-core/plugin_manager.rb +7 -3
  56. data/lib/bridgetown-core/rack/boot.rb +7 -57
  57. data/lib/bridgetown-core/rack/default_config.ru +14 -0
  58. data/lib/bridgetown-core/rack/loader_hooks.rb +83 -0
  59. data/lib/bridgetown-core/rack/logger.rb +0 -2
  60. data/lib/bridgetown-core/rack/routes.rb +3 -2
  61. data/lib/bridgetown-core/resource/base.rb +8 -8
  62. data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
  63. data/lib/bridgetown-core/resource/relations.rb +3 -1
  64. data/lib/bridgetown-core/ruby_template_view.rb +0 -1
  65. data/lib/bridgetown-core/static_file.rb +15 -20
  66. data/lib/bridgetown-core/tags/class_map.rb +1 -1
  67. data/lib/bridgetown-core/tags/post_url.rb +2 -32
  68. data/lib/bridgetown-core/utils/initializers.rb +2 -2
  69. data/lib/bridgetown-core/utils/require_gems.rb +1 -3
  70. data/lib/bridgetown-core/utils.rb +41 -44
  71. data/lib/bridgetown-core/watcher.rb +2 -3
  72. data/lib/bridgetown-core.rb +29 -10
  73. data/lib/roda/plugins/bridgetown_server.rb +13 -25
  74. data/lib/roda/plugins/bridgetown_ssr.rb +21 -3
  75. data/lib/roda/plugins/flashier.rb +57 -0
  76. data/lib/roda/plugins/generic_index.html +127 -0
  77. data/lib/roda/plugins/ssg.rb +3 -2
  78. data/lib/site_template/config/initializers.rb +2 -0
  79. data/lib/site_template/package.json.erb +1 -0
  80. data/lib/site_template/postcss.config.js.erb +1 -1
  81. metadata +26 -7
  82. data/lib/bridgetown-core/commands/doctor.rb +0 -147
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad323d78c36221049d27482e186a24793c5e52b478e913b778ba0d8809658990
4
- data.tar.gz: dfc80b46023d5f28e38f2116e62676f579d175f1fcca023c46bb921298c99dc7
3
+ metadata.gz: 813f0bb565e3342b5eb466d6f3f65575adec5ba64d0a355c29c49f74925ee695
4
+ data.tar.gz: b8141708de43e8035b04ce2085fded27ddd5f4b5657ed53143c80ccf26927b5e
5
5
  SHA512:
6
- metadata.gz: b0a025a6629018fc3cd5687f6675aee4ce0f4ef0edb740c35b1ba45f1f77df3fc6bb85b658d52a469d9b7f2e83820efcb636a9e062d1b196372fb8cb0b3b447e
7
- data.tar.gz: a7af845632eda73b48f00fe07863f2b90f287e35402239203be296808aa5ae57d41fb3e8a498882254ed3407022f5f88d0895e0e81d59d861f83794f6bdbef76
6
+ metadata.gz: acad0c9039fcad0cf8654b19672b149ef660cc2adb75307a810d9379695a54398c6dbaffb206f850b2272e831b2280853f82b20e35115c0454457e21ec22c055
7
+ data.tar.gz: 51af878741c57eac002b78b3690887703d0469f851f6b980203f187d5731282feec110d91ad0abafa60fc99d3ba813d39b8174a22931d32daf4eb209511774e1
data/.rubocop.yml CHANGED
@@ -43,3 +43,6 @@ Style/OpenStructUse:
43
43
  Style/StringConcatenation:
44
44
  Exclude:
45
45
  - test/test_apply_command.rb
46
+
47
+ Style/SafeNavigationChainLength:
48
+ Enabled: false
@@ -2,58 +2,59 @@
2
2
 
3
3
  require_relative "../bridgetown-foundation/lib/bridgetown/version"
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = "bridgetown-core"
7
- s.version = Bridgetown::VERSION
8
- s.license = "MIT"
9
- s.author = "Bridgetown Team"
10
- s.email = "maintainers@bridgetownrb.com"
11
- s.homepage = "https://www.bridgetownrb.com"
12
- s.summary = "A next-generation, progressive site generator & fullstack framework, powered by Ruby"
13
- s.description = "Bridgetown is a next-generation, progressive site generator & fullstack framework, powered by Ruby"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridgetown-core"
7
+ spec.version = Bridgetown::VERSION
8
+ spec.license = "MIT"
9
+ spec.author = "Bridgetown Team"
10
+ spec.email = "maintainers@bridgetownrb.com"
11
+ spec.homepage = "https://www.bridgetownrb.com"
12
+ spec.summary = "A next-generation, progressive site generator & fullstack framework, powered by Ruby"
13
+ spec.description = "Bridgetown is a next-generation, progressive site generator & fullstack framework, powered by Ruby"
14
14
 
15
- s.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
16
  f.match(%r!^(benchmark|features|script|test)/!)
17
17
  end
18
- s.executables = ["bridgetown", "bt"] # `bt` is a shortcut to `bridgetown` command
19
- s.bindir = "bin"
20
- s.require_paths = ["lib"]
18
+ spec.executables = ["bridgetown", "bt"] # `bt` is a shortcut to `bridgetown` command
19
+ spec.bindir = "bin"
20
+ spec.require_paths = ["lib"]
21
21
 
22
- s.metadata = {
22
+ spec.metadata = {
23
23
  "source_code_uri" => "https://github.com/bridgetownrb/bridgetown",
24
24
  "bug_tracker_uri" => "https://github.com/bridgetownrb/bridgetown/issues",
25
25
  "changelog_uri" => "https://github.com/bridgetownrb/bridgetown/releases",
26
- "homepage_uri" => s.homepage,
26
+ "homepage_uri" => spec.homepage,
27
27
  "rubygems_mfa_required" => "true",
28
28
  }
29
29
 
30
- s.rdoc_options = ["--charset=UTF-8"]
30
+ spec.rdoc_options = ["--charset=UTF-8"]
31
31
 
32
- s.required_ruby_version = ">= 3.1.0"
32
+ spec.required_ruby_version = ">= 3.1.0"
33
33
 
34
- s.add_runtime_dependency("activesupport", [">= 6.0", "< 8.0"])
35
- s.add_runtime_dependency("addressable", "~> 2.4")
36
- s.add_runtime_dependency("amazing_print", "~> 1.2")
37
- s.add_runtime_dependency("bridgetown-foundation", Bridgetown::VERSION)
38
- s.add_runtime_dependency("csv", "~> 3.2")
39
- s.add_runtime_dependency("dry-inflector", ">= 1.0")
40
- s.add_runtime_dependency("erubi", "~> 1.9")
41
- s.add_runtime_dependency("faraday", "~> 2.0")
42
- s.add_runtime_dependency("faraday-follow_redirects", "~> 0.3")
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", "< 5.5"])
47
- s.add_runtime_dependency("listen", "~> 3.0")
48
- s.add_runtime_dependency("rack", ">= 3.0")
49
- s.add_runtime_dependency("rackup", "~> 2.0")
50
- s.add_runtime_dependency("rake", ">= 13.0")
51
- s.add_runtime_dependency("roda", "~> 3.46")
52
- s.add_runtime_dependency("rouge", [">= 3.0", "< 5.0"])
53
- s.add_runtime_dependency("serbea", "~> 2.1")
54
- s.add_runtime_dependency("signalize", "~> 1.3")
55
- s.add_runtime_dependency("streamlined", ">= 0.5.2")
56
- s.add_runtime_dependency("thor", "~> 1.1")
57
- s.add_runtime_dependency("tilt", "~> 2.0")
58
- s.add_runtime_dependency("zeitwerk", "~> 2.5")
34
+ spec.add_dependency("activesupport", [">= 6.0", "< 8.0"])
35
+ spec.add_dependency("addressable", "~> 2.4")
36
+ spec.add_dependency("amazing_print", "~> 1.2")
37
+ spec.add_dependency("bridgetown-foundation", Bridgetown::VERSION)
38
+ spec.add_dependency("csv", "~> 3.2")
39
+ spec.add_dependency("dry-inflector", ">= 1.0")
40
+ spec.add_dependency("erubi", "~> 1.9")
41
+ spec.add_dependency("faraday", "~> 2.0")
42
+ spec.add_dependency("faraday-follow_redirects", "~> 0.3")
43
+ spec.add_dependency("i18n", "~> 1.0")
44
+ spec.add_dependency("irb", ">= 1.14")
45
+ spec.add_dependency("kramdown", "~> 2.1")
46
+ spec.add_dependency("kramdown-parser-gfm", "~> 1.0")
47
+ spec.add_dependency("liquid", [">= 5.0", "< 5.5"])
48
+ spec.add_dependency("listen", "~> 3.0")
49
+ spec.add_dependency("rack", ">= 3.0")
50
+ spec.add_dependency("rackup", "~> 2.0")
51
+ spec.add_dependency("rake", ">= 13.0")
52
+ spec.add_dependency("roda", "~> 3.46")
53
+ spec.add_dependency("rouge", [">= 3.0", "< 5.0"])
54
+ spec.add_dependency("serbea", "~> 2.1")
55
+ spec.add_dependency("signalize", "~> 1.3")
56
+ spec.add_dependency("streamlined", ">= 0.6.0")
57
+ spec.add_dependency("thor", "~> 1.1")
58
+ spec.add_dependency("tilt", "~> 2.0")
59
+ spec.add_dependency("zeitwerk", "~> 2.5")
59
60
  end
@@ -33,8 +33,6 @@ module Bridgetown
33
33
 
34
34
  # Compare the current config to the cached config
35
35
  # If they are different, clear all caches
36
- #
37
- # Returns nothing.
38
36
  def clear_if_config_changed(config)
39
37
  config = config.inspect
40
38
  cache = Bridgetown::Cache.new "Bridgetown::Cache"
@@ -49,8 +47,6 @@ module Bridgetown
49
47
  private
50
48
 
51
49
  # Delete all cached items from all caches
52
- #
53
- # Returns nothing.
54
50
  def delete_cache_files
55
51
  FileUtils.rm_rf(@cache_dir) if disk_cache_enabled
56
52
  end
@@ -60,9 +56,7 @@ module Bridgetown
60
56
 
61
57
  # Get an existing named cache, or create a new one if none exists
62
58
  #
63
- # name - name of the cache
64
- #
65
- # Returns nothing.
59
+ # @param name [String] name of the cache
66
60
  def initialize(name)
67
61
  @cache = Bridgetown::Cache.base_cache[name] ||= {}
68
62
  @name = name.gsub(%r![^\w\s-]!, "-")
@@ -77,7 +71,7 @@ module Bridgetown
77
71
  # Retrieve a cached item
78
72
  # Raises if key does not exist in cache
79
73
  #
80
- # Returns cached value
74
+ # @return [Object] cached value
81
75
  def [](key)
82
76
  return @cache[key] if @cache.key?(key)
83
77
 
@@ -88,8 +82,6 @@ module Bridgetown
88
82
  end
89
83
 
90
84
  # Add an item to cache
91
- #
92
- # Returns nothing.
93
85
  def []=(key, value)
94
86
  @cache[key] = value
95
87
  return unless disk_cache_enabled?
@@ -112,8 +104,6 @@ module Bridgetown
112
104
  end
113
105
 
114
106
  # Remove one particular item from the cache
115
- #
116
- # Returns nothing.
117
107
  def delete(key)
118
108
  @cache.delete(key)
119
109
  File.delete(path_to(hash(key))) if disk_cache_enabled?
@@ -121,7 +111,7 @@ module Bridgetown
121
111
 
122
112
  # Check if `key` already exists in this cache
123
113
  #
124
- # Returns true if key exists in the cache, false otherwise
114
+ # @return [Boolean] true if key exists in the cache, false otherwise
125
115
  def key?(key)
126
116
  # First, check if item is already cached in memory
127
117
  return true if @cache.key?(key)
@@ -153,14 +143,11 @@ module Bridgetown
153
143
  end
154
144
 
155
145
  # Remove all this caches items from disk
156
- #
157
- # Returns nothing.
158
146
  def delete_cache_files
159
147
  FileUtils.rm_rf(path_to) if disk_cache_enabled?
160
148
  end
161
149
 
162
150
  # Load `path` from disk and return the result.
163
- # This MUST NEVER be called in Safe Mode
164
151
  # rubocop:disable Security/MarshalLoad
165
152
  def load(path)
166
153
  raise unless disk_cache_enabled?
@@ -173,9 +160,6 @@ module Bridgetown
173
160
  # rubocop:enable Security/MarshalLoad
174
161
 
175
162
  # Given a path and a value, save value to disk at path.
176
- # This should NEVER be called in Safe Mode
177
- #
178
- # Returns nothing.
179
163
  def dump(path, value)
180
164
  return unless disk_cache_enabled?
181
165
 
@@ -17,9 +17,9 @@ module Bridgetown
17
17
 
18
18
  private
19
19
 
20
- # Private: The list of files and directories to be deleted during cleanup process
20
+ # The list of files and directories to be deleted during cleanup process
21
21
  #
22
- # Returns an Array of the file and directory paths
22
+ # @return [Array<String>] file and directory paths
23
23
  def obsolete_files
24
24
  out = (existing_files - new_files - new_dirs + replaced_files).to_a
25
25
  Bridgetown::Hooks.trigger :clean, :on_obsolete, out
@@ -27,10 +27,9 @@ module Bridgetown
27
27
  out
28
28
  end
29
29
 
30
- # Private: The list of existing files, apart from those included in
31
- # keep_files and hidden files.
30
+ # The list of existing files, apart from those included in keep_files and hidden files
32
31
  #
33
- # Returns a Set with the file paths
32
+ # @return [Set<String>] file paths
34
33
  def existing_files
35
34
  files = Set.new
36
35
  regex = keep_file_regex
@@ -45,9 +44,9 @@ module Bridgetown
45
44
  files
46
45
  end
47
46
 
48
- # Private: The list of files to be created when site is built.
47
+ # The list of files to be created when site is built.
49
48
  #
50
- # Returns a Set with the file paths
49
+ # @return [Set<String>] file paths
51
50
  def new_files
52
51
  @new_files ||= Set.new.tap do |files|
53
52
  site.each_site_file do |item|
@@ -60,17 +59,17 @@ module Bridgetown
60
59
  end
61
60
  end
62
61
 
63
- # Private: The list of directories to be created when site is built.
62
+ # The list of directories to be created when site is built.
64
63
  # These are the parent directories of the files in #new_files.
65
64
  #
66
- # Returns a Set with the directory paths
65
+ # @return [Set<String>] directory paths
67
66
  def new_dirs
68
67
  @new_dirs ||= new_files.flat_map { |file| parent_dirs(file) }.to_set
69
68
  end
70
69
 
71
- # Private: The list of parent directories of a given file
70
+ # The list of parent directories of a given file
72
71
  #
73
- # Returns an Array with the directory paths
72
+ # @return [Array<String>] directory paths
74
73
  def parent_dirs(file)
75
74
  parent_dir = File.dirname(file)
76
75
  if parent_dir == site.dest
@@ -80,29 +79,28 @@ module Bridgetown
80
79
  end
81
80
  end
82
81
 
83
- # Private: The list of existing files that will be replaced by a directory
84
- # during build
82
+ # The list of existing files that will be replaced by a directory during build
85
83
  #
86
- # Returns a Set with the file paths
84
+ # @return [Set<String>] file paths
87
85
  def replaced_files
88
86
  new_dirs.select { |dir| File.file?(dir) }.to_set
89
87
  end
90
88
 
91
- # Private: The list of directories that need to be kept because they are
89
+ # The list of directories that need to be kept because they are
92
90
  # parent directories of files specified in keep_files
93
91
  #
94
- # Returns a Set with the directory paths
92
+ # @return [Set<String>] directory paths
95
93
  def keep_dirs
96
94
  site.config.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
97
95
  end
98
96
 
99
- # Private: Creates a regular expression from the config's keep_files array
97
+ # Creates a regular expression from the config's keep_files array
100
98
  #
101
- # Examples
99
+ # @example
102
100
  # ['.git','.svn'] with site.dest "/myblog/_site" creates
103
101
  # the following regex: /\A\/myblog\/_site\/(\.git|\/.svn)/
104
102
  #
105
- # Returns the regular expression
103
+ # @return [Regexp]
106
104
  def keep_file_regex
107
105
  %r!\A#{Regexp.quote(site.dest)}/(#{Regexp.union(site.config.keep_files).source})!
108
106
  end
@@ -55,13 +55,13 @@ module Bridgetown
55
55
  # Iterate over Resources by delegating to `resources.each` (supports Enumerable)
56
56
  def each(...) = resources.each(...)
57
57
 
58
- # Delgates to `resources.last`
58
+ # Delegates to `resources.last`
59
59
  def last(...) = resources.last(...)
60
60
 
61
- # Delgates to `resources.deconstruct`
61
+ # Delegates to `resources.deconstruct`
62
62
  def deconstruct = resources.deconstruct
63
63
 
64
- # Delgates to `resources[]`
64
+ # Delegates to `resources[]`
65
65
  def [](...) = resources.[](...)
66
66
 
67
67
  # Fetch the static files in this collection.
@@ -184,7 +184,8 @@ module Bridgetown
184
184
  #
185
185
  # @return [String]
186
186
  def inspect
187
- "#<#{self.class} @label=#{label} resources=#{resources}>"
187
+ "#<#{self.class} #{label}: #{resources.count} metadata=#{metadata.inspect} " \
188
+ "static_files: #{static_files.count}>"
188
189
  end
189
190
 
190
191
  # Produce a sanitized label name
@@ -400,7 +401,7 @@ module Bridgetown
400
401
 
401
402
  def model_id_from_relative_path(model_relative_path, manifest: nil)
402
403
  scheme = manifest ? "plugin" : "repo"
403
- id = +"#{scheme}://#{label}.collection/"
404
+ id = "#{scheme}://#{label}.collection/"
404
405
  id += "#{manifest.origin}/" if manifest
405
406
  id += Addressable::URI.escape(model_relative_path).gsub("#", "%23")
406
407
  id
@@ -66,6 +66,13 @@ module Bridgetown
66
66
  puts "Unknown task: #{cmd.split("[")[0]}\n\nHere's a list of tasks you can run:"
67
67
  display_rake_tasks(rake)
68
68
  end
69
+ rescue RuntimeError => e
70
+ # re-raise error unless it's an error through Minitest
71
+ raise e unless e.message.include?("ruby -Ilib:test")
72
+
73
+ Bridgetown.logger.error "test aborted!"
74
+ Bridgetown.logger.error e.message
75
+ exit(false)
69
76
  end
70
77
  end
71
78
  end
@@ -50,11 +50,7 @@ module Bridgetown
50
50
  if Bridgetown::Utils.frontend_bundler_type(config_options[:root_dir]) == :esbuild
51
51
  Bridgetown::Utils.update_esbuild_autogenerated_config config_options
52
52
  end
53
- require "rake"
54
- Rake.with_application do |rake|
55
- rake.load_rakefile
56
- rake["frontend:watcher"].invoke(true)
57
- end
53
+ invoke_frontend_watcher_from_rake
58
54
  end
59
55
 
60
56
  @site = Bridgetown::Site.new(config_options)
@@ -66,11 +62,7 @@ module Bridgetown
66
62
  build_site(config_options)
67
63
  end
68
64
 
69
- # TODO: remove this logicā€¦I can't find "detach" anywhere
70
- if config_options.fetch("detach", false)
71
- Bridgetown.logger.info "Auto-regeneration:",
72
- "disabled when running server detached."
73
- elsif config_options.fetch("watch", false)
65
+ if config_options.fetch("watch", false)
74
66
  watch_site(config_options)
75
67
  else
76
68
  Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
@@ -79,11 +71,9 @@ module Bridgetown
79
71
 
80
72
  protected
81
73
 
82
- # Build your Bridgetown site.
83
- #
84
- # options - A Hash of options passed to the command or loaded from config
74
+ # Build your Bridgetown site
85
75
  #
86
- # Returns nothing.
76
+ # @param options [Bridgetown::Configuration] options loaded from config and/or CLI
87
77
  def build_site(config_options)
88
78
  t = Time.now
89
79
  display_folder_paths(config_options)
@@ -97,32 +87,55 @@ module Bridgetown
97
87
  "#{(Time.now - t).ceil(2)} seconds."
98
88
  end
99
89
 
100
- # Watch for file changes and rebuild the site.
101
- #
102
- # options - A Hash of options passed to the command or loaded from config
90
+ # Watch for file changes and rebuild the site
103
91
  #
104
- # Returns nothing.
92
+ # @param options [Bridgetown::Configuration] options loaded from config and/or CLI
105
93
  def watch_site(config_options)
94
+ if config_options["url"]&.include?("://localhost")
95
+ require "socket"
96
+ external_ip = Socket.ip_address_list.find do |ai|
97
+ ai.ipv4? && !ai.ipv4_loopback?
98
+ end&.ip_address
99
+ scheme = config_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
100
+ port = ENV.fetch("BRIDGETOWN_PORT", config_options.port)
101
+ Bridgetown.logger.info ""
102
+ Bridgetown.logger.info "Now serving at:", "#{scheme}://localhost:#{port}".magenta
103
+ Bridgetown.logger.info "", "#{scheme}://#{external_ip}:#{port}".magenta if external_ip
104
+ Bridgetown.logger.info ""
105
+ end
106
+
106
107
  Bridgetown::Watcher.watch(@site, config_options)
107
108
  end
108
109
 
109
110
  # Display the source and destination folder paths
110
111
  #
111
- # options - A Hash of options passed to the command
112
- #
113
- # Returns nothing.
112
+ # @param options [Bridgetown::Configuration] options loaded from config and/or CLI
114
113
  def display_folder_paths(config_options)
115
114
  source = File.expand_path(config_options["source"])
116
115
  destination = File.expand_path(config_options["destination"])
117
116
  Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
118
117
  Bridgetown.logger.info "Source:", source
119
118
  Bridgetown.logger.info "Destination:", destination
120
- # TODO: work with arrays
121
119
  return unless config_options["plugins_dir"].is_a?(String)
122
120
 
123
121
  plugins_dir = File.expand_path(config_options["plugins_dir"])
124
122
  Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
125
123
  end
124
+
125
+ def invoke_frontend_watcher_from_rake
126
+ require "rake"
127
+ Rake.with_application do |rake|
128
+ begin
129
+ rake.raw_load_rakefile
130
+ rescue StandardError => e
131
+ unless e.message.include?("No Rakefile found")
132
+ Bridgetown.logger.error "Error Running Rake:", "#{e.message} (#{e.class})"
133
+ e.backtrace[0..1].each { |backtrace_line| Bridgetown.logger.info backtrace_line }
134
+ end
135
+ end
136
+ rake["frontend:watcher"].invoke(true) if rake.tasks.any? { _1.name == "frontend:watcher" }
137
+ end
138
+ end
126
139
  end
127
140
  end
128
141
  end
@@ -116,6 +116,10 @@ module Bridgetown
116
116
  run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_install_command} #{package_details}" # rubocop:disable Layout
117
117
  end
118
118
 
119
+ def remove_npm_package(package_details)
120
+ run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_uninstall_command} #{package_details}" # rubocop:disable Layout
121
+ end
122
+
119
123
  def apply_from_url(url)
120
124
  apply transform_automation_url(url.dup)
121
125
  end
@@ -80,7 +80,6 @@ module Bridgetown
80
80
 
81
81
  config_options = configuration_with_overrides(options)
82
82
  if options[:"server-config"]
83
- require "puma"
84
83
  require "bridgetown-core/rack/boot"
85
84
  Bridgetown::Rack.boot
86
85
  else
@@ -1,16 +1,17 @@
1
- const build = require("./config/esbuild.defaults.js")
1
+ import build from "./config/esbuild.defaults.js"
2
2
 
3
3
  // You can customize this as you wish, perhaps to add new esbuild plugins.
4
4
  //
5
5
  // ```
6
- // const path = require("path")
7
- // const esbuildCopy = require('esbuild-plugin-copy').default
6
+ // import { copy } from 'esbuild-plugin-copy'
7
+ //
8
8
  // const esbuildOptions = {
9
9
  // plugins: [
10
- // esbuildCopy({
10
+ // copy({
11
+ // resolveFrom: 'cwd',
11
12
  // assets: {
12
- // from: [path.resolve(__dirname, 'node_modules/somepackage/files/*')],
13
- // to: [path.resolve(__dirname, 'output/_bridgetown/somepackage/files')],
13
+ // from: ['./node_modules/somepackage/files/*')],
14
+ // to: ['./output/_bridgetown/somepackage/files')],
14
15
  // },
15
16
  // verbose: false
16
17
  // }),
@@ -16,19 +16,19 @@ const autogeneratedBridgetownConfig = {
16
16
  "islandsDir": "_islands"
17
17
  }
18
18
 
19
- const path = require("path")
20
- const fsLib = require("fs")
19
+ import path from "path"
20
+ import fsLib from "fs"
21
21
  const fs = fsLib.promises
22
- const { pathToFileURL, fileURLToPath } = require("url")
23
- const glob = require("glob")
24
- const postcss = require("postcss")
25
- const postCssImport = require("postcss-import")
26
- const readCache = require("read-cache")
22
+ import { pathToFileURL, fileURLToPath } from "url"
23
+ import { glob } from "glob"
24
+ import postcss from "postcss"
25
+ import postCssImport from "postcss-import"
26
+ import readCache from "read-cache"
27
27
 
28
28
  // Detect if an NPM package is available
29
29
  const moduleAvailable = name => {
30
30
  try {
31
- require.resolve(name)
31
+ import.meta.resolve(name)
32
32
  return true
33
33
  } catch (e) { }
34
34
  return false
@@ -43,7 +43,7 @@ const generateSourceMappingURL = sourceMap => {
43
43
  // Import Sass if available
44
44
  let sass
45
45
  if (moduleAvailable("sass")) {
46
- sass = require("sass")
46
+ sass = (await import("sass")).default
47
47
  }
48
48
 
49
49
  // Glob plugin derived from:
@@ -288,9 +288,9 @@ const bridgetownConfigured = (bridgetownConfig, outputFolder) => {
288
288
  }
289
289
 
290
290
  // Load the PostCSS config from postcss.config.js or whatever else is a supported location/format
291
- const postcssrc = require("postcss-load-config")
291
+ const postcssrc = (await import("postcss-load-config")).default
292
292
 
293
- module.exports = async (esbuildOptions, ...args) => {
293
+ export default async (esbuildOptions, ...args) => {
294
294
  let outputFolder;
295
295
  if (typeof esbuildOptions === "string") { // legacy syntax where first argument is output folder
296
296
  outputFolder = esbuildOptions
@@ -313,11 +313,12 @@ module.exports = async (esbuildOptions, ...args) => {
313
313
  esbuildOptions.plugins.push(bridgetownPreset(bridgetownConfig))
314
314
  if (esbuildOptions.bridgetownConfig) delete esbuildOptions.bridgetownConfig
315
315
 
316
- const esbuild = require("esbuild")
316
+ const esbuild = (await import("esbuild")).default
317
317
  const entryPoints = esbuildOptions.entryPoints || ["./frontend/javascript/index.js"]
318
318
  if (esbuildOptions.entryPoints) delete esbuildOptions.entryPoints
319
319
 
320
320
  const islands = glob.sync(`./${bridgetownConfig.source}/${bridgetownConfig.islandsDir}/*.{js,js.rb}`).map(item => `./${item}`)
321
+ const islandsAsObject = islands.reduce((obj, str) => obj[str] = str, {})
321
322
 
322
323
  esbuild.context({
323
324
  bundle: true,
@@ -339,7 +340,7 @@ module.exports = async (esbuildOptions, ...args) => {
339
340
  minify: process.argv.includes("--minify"),
340
341
  sourcemap: true,
341
342
  target: "es2020",
342
- entryPoints: [...entryPoints, ...islands],
343
+ entryPoints: Array.isArray(entryPoints) ? [...entryPoints, ...islands] : {...entryPoints, ...islandsAsObject},
343
344
  entryNames: "[dir]/[name].[hash]",
344
345
  outdir: path.join(process.cwd(), `${bridgetownConfig.destination}/_bridgetown/static`),
345
346
  publicPath: "/_bridgetown/static",
@@ -25,7 +25,7 @@ unless Bridgetown.environment.test?
25
25
  confirm = ask "\nThe following packages will be removed: \n\n#{packages_to_remove.join("\n")}\n\nWould you like to continue? [Yn]"
26
26
  return unless confirm.casecmp?("Y")
27
27
 
28
- run "yarn remove #{packages_to_remove.join(" ")}"
28
+ remove_npm_package packages_to_remove.join(" ")
29
29
  end
30
30
  end
31
31
 
@@ -2,8 +2,22 @@
2
2
 
3
3
  template "esbuild.defaults.js.erb", "config/esbuild.defaults.js", force: true
4
4
  copy_file "jsconfig.json"
5
- say "šŸŽ‰ esbuild configuration updated successfully!"
5
+
6
+ unless File.read("package.json").include?('"type": "module"')
7
+ insert_into_file "package.json",
8
+ after: '"private": true,' do
9
+ <<-JS.chomp
10
+
11
+ "type": "module",
12
+ JS
13
+ end
14
+ end
15
+
16
+ gsub_file "postcss.config.js", "module.exports =", "export default"
17
+ gsub_file "esbuild.config.js", 'const build = require("./config/esbuild.defaults.js")',
18
+ 'import build from "./config/esbuild.defaults.js"'
19
+ add_npm_package "esbuild@latest glob@latest" unless Bridgetown.env.test?
20
+
21
+ say "\nšŸŽ‰ esbuild configuration updated successfully!"
6
22
  say "You may need to add `$styles/` to the front of your main CSS imports."
7
23
  say "See https://www.bridgetownrb.com/docs/frontend-assets#esbuild-setup for details."
8
- say "āš ļø Don't forget to update the esbuild version in your `package.json` file to \"^0.20.2\""
9
- say "and run `npm install`!"
@@ -3,7 +3,7 @@
3
3
  module Bridgetown
4
4
  module Commands
5
5
  class Esbuild < Thor::Group
6
- include Thor::Actions
6
+ include Thor::Actions, Bridgetown::Commands::Actions
7
7
  extend Summarizable
8
8
 
9
9
  Registrations.register do