bridgetown-core 1.3.4 → 2.0.0.beta2

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.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -1
  3. data/bin/bridgetown +0 -6
  4. data/bin/bt +6 -0
  5. data/bridgetown-core.gemspec +10 -7
  6. data/lib/bridgetown-core/cleaner.rb +1 -1
  7. data/lib/bridgetown-core/collection.rb +37 -18
  8. data/lib/bridgetown-core/commands/build.rb +9 -22
  9. data/lib/bridgetown-core/commands/concerns/actions.rb +15 -8
  10. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +1 -1
  11. data/lib/bridgetown-core/commands/console.rb +3 -0
  12. data/lib/bridgetown-core/commands/doctor.rb +2 -4
  13. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +1 -1
  14. data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
  15. data/lib/bridgetown-core/commands/esbuild/update.rb +2 -2
  16. data/lib/bridgetown-core/commands/esbuild.rb +3 -3
  17. data/lib/bridgetown-core/commands/new.rb +32 -39
  18. data/lib/bridgetown-core/commands/start.rb +76 -60
  19. data/lib/bridgetown-core/component.rb +19 -13
  20. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  21. data/lib/bridgetown-core/concerns/prioritizable.rb +11 -1
  22. data/lib/bridgetown-core/concerns/site/configurable.rb +7 -18
  23. data/lib/bridgetown-core/concerns/site/content.rb +10 -9
  24. data/lib/bridgetown-core/concerns/site/extensible.rb +4 -6
  25. data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +161 -0
  26. data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
  27. data/lib/bridgetown-core/concerns/site/renderable.rb +31 -7
  28. data/lib/bridgetown-core/concerns/site/ssr.rb +23 -9
  29. data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
  30. data/lib/bridgetown-core/concerns/transformable.rb +3 -5
  31. data/lib/bridgetown-core/configuration/configuration_dsl.rb +23 -14
  32. data/lib/bridgetown-core/configuration.rb +67 -114
  33. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -2
  34. data/lib/bridgetown-core/configurations/cypress/cypress_tasks +2 -2
  35. data/lib/bridgetown-core/configurations/cypress.rb +1 -1
  36. data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +3 -3
  37. data/lib/bridgetown-core/configurations/is-land.rb +1 -1
  38. data/lib/bridgetown-core/configurations/lit.rb +1 -1
  39. data/lib/bridgetown-core/configurations/open-props.rb +1 -1
  40. data/lib/bridgetown-core/configurations/purgecss.rb +1 -1
  41. data/lib/bridgetown-core/configurations/ruby2js.rb +1 -1
  42. data/lib/bridgetown-core/configurations/shoelace.rb +8 -20
  43. data/lib/bridgetown-core/configurations/stimulus.rb +17 -36
  44. data/lib/bridgetown-core/configurations/turbo.rb +1 -2
  45. data/lib/bridgetown-core/converter.rb +38 -10
  46. data/lib/bridgetown-core/converters/erb_templates.rb +9 -26
  47. data/lib/bridgetown-core/converters/identity.rb +1 -1
  48. data/lib/bridgetown-core/converters/liquid_templates.rb +2 -20
  49. data/lib/bridgetown-core/converters/ruby_templates.rb +61 -3
  50. data/lib/bridgetown-core/converters/serbea_templates.rb +12 -24
  51. data/lib/bridgetown-core/current.rb +19 -17
  52. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  53. data/lib/bridgetown-core/drops/drop.rb +3 -3
  54. data/lib/bridgetown-core/drops/relations_drop.rb +3 -2
  55. data/lib/bridgetown-core/drops/site_drop.rb +0 -5
  56. data/lib/bridgetown-core/entry_filter.rb +4 -6
  57. data/lib/bridgetown-core/errors.rb +2 -2
  58. data/lib/bridgetown-core/filters/from_liquid.rb +6 -10
  59. data/lib/bridgetown-core/filters/localization_filters.rb +1 -1
  60. data/lib/bridgetown-core/filters/translation_filters.rb +2 -2
  61. data/lib/bridgetown-core/filters.rb +3 -3
  62. data/lib/bridgetown-core/front_matter/defaults.rb +225 -0
  63. data/lib/bridgetown-core/front_matter/importer.rb +34 -0
  64. data/lib/bridgetown-core/front_matter/loaders/base.rb +29 -0
  65. data/lib/bridgetown-core/front_matter/loaders/ruby.rb +113 -0
  66. data/lib/bridgetown-core/front_matter/loaders/yaml.rb +42 -0
  67. data/lib/bridgetown-core/front_matter/loaders.rb +44 -0
  68. data/lib/bridgetown-core/{utils/ruby_front_matter.rb → front_matter/ruby.rb} +5 -5
  69. data/lib/bridgetown-core/front_matter.rb +11 -0
  70. data/lib/bridgetown-core/generated_page.rb +71 -31
  71. data/lib/bridgetown-core/generators/prototype_generator.rb +30 -18
  72. data/lib/bridgetown-core/helpers.rb +36 -47
  73. data/lib/bridgetown-core/hooks.rb +5 -5
  74. data/lib/bridgetown-core/inflector.rb +40 -0
  75. data/lib/bridgetown-core/kramdown/parser/gfm.rb +2 -2
  76. data/lib/bridgetown-core/layout.rb +3 -3
  77. data/lib/bridgetown-core/log_adapter.rb +12 -13
  78. data/lib/bridgetown-core/log_writer.rb +4 -4
  79. data/lib/bridgetown-core/model/base.rb +17 -17
  80. data/lib/bridgetown-core/model/builder_origin.rb +5 -3
  81. data/lib/bridgetown-core/model/origin.rb +1 -3
  82. data/lib/bridgetown-core/model/repo_origin.rb +12 -14
  83. data/lib/bridgetown-core/plugin.rb +0 -1
  84. data/lib/bridgetown-core/plugin_manager.rb +38 -84
  85. data/lib/bridgetown-core/rack/boot.rb +0 -15
  86. data/lib/bridgetown-core/rack/routes.rb +30 -90
  87. data/lib/bridgetown-core/reader.rb +6 -4
  88. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  89. data/lib/bridgetown-core/readers/plugin_content_reader.rb +2 -2
  90. data/lib/bridgetown-core/resource/base.rb +112 -29
  91. data/lib/bridgetown-core/resource/destination.rb +1 -1
  92. data/lib/bridgetown-core/resource/relations.rb +11 -8
  93. data/lib/bridgetown-core/resource/taxonomy_type.rb +3 -1
  94. data/lib/bridgetown-core/resource/transformer.rb +4 -4
  95. data/lib/bridgetown-core/ruby_template_view.rb +44 -28
  96. data/lib/bridgetown-core/signals.rb +95 -0
  97. data/lib/bridgetown-core/site.rb +22 -4
  98. data/lib/bridgetown-core/slot.rb +5 -5
  99. data/lib/bridgetown-core/static_file.rb +5 -7
  100. data/lib/bridgetown-core/tags/asset_path.rb +11 -2
  101. data/lib/bridgetown-core/tags/find.rb +3 -5
  102. data/lib/bridgetown-core/tags/highlight.rb +3 -3
  103. data/lib/bridgetown-core/tags/post_url.rb +1 -1
  104. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +2 -2
  105. data/lib/bridgetown-core/utils/aux.rb +41 -41
  106. data/lib/bridgetown-core/utils/loaders_manager.rb +2 -21
  107. data/lib/bridgetown-core/utils/ruby_exec.rb +17 -0
  108. data/lib/bridgetown-core/utils.rb +46 -110
  109. data/lib/bridgetown-core/watcher.rb +21 -10
  110. data/lib/bridgetown-core.rb +35 -49
  111. data/lib/roda/plugins/bridgetown_server.rb +54 -12
  112. data/lib/roda/plugins/bridgetown_ssr.rb +13 -2
  113. data/lib/roda/plugins/ssg.rb +72 -0
  114. data/lib/site_template/.gitignore +9 -3
  115. data/lib/site_template/Gemfile.erb +3 -3
  116. data/lib/site_template/README.md +3 -4
  117. data/lib/site_template/Rakefile.erb +2 -15
  118. data/lib/site_template/TEMPLATES/erb/_partials/_head.erb +2 -2
  119. data/lib/site_template/TEMPLATES/serbea/_partials/_head.serb +2 -2
  120. data/lib/site_template/config/initializers.rb +60 -22
  121. data/lib/site_template/config/puma.rb +2 -0
  122. data/lib/site_template/package.json.erb +2 -27
  123. data/lib/site_template/src/index.md.erb +3 -3
  124. data/lib/site_template/src/posts.md.erb +8 -8
  125. data/lib/site_template/tmp/pids/.keep +0 -0
  126. metadata +98 -64
  127. data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +0 -12
  128. data/lib/bridgetown-core/commands/webpack/setup.rb +0 -4
  129. data/lib/bridgetown-core/commands/webpack/update.rb +0 -24
  130. data/lib/bridgetown-core/commands/webpack/webpack.config.js +0 -31
  131. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +0 -135
  132. data/lib/bridgetown-core/commands/webpack.rb +0 -82
  133. data/lib/bridgetown-core/concerns/front_matter_importer.rb +0 -52
  134. data/lib/bridgetown-core/concerns/liquid_renderable.rb +0 -30
  135. data/lib/bridgetown-core/core_ext/psych.rb +0 -15
  136. data/lib/bridgetown-core/drops/url_drop.rb +0 -152
  137. data/lib/bridgetown-core/frontmatter_defaults.rb +0 -223
  138. data/lib/bridgetown-core/rack/static_indexes.rb +0 -31
  139. data/lib/bridgetown-core/url.rb +0 -166
  140. data/lib/bridgetown-core/utils/ansi.rb +0 -57
  141. data/lib/bridgetown-core/version.rb +0 -6
  142. data/lib/site_template/bridgetown.config.yml +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb150e09ad6d4f40f0f5cd7a636b19b4ff0d40922d31601f33c67a98e7ffd24b
4
- data.tar.gz: '02795bee7a4b0ec92ef8fd8d2c61c2295e9882e145e023a2de697a56a3b3a4a4'
3
+ metadata.gz: ad323d78c36221049d27482e186a24793c5e52b478e913b778ba0d8809658990
4
+ data.tar.gz: dfc80b46023d5f28e38f2116e62676f579d175f1fcca023c46bb921298c99dc7
5
5
  SHA512:
6
- metadata.gz: 94f8313458630933d419a4b001a9da01328c92a0668068198a6b84330ce79e37dde9d6dffcb6db5d56596c243ca1740ab7e04045fabaf608e3ee8ca36be5742f
7
- data.tar.gz: 7ebe8c1ae5bbdd275b31d321fd8d3c9d007abd3679e8b9d61fc370970470830c60373b7ea84dad8a1c043461d38fa1ee90747bb0df2c9d1c033fccf8f747db60
6
+ metadata.gz: b0a025a6629018fc3cd5687f6675aee4ce0f4ef0edb740c35b1ba45f1f77df3fc6bb85b658d52a469d9b7f2e83820efcb636a9e062d1b196372fb8cb0b3b447e
7
+ data.tar.gz: a7af845632eda73b48f00fe07863f2b90f287e35402239203be296808aa5ae57d41fb3e8a498882254ed3407022f5f88d0895e0e81d59d861f83794f6bdbef76
data/Rakefile CHANGED
@@ -3,7 +3,8 @@
3
3
  require "bundler/gem_tasks"
4
4
 
5
5
  $LOAD_PATH.unshift File.expand_path("lib", __dir__)
6
- require "bridgetown-core/version"
6
+ $LOAD_PATH.unshift File.expand_path("../bridgetown-foundation/lib", __dir__)
7
+ require "bridgetown/version"
7
8
 
8
9
  task spec: :test
9
10
  require "rake/testtask"
data/bin/bridgetown CHANGED
@@ -5,12 +5,6 @@ STDOUT.sync = true
5
5
 
6
6
  $LOAD_PATH.unshift File.expand_path("../../bridgetown/lib", __dir__)
7
7
 
8
- # Used by commands/automations
9
- require "active_support"
10
- require "active_support/core_ext/array/extract_options"
11
- require "active_support/core_ext/string/strip"
12
- require "active_support/core_ext/string/indent"
13
-
14
8
  require "bridgetown"
15
9
 
16
10
  # Support NO_COLOR: https://no-color.org
data/bin/bt ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # `bt` is a shortcut to `bridgetown`
5
+
6
+ load File.join(File.dirname(__FILE__), 'bridgetown')
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/bridgetown-core/version"
3
+ require_relative "../bridgetown-foundation/lib/bridgetown/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "bridgetown-core"
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.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"]
18
+ s.executables = ["bridgetown", "bt"] # `bt` is a shortcut to `bridgetown` command
19
19
  s.bindir = "bin"
20
20
  s.require_paths = ["lib"]
21
21
 
@@ -29,27 +29,30 @@ Gem::Specification.new do |s|
29
29
 
30
30
  s.rdoc_options = ["--charset=UTF-8"]
31
31
 
32
- s.required_ruby_version = ">= 2.7.0"
32
+ s.required_ruby_version = ">= 3.1.0"
33
33
 
34
- s.add_runtime_dependency("activemodel", [">= 6.0", "< 8.0"])
35
34
  s.add_runtime_dependency("activesupport", [">= 6.0", "< 8.0"])
36
35
  s.add_runtime_dependency("addressable", "~> 2.4")
37
36
  s.add_runtime_dependency("amazing_print", "~> 1.2")
38
- s.add_runtime_dependency("colorator", "~> 1.0")
37
+ s.add_runtime_dependency("bridgetown-foundation", Bridgetown::VERSION)
39
38
  s.add_runtime_dependency("csv", "~> 3.2")
39
+ s.add_runtime_dependency("dry-inflector", ">= 1.0")
40
40
  s.add_runtime_dependency("erubi", "~> 1.9")
41
41
  s.add_runtime_dependency("faraday", "~> 2.0")
42
42
  s.add_runtime_dependency("faraday-follow_redirects", "~> 0.3")
43
- s.add_runtime_dependency("hash_with_dot_access", "~> 1.2")
44
43
  s.add_runtime_dependency("i18n", "~> 1.0")
45
44
  s.add_runtime_dependency("kramdown", "~> 2.1")
46
45
  s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
47
46
  s.add_runtime_dependency("liquid", [">= 5.0", "< 5.5"])
48
47
  s.add_runtime_dependency("listen", "~> 3.0")
48
+ s.add_runtime_dependency("rack", ">= 3.0")
49
+ s.add_runtime_dependency("rackup", "~> 2.0")
49
50
  s.add_runtime_dependency("rake", ">= 13.0")
50
51
  s.add_runtime_dependency("roda", "~> 3.46")
51
52
  s.add_runtime_dependency("rouge", [">= 3.0", "< 5.0"])
52
- s.add_runtime_dependency("serbea", "~> 1.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")
53
56
  s.add_runtime_dependency("thor", "~> 1.1")
54
57
  s.add_runtime_dependency("tilt", "~> 2.0")
55
58
  s.add_runtime_dependency("zeitwerk", "~> 2.5")
@@ -3,7 +3,7 @@
3
3
  module Bridgetown
4
4
  # Handles the cleanup of a site's destination before it is built.
5
5
  class Cleaner
6
- HIDDEN_FILE_REGEX = %r!/\.{1,2}$!.freeze
6
+ HIDDEN_FILE_REGEX = %r!/\.{1,2}$!
7
7
  attr_reader :site
8
8
 
9
9
  def initialize(site)
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Bridgetown
4
4
  class Collection
5
+ using Bridgetown::Refinements
6
+ include Enumerable
7
+
5
8
  # @return [Bridgetown::Site]
6
9
  attr_reader :site
7
10
 
@@ -20,7 +23,7 @@ module Bridgetown
20
23
  end
21
24
 
22
25
  def builtin?
23
- @is_builtin ||= label.in?(%w(posts pages data).freeze)
26
+ @is_builtin ||= label.within?(%w(posts pages data).freeze)
24
27
  end
25
28
 
26
29
  def data?
@@ -49,10 +52,17 @@ module Bridgetown
49
52
  resources.group_by(&:relative_url).transform_values(&:first)
50
53
  end
51
54
 
52
- # Iterate over Resources
53
- def each(&block)
54
- resources.each(&block)
55
- end
55
+ # Iterate over Resources by delegating to `resources.each` (supports Enumerable)
56
+ def each(...) = resources.each(...)
57
+
58
+ # Delgates to `resources.last`
59
+ def last(...) = resources.last(...)
60
+
61
+ # Delgates to `resources.deconstruct`
62
+ def deconstruct = resources.deconstruct
63
+
64
+ # Delgates to `resources[]`
65
+ def [](...) = resources.[](...)
56
66
 
57
67
  # Fetch the static files in this collection.
58
68
  # Defaults to an empty array if no static files have been read in.
@@ -62,11 +72,6 @@ module Bridgetown
62
72
  @static_files ||= []
63
73
  end
64
74
 
65
- def files
66
- Bridgetown::Deprecator.deprecation_message "Collection#files is now Collection#static_files"
67
- static_files
68
- end
69
-
70
75
  # Read the allowed resources into the collection's array of resources.
71
76
  #
72
77
  # @return [Bridgetown::Collection] self
@@ -77,8 +82,7 @@ module Bridgetown
77
82
 
78
83
  next if File.basename(file_path).starts_with?("_")
79
84
 
80
- if label == "data" || Utils.has_yaml_header?(full_path) ||
81
- Utils.has_rbfm_header?(full_path)
85
+ if label == "data" || FrontMatter::Loaders.front_matter?(full_path)
82
86
  read_resource(full_path)
83
87
  else
84
88
  read_static_file(file_path, full_path)
@@ -212,10 +216,25 @@ module Bridgetown
212
216
  !!metadata.fetch("output", false)
213
217
  end
214
218
 
215
- # Used by Resource's permalink processor
219
+ # Used by Resources permalink processors
216
220
  # @return [String]
217
221
  def default_permalink
218
- metadata.fetch("permalink", "/:locale/:collection/:path/")
222
+ metadata.fetch("permalink", default_configured_permalink)
223
+ end
224
+
225
+ # What the configured permalink should be absent of user overrides
226
+ # @return [String]
227
+ def default_configured_permalink
228
+ @default_configured_permalink ||= case label
229
+ when "data"
230
+ nil
231
+ when "posts"
232
+ site.config.permalink
233
+ when "pages"
234
+ "/:locale/:path/"
235
+ else
236
+ "/:locale/:collection/:path/"
237
+ end
219
238
  end
220
239
 
221
240
  # Extract options for this collection from the site configuration.
@@ -253,7 +272,7 @@ module Bridgetown
253
272
  end
254
273
  end
255
274
 
256
- merge_environment_specific_metadata(data_contents).with_dot_access
275
+ merge_environment_specific_metadata(data_contents).as_dots
257
276
  end
258
277
 
259
278
  def merge_environment_specific_metadata(data_contents)
@@ -273,10 +292,10 @@ module Bridgetown
273
292
  # @param manifest [Bridgetown::Configuration::SourceManifest]
274
293
  # @return [void]
275
294
  def read_resource(full_path, manifest: nil)
276
- model_relative_path = relative_model_path_for(full_path, manifest: manifest)
295
+ model_relative_path = relative_model_path_for(full_path, manifest:)
277
296
  model = Bridgetown::Model::Base.find(
278
- model_id_from_relative_path(model_relative_path, manifest: manifest),
279
- site: site
297
+ model_id_from_relative_path(model_relative_path, manifest:),
298
+ site:
280
299
  )
281
300
 
282
301
  if model_is_multi_locale?(model, model_relative_path)
@@ -31,23 +31,22 @@ module Bridgetown
31
31
  def build
32
32
  Bridgetown.logger.adjust_verbosity(options)
33
33
 
34
- unless caller_locations.find do |loc|
35
- loc.to_s.include?("bridgetown-core/commands/start.rb")
36
- end
37
- self.class.print_startup_message
38
- end
39
-
40
34
  # @type [Bridgetown::Configuration]
41
35
  config_options = configuration_with_overrides(
42
36
  options, Bridgetown::Current.preloaded_configuration
43
37
  )
44
38
 
45
- config_options.run_initializers! context: :static
39
+ self.class.print_startup_message unless config_options["start_command"]
46
40
 
47
- config_options["serving"] = false unless config_options["serving"]
41
+ Process.setproctitle(
42
+ "bridgetown #{Bridgetown::VERSION} " \
43
+ "(#{config_options["start_command"] ? "start" : "build"}) [#{File.basename(Dir.pwd)}]"
44
+ )
45
+
46
+ config_options.run_initializers! context: :static
48
47
 
49
48
  if !Bridgetown.env.production? &&
50
- !config_options[:skip_frontend] && config_options["using_puma"]
49
+ !config_options[:skip_frontend] && config_options["start_command"]
51
50
  if Bridgetown::Utils.frontend_bundler_type(config_options[:root_dir]) == :esbuild
52
51
  Bridgetown::Utils.update_esbuild_autogenerated_config config_options
53
52
  end
@@ -67,6 +66,7 @@ module Bridgetown
67
66
  build_site(config_options)
68
67
  end
69
68
 
69
+ # TODO: remove this logic…I can't find "detach" anywhere
70
70
  if config_options.fetch("detach", false)
71
71
  Bridgetown.logger.info "Auto-regeneration:",
72
72
  "disabled when running server detached."
@@ -95,19 +95,6 @@ module Bridgetown
95
95
  @site.process
96
96
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".bold.green} in less than " \
97
97
  "#{(Time.now - t).ceil(2)} seconds."
98
-
99
- return unless config_options[:using_puma]
100
-
101
- require "socket"
102
- external_ip = Socket.ip_address_list.find do |ai|
103
- ai.ipv4? && !ai.ipv4_loopback?
104
- end&.ip_address
105
- scheme = config_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
106
- port = config_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
107
- Bridgetown.logger.info ""
108
- Bridgetown.logger.info "Now serving at:", "#{scheme}://localhost:#{port}".magenta
109
- Bridgetown.logger.info "", "#{scheme}://#{external_ip}:#{port}".magenta if external_ip
110
- Bridgetown.logger.info ""
111
98
  end
112
99
 
113
100
  # Watch for file changes and rebuild the site.
@@ -3,10 +3,12 @@
3
3
  module Bridgetown
4
4
  module Commands
5
5
  module Actions
6
- GITHUB_REGEX = %r!https://github\.com!.freeze
7
- GITHUB_TREE_REGEX = %r!#{GITHUB_REGEX}/.*/.*/tree/.*/?!.freeze
8
- GITHUB_BLOB_REGEX = %r!#{GITHUB_REGEX}/.*/.*/blob/!.freeze
9
- GITHUB_REPO_REGEX = %r!github\.com/(.*?/[^/]*)!.freeze
6
+ using Bridgetown::Refinements
7
+
8
+ GITHUB_REGEX = %r!https://github\.com!
9
+ GITHUB_TREE_REGEX = %r!#{GITHUB_REGEX}/.*/.*/tree/.*/?!
10
+ GITHUB_BLOB_REGEX = %r!#{GITHUB_REGEX}/.*/.*/blob/!
11
+ GITHUB_REPO_REGEX = %r!github\.com/(.*?/[^/]*)!
10
12
 
11
13
  def create_builder(filename, data = nil)
12
14
  say_status :create_builder, filename
@@ -99,14 +101,19 @@ module Bridgetown
99
101
  before: %r!^end$!, verbose: false, force: false
100
102
  end
101
103
 
102
- def add_yarn_for_gem(gemname)
103
- say_status :add_yarn, gemname
104
+ def add_npm_for_gem(gemname)
105
+ say_status :add_npm, gemname
104
106
 
105
107
  Bundler.reset!
106
108
  Bridgetown::PluginManager.load_determined_bundler_environment
107
- Bridgetown::PluginManager.install_yarn_dependencies(name: gemname)
109
+ Bridgetown::PluginManager.install_npm_dependencies(name: gemname)
108
110
  rescue SystemExit
109
- say_status :add_yarn, "Package not added due to yarn error", :red
111
+ say_status :add_npm, "Package not added due to NPM error", :red
112
+ end
113
+ alias_method :add_yarn_for_gem, :add_npm_for_gem
114
+
115
+ def add_npm_package(package_details)
116
+ run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_install_command} #{package_details}" # rubocop:disable Layout
110
117
  end
111
118
 
112
119
  def apply_from_url(url)
@@ -7,7 +7,7 @@ module Bridgetown
7
7
  desc = "The environment used for this command (aka development, test, production, etc.)"
8
8
  klass.class_option :environment,
9
9
  aliases: "-e",
10
- desc: desc
10
+ desc:
11
11
  end
12
12
 
13
13
  # Create a full Bridgetown configuration with the options passed in as overrides
@@ -95,6 +95,9 @@ module Bridgetown
95
95
  workspace = IRB::WorkSpace.new
96
96
  workspace.main.define_singleton_method(:site) { Bridgetown::Current.site }
97
97
  workspace.main.define_singleton_method(:collections) { site.collections }
98
+ workspace.main.define_singleton_method(:helpers) do
99
+ Bridgetown::RubyTemplateView::Helpers.new
100
+ end
98
101
  irb = IRB::Irb.new(workspace)
99
102
  IRB.conf[:IRB_RC]&.call(irb.context)
100
103
  IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -97,11 +97,9 @@ module Bridgetown
97
97
 
98
98
  def collect_urls(urls, things, destination)
99
99
  things.each do |thing|
100
- dest = if thing.method(:destination).arity == 1
101
- thing.destination(destination)
102
- else
100
+ dest = thing.method(:destination).arity == 1 ?
101
+ thing.destination(destination) :
103
102
  thing.destination
104
- end
105
103
  if urls[dest]
106
104
  urls[dest] << thing.path
107
105
  else
@@ -155,7 +155,7 @@ const sassPlugin = (options) => ({
155
155
  // Process .scss and .sass files with Sass
156
156
  build.onLoad({ filter: /\.(sass|scss)$/ }, async (args) => {
157
157
  if (!sass) {
158
- console.error("error: Sass is not installed. Try running `yarn add sass` and then building again.")
158
+ console.error("error: Sass is not installed. Try running `npm i sass -D` and then building again.")
159
159
  return
160
160
  }
161
161
 
@@ -18,7 +18,7 @@ unless Bridgetown.environment.test?
18
18
 
19
19
  gsub_file "package.json", %r! "postcss-focus-within": "^4.0.0",?!, ""
20
20
 
21
- run "yarn add -D #{required_packages.join(" ")}"
21
+ add_npm_package "-D #{required_packages.join(" ")}"
22
22
 
23
23
  packages_to_remove = package_json["devDependencies"].slice(*redundant_packages).keys
24
24
  unless packages_to_remove.empty?
@@ -5,5 +5,5 @@ copy_file "jsconfig.json"
5
5
  say "🎉 esbuild configuration updated successfully!"
6
6
  say "You may need to add `$styles/` to the front of your main CSS imports."
7
7
  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.19.2\""
9
- say "and run `yarn install`!"
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`!"
@@ -24,7 +24,7 @@ module Bridgetown
24
24
  return show_actions if args.empty?
25
25
 
26
26
  action = args.first
27
- if supported_actions.include?(action)
27
+ if supported_actions.include?(action.to_sym)
28
28
  perform action
29
29
  else
30
30
  @logger.error "Error:".red, "🚨 Please enter a valid action."
@@ -66,7 +66,7 @@ module Bridgetown
66
66
 
67
67
  longest_action = supported_actions.keys.max_by(&:size).size
68
68
  supported_actions.each do |action, description|
69
- say "#{action.ljust(longest_action).to_s.bold.blue}\t# #{description}"
69
+ say "#{action.to_s.ljust(longest_action).bold.blue}\t# #{description}"
70
70
  end
71
71
  end
72
72
 
@@ -76,7 +76,7 @@ module Bridgetown
76
76
  update: "Updates the Bridgetown esbuild defaults to the latest available version",
77
77
  "migrate-from-webpack":
78
78
  "Removes Webpack from your project and installs/configures esbuild",
79
- }.with_indifferent_access
79
+ }
80
80
  end
81
81
  end
82
82
  end
@@ -26,21 +26,21 @@ module Bridgetown
26
26
  desc: "Comma separated list of bundled configurations to perform"
27
27
  class_option :templates,
28
28
  aliases: "-t",
29
- banner: "liquid|erb|serbea",
30
- desc: "Preferred template engine (defaults to Liquid)"
29
+ banner: "erb|serbea|liquid",
30
+ desc: "Preferred template engine (defaults to ERB)"
31
31
  class_option :"frontend-bundling",
32
32
  aliases: "-e",
33
- banner: "esbuild|webpack",
34
- desc: "Choose your frontend bundling stack (defaults to esbuild)"
33
+ banner: "esbuild",
34
+ desc: "Choose frontend bundling stack (defaults to esbuild)"
35
35
  class_option :force,
36
36
  type: :boolean,
37
37
  desc: "Force creation even if PATH already exists"
38
38
  class_option :"skip-bundle",
39
39
  type: :boolean,
40
40
  desc: "Skip 'bundle install'"
41
- class_option :"skip-yarn",
41
+ class_option :"skip-npm",
42
42
  type: :boolean,
43
- desc: "Skip 'yarn install'"
43
+ desc: "Skip 'npm install'"
44
44
  class_option :"use-sass",
45
45
  type: :boolean,
46
46
  desc: "Set up a Sass configuration for your stylesheet"
@@ -91,7 +91,7 @@ module Bridgetown
91
91
  end
92
92
 
93
93
  def frontend_bundling_option
94
- options["frontend-bundling"] == "webpack" ? "webpack" : "esbuild"
94
+ "esbuild"
95
95
  end
96
96
 
97
97
  def postcss_option
@@ -99,7 +99,8 @@ module Bridgetown
99
99
  end
100
100
 
101
101
  def disable_postcss?
102
- options["use-sass"] && options["frontend-bundling"] == "webpack"
102
+ # TODO: add option not to use postcss/sass at all
103
+ false
103
104
  end
104
105
 
105
106
  def create_site(new_site_path)
@@ -120,50 +121,42 @@ module Bridgetown
120
121
  copy_file("frontend/styles/syntax-highlighting.css")
121
122
 
122
123
  case options["templates"]
123
- when "erb"
124
- setup_erb_templates
125
124
  when "serbea"
126
125
  setup_serbea_templates
127
- else
126
+ when "liquid"
128
127
  setup_liquid_templates
128
+ else # default if no option specififed
129
+ setup_erb_templates
129
130
  end
130
131
 
131
132
  postcss_option ? configure_postcss : configure_sass
132
133
 
133
- if frontend_bundling_option == "esbuild"
134
- invoke(Esbuild, ["setup"], {})
135
- else
136
- invoke(Webpack, ["setup"], {})
137
- end
134
+ return unless frontend_bundling_option == "esbuild"
135
+
136
+ invoke(Esbuild, ["setup"], {})
138
137
  end
139
138
 
140
139
  def setup_erb_templates
141
140
  directory "TEMPLATES/erb/_layouts", "src/_layouts"
142
141
  directory "TEMPLATES/erb/_components", "src/_components"
143
142
  directory "TEMPLATES/erb/_partials", "src/_partials"
144
- gsub_file "bridgetown.config.yml", %r!permalink: pretty\n!, <<~YML
145
- permalink: pretty
146
- template_engine: erb
147
- YML
148
143
  end
149
144
 
150
145
  def setup_serbea_templates
151
146
  directory "TEMPLATES/serbea/_layouts", "src/_layouts"
152
147
  directory "TEMPLATES/serbea/_components", "src/_components"
153
148
  directory "TEMPLATES/serbea/_partials", "src/_partials"
154
- gsub_file "bridgetown.config.yml", %r!permalink: pretty\n!, <<~YML
155
- permalink: pretty
156
- template_engine: serbea
157
- YML
149
+ gsub_file "config/initializers.rb", %r!template_engine "erb"\n!, <<~RUBY
150
+ template_engine "serbea"
151
+ RUBY
158
152
  end
159
153
 
160
154
  def setup_liquid_templates
161
155
  directory "TEMPLATES/liquid/_layouts", "src/_layouts"
162
156
  directory "TEMPLATES/liquid/_components", "src/_components"
163
- gsub_file "bridgetown.config.yml", %r!permalink: pretty\n!, <<~YML
164
- permalink: pretty
165
- template_engine: liquid
166
- YML
157
+ gsub_file "config/initializers.rb", %r!template_engine "erb"\n!, <<~RUBY
158
+ template_engine "liquid"
159
+ RUBY
167
160
  end
168
161
 
169
162
  def configure_sass
@@ -172,7 +165,7 @@ module Bridgetown
172
165
  end
173
166
 
174
167
  def configure_postcss
175
- template("postcss.config.js.erb", "postcss.config.js")
168
+ template("postcss.config.js.erb", "postcss.config.js") unless disable_postcss?
176
169
  copy_file("frontend/styles/index.css")
177
170
  end
178
171
 
@@ -187,8 +180,8 @@ module Bridgetown
187
180
  @skipped_bundle = true # is set to false if bundle install worked
188
181
  bundle_install path unless options["skip-bundle"]
189
182
 
190
- @skipped_yarn = true
191
- yarn_install path unless options["skip-yarn"]
183
+ @skipped_npm = true
184
+ npm_install path unless options["skip-npm"]
192
185
 
193
186
  invoke(Apply, [], options) if options[:apply]
194
187
  invoke(Configure, options[:configure].split(","), {}) if options[:configure]
@@ -198,9 +191,9 @@ module Bridgetown
198
191
  logger.info ""
199
192
  logger.info "Success!".green, "🎉 Your new Bridgetown site was " \
200
193
  "generated in #{cli_path.cyan}."
201
- if options["skip-yarn"]
194
+ if options["skip-npm"]
202
195
  logger.info "You can now #{"cd".cyan} #{cli_path.cyan} to get started."
203
- logger.info "You'll probably also want to #{"yarn install".cyan} " \
196
+ logger.info "You'll probably also want to #{"npm install".cyan} " \
204
197
  "to load in your frontend assets."
205
198
  else
206
199
  logger.info "You can now #{"cd".cyan} #{cli_path.cyan} and run #{bt_start.cyan} " \
@@ -214,7 +207,7 @@ module Bridgetown
214
207
  logger.info "You will need to run #{"bundle binstubs bridgetown-core".cyan} manually."
215
208
  end
216
209
 
217
- logger.info "Yarn install skipped.".yellow if @skipped_yarn
210
+ logger.info "NPM install skipped.".yellow if @skipped_npm
218
211
  end
219
212
  # rubocop:enable Metrics/CyclomaticComplexity
220
213
  # rubocop:enable Metrics/PerceivedComplexity
@@ -225,8 +218,8 @@ module Bridgetown
225
218
  Bridgetown.with_unbundled_env do
226
219
  inside(path) do
227
220
  run "bundle install", abort_on_failure: true
221
+ # create binstubs to `bin/bridgetown` and `bin/bt`
228
222
  run "bundle binstubs bridgetown-core"
229
- run "cp bin/bridgetown bin/bt"
230
223
  end
231
224
  end
232
225
  end
@@ -247,15 +240,15 @@ module Bridgetown
247
240
  say_status :alert, "Could not load git. git init skipped.", :red
248
241
  end
249
242
 
250
- def yarn_install(path)
243
+ def npm_install(path)
251
244
  unless Bridgetown.environment.test?
252
245
  inside(path) do
253
- run "yarn install", abort_on_failure: true
246
+ run "npm install", abort_on_failure: true
254
247
  end
255
248
  end
256
- @skipped_yarn = false
249
+ @skipped_npm = false
257
250
  rescue SystemExit
258
- say_status :alert, "Could not load yarn. yarn install skipped.", :red
251
+ say_status :alert, "Could not load npm. NPM install skipped.", :red
259
252
  end
260
253
  end
261
254
  end