bridgetown-core 2.0.5 → 2.1.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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -2
  3. data/bin/bridgetown +19 -7
  4. data/bridgetown-core.gemspec +8 -6
  5. data/lib/bridgetown-core/collection.rb +4 -3
  6. data/lib/bridgetown-core/command.rb +97 -0
  7. data/lib/bridgetown-core/commands/application.rb +208 -0
  8. data/lib/bridgetown-core/commands/apply.rb +17 -29
  9. data/lib/bridgetown-core/commands/build.rb +9 -16
  10. data/lib/bridgetown-core/commands/clean.rb +7 -10
  11. data/lib/bridgetown-core/commands/concerns/{actions.rb → automations.rb} +103 -17
  12. data/lib/bridgetown-core/commands/concerns/build_options.rb +24 -60
  13. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +2 -4
  14. data/lib/bridgetown-core/commands/configure.rb +24 -24
  15. data/lib/bridgetown-core/commands/console.rb +38 -34
  16. data/lib/bridgetown-core/commands/esbuild.rb +14 -24
  17. data/lib/bridgetown-core/commands/help.rb +24 -0
  18. data/lib/bridgetown-core/commands/new.rb +38 -60
  19. data/lib/bridgetown-core/commands/plugins.rb +237 -211
  20. data/lib/bridgetown-core/commands/registrations.rb +10 -1
  21. data/lib/bridgetown-core/commands/start.rb +23 -31
  22. data/lib/bridgetown-core/commands/thor_shim.rb +94 -0
  23. data/lib/bridgetown-core/component.rb +3 -3
  24. data/lib/bridgetown-core/concerns/publishable.rb +1 -3
  25. data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
  26. data/lib/bridgetown-core/configuration/configuration_dsl.rb +2 -2
  27. data/lib/bridgetown-core/configuration.rb +27 -7
  28. data/lib/bridgetown-core/converters/erb_templates.rb +31 -21
  29. data/lib/bridgetown-core/converters/ruby_templates.rb +14 -13
  30. data/lib/bridgetown-core/converters/serbea_templates.rb +5 -2
  31. data/lib/bridgetown-core/entry_filter.rb +1 -4
  32. data/lib/bridgetown-core/front_matter/defaults.rb +1 -1
  33. data/lib/bridgetown-core/front_matter/importer.rb +7 -1
  34. data/lib/bridgetown-core/front_matter/loaders.rb +1 -1
  35. data/lib/bridgetown-core/front_matter/ruby.rb +3 -9
  36. data/lib/bridgetown-core/generated_page.rb +2 -2
  37. data/lib/bridgetown-core/generators/prototype_generator.rb +1 -1
  38. data/lib/bridgetown-core/helpers.rb +10 -11
  39. data/lib/bridgetown-core/hooks.rb +2 -3
  40. data/lib/bridgetown-core/locale/en.yml +30 -0
  41. data/lib/bridgetown-core/model/base.rb +5 -5
  42. data/lib/bridgetown-core/model/builder_origin.rb +1 -1
  43. data/lib/bridgetown-core/model/origin.rb +5 -1
  44. data/lib/bridgetown-core/model/plugin_origin.rb +3 -1
  45. data/lib/bridgetown-core/model/repo_origin.rb +3 -1
  46. data/lib/bridgetown-core/rack/routes.rb +1 -1
  47. data/lib/bridgetown-core/reader.rb +2 -2
  48. data/lib/bridgetown-core/readers/plugin_content_reader.rb +31 -7
  49. data/lib/bridgetown-core/resource/base.rb +16 -7
  50. data/lib/bridgetown-core/resource/destination.rb +1 -1
  51. data/lib/bridgetown-core/resource/permalink_processor.rb +4 -4
  52. data/lib/bridgetown-core/static_file.rb +1 -1
  53. data/lib/bridgetown-core/tags/class_map.rb +0 -2
  54. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +8 -11
  55. data/lib/bridgetown-core/{ruby_template_view.rb → template_view.rb} +108 -4
  56. data/lib/bridgetown-core/utils/initializers.rb +28 -1
  57. data/lib/bridgetown-core/utils/loaders_manager.rb +2 -1
  58. data/lib/bridgetown-core/utils.rb +19 -1
  59. data/lib/bridgetown-core/watcher.rb +16 -8
  60. data/lib/bridgetown-core.rb +5 -10
  61. data/lib/roda/plugins/bridgetown_server.rb +1 -1
  62. data/lib/site_template/README.md +10 -8
  63. metadata +84 -70
  64. data/lib/bridgetown-core/commands/base.rb +0 -123
  65. data/lib/bridgetown-core/commands/concerns/summarizable.rb +0 -13
  66. data/lib/bridgetown-core/configurations/.keep +0 -0
  67. data/lib/bridgetown-core/configurations/stimulus.rb +0 -59
  68. data/lib/bridgetown-core/configurations/turbo/turbo_transitions.js +0 -48
  69. data/lib/bridgetown-core/configurations/turbo.rb +0 -35
  70. data/lib/bridgetown-core/configurations/vercel/vercel.json +0 -45
  71. data/lib/bridgetown-core/configurations/vercel/vercel_url.rb +0 -12
  72. data/lib/bridgetown-core/configurations/vercel.rb +0 -4
  73. data/lib/bridgetown-core/inflector.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04724f0d282ebd3b98d82230277b3f525b6b514036529bd0a86a5d617582a55d
4
- data.tar.gz: 6d75adb7396c2d635f2032b8c3af85d7b12ebda90f72fa8e1a7c794d6113ddb5
3
+ metadata.gz: 696307e4270883706cdcff2ad44ea6d83120449aab4a5e74a67101fc3769fc3b
4
+ data.tar.gz: 5596f15af73805b95d1f2c8df40e4da2256733363697b235828fe6f59a5469fe
5
5
  SHA512:
6
- metadata.gz: 7567e6a5d81cfae3e6ea665cdf2cb99376e1c2a6433be20d37924e9a04e3162361670c4b54234fb5ef186140a5c6c6b36ac484e3bbae9d6e0ea80a0faabbbff8
7
- data.tar.gz: 875cff3b9e332cdb783d0190207aeda11b08a8fc0ce981e44a843f5299a9dc12caed0faa13cc65f5f3db71a6e4279e7c68fd177f3fa1f2cc66a9126d7f175ee5
6
+ metadata.gz: a72aa20636088803d8960f3880b48465702fa8961923b51ec6edc7b5245d8d6f9645c83c18b02993f396076c35cd7c461dfb5b97f04bcfc4f78d4f8984bd5eed
7
+ data.tar.gz: 9f4bdb2e72807ddc0a6caf528a26931ea6ce02e4384c6c31f889ab12f6bd0887d0da6181d7d1ee4c54d06b62f9f646958cf1d0ad09f50c66e346b45b1e0b1ca8
data/.rubocop.yml CHANGED
@@ -12,8 +12,6 @@ AllCops:
12
12
  - tmp/**/*
13
13
  - test/source/**/*
14
14
  - test/resources/src/**/*.rb
15
- - lib/bridgetown-core/commands/base.rb
16
- - lib/bridgetown-core/commands/plugins.rb
17
15
  - lib/bridgetown-core/configurations/ruby2js/**/*
18
16
  - lib/bridgetown-core/rack/roda.rb
19
17
  - lib/site_template/TEMPLATES/**/*
@@ -23,6 +21,10 @@ AllCops:
23
21
  - lib/site_template/plugins/site_builder.rb
24
22
  - lib/site_template/server/roda_app.rb
25
23
 
24
+ Bridgetown/NoPutsAllowed:
25
+ Exclude:
26
+ - lib/bridgetown-core/commands/**/*
27
+
26
28
  Lint/ConstantDefinitionInBlock:
27
29
  Exclude:
28
30
  - test/test_liquid_extensions.rb
data/bin/bridgetown CHANGED
@@ -9,12 +9,12 @@ require "bridgetown"
9
9
 
10
10
  # Support NO_COLOR: https://no-color.org
11
11
  # TODO: need to change behavior of Colorator gem
12
- ENV["THOR_SHELL"] = "Basic" if ENV["NO_COLOR"]
12
+ #ENV["THOR_SHELL"] = "Basic" if ENV["NO_COLOR"]
13
13
 
14
- output_version = if ARGV[0] == "-v" || ARGV[0] == "--version"
15
- puts "bridgetown #{Bridgetown::VERSION} \"#{Bridgetown::CODE_NAME}\""
16
- true
17
- end
14
+ if ARGV[0] == "-v" || ARGV[0] == "--version"
15
+ puts "bridgetown #{Bridgetown::VERSION} \"#{Bridgetown::CODE_NAME}\""
16
+ exit(true)
17
+ end
18
18
 
19
19
  if env_index = ARGV.index { |arg| arg == "-e" } # rubocop:disable Lint/AssignmentInCondition
20
20
  env = ARGV[env_index + 1]
@@ -25,9 +25,21 @@ end
25
25
 
26
26
  Bridgetown.begin!
27
27
 
28
- require "bridgetown-core/commands/base"
28
+ require "bridgetown-core/commands/application"
29
+
30
+ custom_commands_file = File.expand_path("config/custom_commands.rb", Dir.pwd)
31
+ require custom_commands_file if File.exist?(custom_commands_file)
32
+
29
33
  begin
30
- Bridgetown::Commands::Base.start unless output_version
34
+ Bridgetown::Commands::Application.parse(ARGV).call
35
+ rescue Samovar::MissingValueError => e
36
+ puts "#{"Command error:".bold.red} #{e.message.to_s.yellow}\n\n"
37
+ e.command.print_usage
38
+ exit(false)
39
+ rescue Samovar::InvalidInputError => e
40
+ puts "#{"Unknown token:".bold.red} #{e.token.yellow}\n\n"
41
+ e.command.print_usage
42
+ exit(false)
31
43
  rescue StandardError => e
32
44
  Bridgetown::Errors.print_build_error(e)
33
45
  exit(false)
@@ -29,17 +29,18 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.rdoc_options = ["--charset=UTF-8"]
31
31
 
32
- spec.required_ruby_version = ">= 3.1.0"
32
+ spec.required_ruby_version = ">= 3.2.0"
33
33
 
34
- spec.add_dependency("activesupport", [">= 6.0", "< 8.0"])
35
34
  spec.add_dependency("addressable", "~> 2.4")
36
35
  spec.add_dependency("amazing_print", "~> 1.2")
36
+ spec.add_dependency("base64", ">= 0.3")
37
+ spec.add_dependency("bigdecimal", ">= 3.2")
37
38
  spec.add_dependency("bridgetown-foundation", Bridgetown::VERSION)
38
39
  spec.add_dependency("csv", "~> 3.2")
39
- spec.add_dependency("dry-inflector", ">= 1.0")
40
40
  spec.add_dependency("erubi", "~> 1.9")
41
41
  spec.add_dependency("faraday", "~> 2.0")
42
42
  spec.add_dependency("faraday-follow_redirects", "~> 0.3")
43
+ spec.add_dependency("freyia", ">= 0.5")
43
44
  spec.add_dependency("i18n", "~> 1.0")
44
45
  spec.add_dependency("irb", ">= 1.14")
45
46
  spec.add_dependency("kramdown", "~> 2.1")
@@ -51,10 +52,11 @@ Gem::Specification.new do |spec|
51
52
  spec.add_dependency("rake", ">= 13.0")
52
53
  spec.add_dependency("roda", "~> 3.46")
53
54
  spec.add_dependency("rouge", [">= 3.0", "< 5.0"])
54
- spec.add_dependency("serbea", "~> 2.1")
55
+ spec.add_dependency("samovar", ">= 2.4")
56
+ spec.add_dependency("securerandom", "~> 0.4")
57
+ spec.add_dependency("serbea", ">= 2.4.1")
55
58
  spec.add_dependency("signalize", "~> 1.3")
56
59
  spec.add_dependency("streamlined", ">= 0.6.0")
57
- spec.add_dependency("thor", "~> 1.1")
58
60
  spec.add_dependency("tilt", "~> 2.0")
59
- spec.add_dependency("zeitwerk", "~> 2.5")
61
+ spec.add_dependency("zeitwerk", ">= 2.7.3")
60
62
  end
@@ -292,11 +292,12 @@ module Bridgetown
292
292
  # @param full_path [String]
293
293
  # @param manifest [Bridgetown::Configuration::SourceManifest]
294
294
  # @return [void]
295
- def read_resource(full_path, manifest: nil)
295
+ def read_resource(full_path, manifest: nil, bare_text: false)
296
296
  model_relative_path = relative_model_path_for(full_path, manifest:)
297
297
  model = Bridgetown::Model::Base.find(
298
298
  model_id_from_relative_path(model_relative_path, manifest:),
299
- site:
299
+ site:,
300
+ bare_text:
300
301
  )
301
302
 
302
303
  if model_is_multi_locale?(model, model_relative_path)
@@ -396,7 +397,7 @@ module Bridgetown
396
397
 
397
398
  def relative_model_path_for(full_path, manifest: nil)
398
399
  Pathname(full_path).relative_path_from(
399
- manifest ? Pathname(manifest.content) : Pathname(site.source)
400
+ manifest ? manifest.contents[label.to_sym] : site.source
400
401
  ).to_s
401
402
  end
402
403
 
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "samovar"
4
+ require "freyia"
5
+
6
+ # Monkey-patch to use cyan instead of blue formatting
7
+ Samovar::Output::UsageFormatter.class_eval do
8
+ # Initialize a new usage formatter.
9
+ #
10
+ # @parameter rows [Rows] The rows to format.
11
+ # @parameter output [IO] The output stream to print to.
12
+ def initialize(output)
13
+ @output = output
14
+ @width = 80
15
+ @first = true
16
+
17
+ @terminal = Console::Terminal.for(@output)
18
+ @terminal[:header] = @terminal.style(:cyan, nil, :bright)
19
+ #@terminal[:description] = @terminal.style(:cyan)
20
+ @terminal[:options] = @terminal.style(:cyan)
21
+ @terminal[:error] = @terminal.style(:red)
22
+ end
23
+
24
+ map(Samovar::Output::Row) do |row, rows|
25
+ row[1] = row[1].reset_ansi if row[1]
26
+ @terminal.puts "#{rows.indentation}#{row.align(rows.columns)}", style: :options
27
+ end
28
+ end
29
+
30
+ # Monkey-patch to support `--key=value`
31
+ Samovar::Options.class_eval do
32
+ def parse(input, parent = nil, default = nil) # rubocop:disable Metrics
33
+ values = (default || @defaults).dup
34
+
35
+ while option = @keyed[input.first] || @keyed[input.first&.split("=")&.first] # rubocop:disable Lint/AssignmentInCondition
36
+ result = option.parse(input)
37
+ values[option.key] = result unless result.nil?
38
+ end
39
+
40
+ # Validate required options
41
+ @ordered.each do |option|
42
+ if option.required && !values.key?(option.key)
43
+ raise Samovar::MissingValueError.new(parent, option.key)
44
+ end
45
+ end
46
+
47
+ values
48
+ end
49
+ end
50
+
51
+ Samovar::ValueFlag.class_eval do
52
+ # Parse this flag from the input.
53
+ #
54
+ # @parameter input [Array(String)] The command-line arguments.
55
+ # @returns [String | Symbol | Nil] The parsed value.
56
+ def parse(input)
57
+ if prefix?(input.first)
58
+ # Whether we are expecting to parse a value from input:
59
+ if @value
60
+ # Get the actual value from input:
61
+ _, value = input.shift(2)
62
+ value
63
+ else
64
+ # Otherwise, we are just a boolean flag:
65
+ input.shift
66
+ key
67
+ end
68
+ elsif prefix?(input.first.split("=").first)
69
+ input.shift(1)[0].split("=").last
70
+
71
+ end
72
+ end
73
+ end
74
+
75
+ module Bridgetown
76
+ class Command < Samovar::Command
77
+ def self.summary = description
78
+
79
+ # Compatibility syntax to execute commands.
80
+ # It's recommended you use Samovar's more idiomatic `CmdClass[*args].call` syntax instead
81
+ def self.start(args = []) = self[*args].call
82
+
83
+ # Samovar shows all command options by default when printing out a command name string.
84
+ # We want to hide that part of the output, as options are already listed out separately
85
+ def self.command_line(name)
86
+ table = self.table.merged
87
+
88
+ usage_string = table.each.collect do |row|
89
+ next "" if row.is_a?(Samovar::Options)
90
+
91
+ row.to_s
92
+ end.reject(&:empty?).join(" ")
93
+
94
+ "#{name} #{usage_string}"
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,208 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ # Register a new command for the Bridgetown CLI
6
+ #
7
+ # @param name [Symbol]
8
+ # @param klass [Bridgetown::Command]
9
+ def self.register_command(name, klass)
10
+ Registrations.register(klass, name)
11
+ end
12
+ end
13
+ end
14
+
15
+ require_all "bridgetown-core/commands/concerns"
16
+ require_all "bridgetown-core/commands"
17
+
18
+ module Bridgetown
19
+ module Commands
20
+ class Application < Bridgetown::Command
21
+ self.description =
22
+ "next-generation, progressive site generator & fullstack framework, powered by Ruby"
23
+
24
+ def self.registrations = @registrations ||= {}
25
+
26
+ def self.register(klass, name, *)
27
+ registrations[name.to_s] = klass
28
+ end
29
+
30
+ nested(:command, registrations)
31
+
32
+ def self.desc(name, description)
33
+ @next_cmd_name = name.split.first
34
+ @next_cmd_description = description
35
+ end
36
+
37
+ def self.subcommand(name, klass)
38
+ return unless @next_cmd_name == name
39
+
40
+ table[:command].commands[name] = klass
41
+ klass.description = @next_cmd_description
42
+
43
+ @next_cmd_name = nil
44
+ @next_cmd_description = nil
45
+ end
46
+
47
+ def parse(input)
48
+ Registrations.load_registrations self.class
49
+ self.class.table.merged.parse(input, self)
50
+
51
+ return self if input.empty?
52
+
53
+ new_input = locate_command(input)
54
+ unless new_input
55
+ locate_rake_task(input)
56
+ return self
57
+ end
58
+
59
+ parse(new_input)
60
+ end
61
+
62
+ def call
63
+ if @command
64
+ @command.()
65
+ else
66
+ print_usage
67
+ end
68
+ end
69
+
70
+ def print_usage # rubocop:disable Metrics
71
+ puts "Bridgetown v#{Bridgetown::VERSION.magenta} \"#{Bridgetown::CODE_NAME.yellow}\" " \
72
+ "is a #{self.class.description}"
73
+ puts ""
74
+ puts "Usage:".bold.green + " #{"bridgetown".bold.cyan} #{"<command> [options]".cyan}\n\n"
75
+ puts "Commands:".bold.green
76
+
77
+ commands = self.class.table[:command].commands.to_h do |name, command|
78
+ inputs = command.table.each.find do |item|
79
+ item.is_a?(Samovar::Many) || item.is_a?(Samovar::One) || item.is_a?(Samovar::Nested)
80
+ end
81
+ name = name.bold.cyan
82
+ name = "#{name} #{"<#{inputs.key.upcase}>".cyan}" if inputs
83
+ [name, command]
84
+ end
85
+
86
+ name_max_length = commands.keys.map { Foundation::Packages::Ansi.strip(_1).length }.max
87
+ commands.find do |name, command|
88
+ spaces = " " * (name_max_length - Foundation::Packages::Ansi.strip(name).length)
89
+ puts " #{"bridgetown".cyan} #{name} #{spaces}#{command.description}"
90
+ end
91
+
92
+ puts ""
93
+
94
+ require "rake"
95
+ Rake::TaskManager.record_task_metadata = true
96
+ Rake.with_application do |rake|
97
+ rake.instance_variable_set(:@name, " bridgetown")
98
+ rake.standard_exception_handling do
99
+ rakefile, _location = rake.find_rakefile_location
100
+ return unless rakefile # rubocop:disable Lint/NonLocalExitFromIterator
101
+
102
+ load_rake_tasks(rake)
103
+ puts "Available Rake Tasks:".bold.green
104
+ display_rake_tasks(rake, name_max_length)
105
+ end
106
+ end
107
+ end
108
+
109
+ # @param input [String]
110
+ def locate_command(input)
111
+ token = input.first
112
+
113
+ case token
114
+ when "--help", "-help", "-h"
115
+ input[0] = "help"
116
+ input
117
+ when "c"
118
+ input[0] = "console"
119
+ input
120
+ when "s"
121
+ input[0] = "start"
122
+ input
123
+ else
124
+ self.class.table[:command].commands.find do |name, _command|
125
+ next unless name.start_with?(token)
126
+
127
+ input[0] = name
128
+ input
129
+ end
130
+ end
131
+ end
132
+
133
+ # @param input [String]
134
+ def locate_rake_task(input) # rubocop:todo Metrics
135
+ require "rake"
136
+ Rake::TaskManager.record_task_metadata = true
137
+ cmd = input.first
138
+
139
+ Rake.with_application do |rake|
140
+ rake.standard_exception_handling do
141
+ rakefile, _location = rake.find_rakefile_location
142
+ unless rakefile
143
+ puts "No Rakefile found (searching: #{rake.class::DEFAULT_RAKEFILES.join(", ")})\n\n"
144
+ new.invoke("help")
145
+ return # rubocop:disable Lint/NonLocalExitFromIterator
146
+ end
147
+ rake.init("bridgetown")
148
+ load_rake_tasks(rake)
149
+ end
150
+
151
+ # either return a command proc or nothing, #call will handle either case
152
+ if Rake::Task.task_defined?(cmd.split("[")[0])
153
+ @command = -> { rake.top_level }
154
+ else
155
+ puts "#{"Unknown token:".bold.red} #{cmd.split("[")[0].yellow}\n\n"
156
+ end
157
+ rescue RuntimeError => e
158
+ # re-raise error unless it's an error through Minitest
159
+ raise e unless e.message.include?("ruby -Ilib:test")
160
+
161
+ Bridgetown.logger.error "test aborted!"
162
+ Bridgetown.logger.error e.message
163
+ exit(false)
164
+ end
165
+ end
166
+
167
+ # @param rake [Rake::Application]
168
+ def display_rake_tasks(rake, previous_max_length)
169
+ # based in part on `Rake::Application#display_tasks_and_comments`
170
+ displayable_tasks = rake.tasks.to_h do |t|
171
+ [t.name_with_args, t.comment]
172
+ end
173
+
174
+ name_max_length = [previous_max_length, displayable_tasks.keys.map(&:length).max].max
175
+ displayable_tasks.find do |name, comment|
176
+ next if name == "default"
177
+
178
+ spaces = " " * (name_max_length - name.length)
179
+ puts " #{"bridgetown".cyan} #{name.bold.cyan} #{spaces}#{comment}"
180
+ end
181
+ end
182
+
183
+ # @param rake [Rake::Application]
184
+ def load_rake_tasks(rake)
185
+ rake.load_rakefile
186
+ tasks = rake.instance_variable_get(:@tasks)
187
+ rake.instance_variable_set(:@tasks, tasks.reject do |_k, v|
188
+ v.locations.first&.include?("/lib/rails/tasks/") ||
189
+ v.locations.first&.include?("/lib/rake/dsl_definition")
190
+ end)
191
+ end
192
+ end
193
+
194
+ class Dream < Bridgetown::Command
195
+ self.description = "There's a place where that idea still exists as a reality"
196
+
197
+ def call
198
+ puts ""
199
+ puts "🎶 The Dream of the 90s is Alive in Portland... ✨"
200
+ puts " https://youtu.be/U4hShMEk1Ew"
201
+ puts " https://youtu.be/0_HGqPGp9iY"
202
+ puts ""
203
+ end
204
+ end
205
+
206
+ register_command :dream, Dream
207
+ end
208
+ end
@@ -2,34 +2,19 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Commands
5
- class Apply < Thor::Group
6
- include Thor::Actions
7
- include Actions
8
- extend Summarizable
5
+ class Apply < Bridgetown::Command
6
+ include Automations
9
7
 
10
- Registrations.register do
11
- register(Apply, "apply", "apply", Apply.summary)
12
- end
13
-
14
- def self.banner
15
- "bridgetown apply PATH or URL"
16
- end
17
- summary "Applies an automation to the current site"
8
+ self.description = "Applies an automation to the current site"
18
9
 
19
- def self.source_root
20
- Dir.pwd
21
- end
10
+ one :path_or_url, "Either a path or a URL to an automation file or Git repo"
22
11
 
23
- def self.exit_on_failure?
24
- true
25
- end
26
-
27
- def apply_automation
28
- @source_paths = [Dir.pwd]
12
+ def call(new_site_dir: nil)
13
+ self.source_paths = [Dir.pwd]
29
14
  @logger = Bridgetown.logger
30
15
 
31
- if options[:apply]
32
- apply_after_new_command
16
+ if new_site_dir
17
+ apply_after_new_command new_site_dir
33
18
  else
34
19
  apply_in_pwd
35
20
  end
@@ -43,21 +28,22 @@ module Bridgetown
43
28
 
44
29
  protected
45
30
 
46
- def apply_after_new_command
31
+ def apply_after_new_command(created_site_dir)
47
32
  # Coming from the new command, so set up proper bundler env
48
33
  Bridgetown.with_unbundled_env do
49
- self.destination_root = New.created_site_dir
50
- inside(New.created_site_dir) do
51
- apply_from_url options[:apply]
34
+ self.destination_root = created_site_dir
35
+ inside(created_site_dir) do
36
+ apply_from_url path_or_url
52
37
  end
53
38
  end
54
39
  end
55
40
 
56
41
  def apply_in_pwd
57
42
  # Running standalone
58
- automation_command = args.empty? ? "bridgetown.automation.rb" : args[0]
43
+ self.destination_root = Dir.pwd
44
+ automation_command = path_or_url.nil? ? "bridgetown.automation.rb" : path_or_url
59
45
 
60
- if args.empty? && !File.exist?("bridgetown.automation.rb")
46
+ if path_or_url.nil? && !File.exist?("bridgetown.automation.rb")
61
47
  raise ArgumentError, "You must specify a path or a URL, " \
62
48
  "or add bridgetown.automation.rb to the " \
63
49
  "current folder."
@@ -70,5 +56,7 @@ module Bridgetown
70
56
  @logger.warn "Oops!", e.message
71
57
  end
72
58
  end
59
+
60
+ register_command :apply, Apply
73
61
  end
74
62
  end
@@ -2,24 +2,15 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Commands
5
- class Build < Thor::Group
6
- extend BuildOptions
7
- extend Summarizable
5
+ class Build < Bridgetown::Command
8
6
  include ConfigurationOverridable
9
7
 
10
- Registrations.register do
11
- register(Build, "build", "build", Build.summary)
12
- end
8
+ self.description = "Build your site and save to destination folder"
13
9
 
14
- def self.banner
15
- "bridgetown build [options]"
10
+ options do
11
+ BuildOptions.include_options(self)
12
+ option "-w/--watch", "Watch for changes and rebuild"
16
13
  end
17
- summary "Build your site and save to destination folder"
18
-
19
- class_option :watch,
20
- type: :boolean,
21
- aliases: "-w",
22
- desc: "Watch for changes and rebuild"
23
14
 
24
15
  def self.print_startup_message
25
16
  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta} " \
@@ -28,7 +19,7 @@ module Bridgetown
28
19
 
29
20
  # Build your bridgetown site
30
21
  # Continuously watch if `watch` is set to true in the config.
31
- def build
22
+ def call # rubocop:disable Metrics
32
23
  Bridgetown.logger.adjust_verbosity(**options)
33
24
 
34
25
  # @type [Bridgetown::Configuration]
@@ -90,7 +81,7 @@ module Bridgetown
90
81
  # Watch for file changes and rebuild the site
91
82
  #
92
83
  # @param options [Bridgetown::Configuration] options loaded from config and/or CLI
93
- def watch_site(config_options)
84
+ def watch_site(config_options) # rubocop:disable Metrics
94
85
  if config_options["url"]&.include?("://localhost")
95
86
  require "socket"
96
87
  external_ip = Socket.ip_address_list.find do |ai|
@@ -137,5 +128,7 @@ module Bridgetown
137
128
  end
138
129
  end
139
130
  end
131
+
132
+ register_command :build, Build
140
133
  end
141
134
  end
@@ -2,21 +2,16 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Commands
5
- class Clean < Thor::Group
6
- extend BuildOptions
7
- extend Summarizable
5
+ class Clean < Bridgetown::Command
8
6
  include ConfigurationOverridable
9
7
 
10
- Registrations.register do
11
- register(Clean, "clean", "clean", Clean.summary)
12
- end
8
+ self.description = "Clean the site (removes site output and metadata file) without building"
13
9
 
14
- def self.banner
15
- "bridgetown clean [options]"
10
+ options do
11
+ BuildOptions.include_options(self)
16
12
  end
17
- summary "Clean the site (removes site output and metadata file) without building"
18
13
 
19
- def clean
14
+ def call
20
15
  config = configuration_with_overrides(options, Bridgetown::Current.preloaded_configuration)
21
16
  destination = config["destination"]
22
17
  metadata_file = File.join(config["root_dir"], ".bridgetown-metadata")
@@ -40,5 +35,7 @@ module Bridgetown
40
35
  end
41
36
  end
42
37
  end
38
+
39
+ register_command :clean, Clean
43
40
  end
44
41
  end