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
@@ -2,263 +2,289 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Commands
5
- class Plugins < Thor
6
- include Thor::Actions
7
- include ConfigurationOverridable
8
- include GitHelpers
9
-
10
- Registrations.register do
11
- desc "plugins <command>", "List installed plugins or access plugin content"
12
- subcommand "plugins", Plugins
13
- end
5
+ class Plugins < Bridgetown::Command
6
+ self.description = "List installed plugins or access plugin content"
14
7
 
15
- desc "list", "List information about installed plugins"
16
- option :verbose,
17
- type: :boolean,
18
- desc: "Print the source path of each plugin"
19
- def list
20
- config_options = configuration_with_overrides(options)
21
- config_options.run_initializers! context: :static
22
- site = Bridgetown::Site.new(config_options)
23
- site.reset
24
- Bridgetown::Hooks.trigger :site, :pre_read, site
8
+ class List < Bridgetown::Command
9
+ include ConfigurationOverridable
25
10
 
26
- plugins_list = config_options.initializers.values.sort_by(&:name)
11
+ self.description = "List information about installed plugins"
27
12
 
28
- pm = site.plugin_manager
13
+ def call # rubocop:disable Metrics
14
+ config_options = configuration_with_overrides(@options)
15
+ config_options.run_initializers! context: :static
16
+ site = Bridgetown::Site.new(config_options)
17
+ site.reset
18
+ Bridgetown::Hooks.trigger :site, :pre_read, site
29
19
 
30
- plugins_list += pm.class.registered_plugins.to_a
20
+ plugins_list = config_options.initializers.values.sort_by(&:name)
31
21
 
32
- plugins_list.reject! do |plugin|
33
- plugin.to_s.end_with?("site_builder.rb") || plugin.to_s == "init (Initializer)"
34
- end
22
+ pm = site.plugin_manager
35
23
 
36
- Bridgetown.logger.info("Registered Plugins:", plugins_list.length.to_s.yellow.bold)
24
+ plugins_list += pm.class.registered_plugins.to_a
37
25
 
38
- plugins_list.each do |plugin|
39
- plugin_desc = plugin.to_s
26
+ plugins_list.reject! do |plugin|
27
+ plugin.to_s.end_with?("site_builder.rb") || plugin.to_s == "init (Initializer)"
28
+ end
40
29
 
41
- if plugin.is_a?(Bridgetown::Configuration::Initializer)
42
- Bridgetown.logger.info("", plugin_desc)
43
- Bridgetown.logger.debug(
44
- "", "PATH: " + plugin.block.source_location[0]
45
- )
46
- elsif plugin.is_a?(Bundler::StubSpecification) || plugin.is_a?(Gem::Specification)
47
- Bridgetown.logger.info("", "#{plugin.name} (Rubygem)")
48
- Bridgetown.logger.debug(
49
- "", "PATH: " + plugin.full_gem_path
50
- )
51
- else
52
- Bridgetown.logger.info("", plugin_desc.sub(site.in_root_dir("/"), ""))
30
+ Bridgetown.logger.info("Registered Plugins:", plugins_list.length.to_s.yellow.bold)
31
+
32
+ plugins_list.each do |plugin|
33
+ plugin_desc = plugin.to_s
34
+
35
+ if plugin.is_a?(Bridgetown::Configuration::Initializer)
36
+ Bridgetown.logger.info("", plugin_desc)
37
+ Bridgetown.logger.debug(
38
+ "", "PATH: #{plugin.block.source_location[0]}"
39
+ )
40
+ elsif plugin.is_a?(Bundler::StubSpecification) || plugin.is_a?(Gem::Specification)
41
+ Bridgetown.logger.info("", "#{plugin.name} (Rubygem)")
42
+ Bridgetown.logger.debug(
43
+ "", "PATH: #{plugin.full_gem_path}"
44
+ )
45
+ else
46
+ Bridgetown.logger.info("", plugin_desc.sub(site.in_root_dir("/"), ""))
47
+ end
48
+
49
+ Bridgetown.logger.debug("")
53
50
  end
54
51
 
55
- Bridgetown.logger.debug("")
56
- end
52
+ unless site.config.source_manifests.empty?
53
+ Bridgetown.logger.info("Source Manifests:", "----")
54
+ end
57
55
 
58
- unless site.config.source_manifests.empty?
59
- Bridgetown.logger.info("Source Manifests:", "----")
60
- end
56
+ site.config.source_manifests.each do |manifest|
57
+ Bridgetown.logger.info("Origin:", (manifest.origin || "n/a").to_s.green)
58
+ Bridgetown.logger.info("Components:", (manifest.components || "n/a").to_s.cyan)
59
+ Bridgetown.logger.info("Contents:", (
60
+ manifest.contents&.map { |k, v| "#{v} (#{k})" }&.join(", ") || "n/a"
61
+ ).to_s.cyan)
62
+ Bridgetown.logger.info("Layouts:", (manifest.layouts || "n/a").to_s.cyan)
61
63
 
62
- site.config.source_manifests.each do |manifest|
63
- Bridgetown.logger.info("Origin:", (manifest.origin || "n/a").to_s.green)
64
- Bridgetown.logger.info("Components:", (manifest.components || "n/a").to_s.cyan)
65
- Bridgetown.logger.info("Content:", (manifest.content || "n/a").to_s.cyan)
66
- Bridgetown.logger.info("Layouts:", (manifest.layouts || "n/a").to_s.cyan)
64
+ Bridgetown.logger.info("", "----")
65
+ end
67
66
 
68
- Bridgetown.logger.info("", "----")
69
- end
67
+ unless Bridgetown.autoload? :Builder
68
+ builders = Bridgetown::Builder.descendants
69
+ Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)
70
+
71
+ builders.sort.each do |builder|
72
+ name = plugin_name_for(builder)
73
+ name_components = name.split("::")
74
+ last_name = name_components.pop
75
+ name_components.push last_name.magenta
76
+ Bridgetown.logger.info("", name_components.join("::"))
77
+ Bridgetown.logger.debug(
78
+ "", "PATH: #{builder_path_for(builder)}"
79
+ )
80
+ Bridgetown.logger.debug("")
81
+ end
82
+ Bridgetown.logger.info("", "----")
83
+ end
70
84
 
71
- unless Bridgetown.autoload? :Builder
72
- builders = Bridgetown::Builder.descendants
73
- Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)
85
+ Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)
74
86
 
75
- builders.sort.each do |builder|
76
- name = plugin_name_for(builder)
87
+ site.converters.each do |converter|
88
+ name = plugin_name_for(converter)
77
89
  name_components = name.split("::")
78
90
  last_name = name_components.pop
79
91
  name_components.push last_name.magenta
80
92
  Bridgetown.logger.info("", name_components.join("::"))
81
93
  Bridgetown.logger.debug(
82
- "", "PATH: " + builder_path_for(builder)
94
+ "", "PATH: #{converter_path_for(converter)}"
83
95
  )
84
96
  Bridgetown.logger.debug("")
85
97
  end
98
+
86
99
  Bridgetown.logger.info("", "----")
87
- end
88
100
 
89
- Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)
90
-
91
- site.converters.each do |converter|
92
- name = plugin_name_for(converter)
93
- name_components = name.split("::")
94
- last_name = name_components.pop
95
- name_components.push last_name.magenta
96
- Bridgetown.logger.info("", name_components.join("::"))
97
- Bridgetown.logger.debug(
98
- "", "PATH: " + converter_path_for(converter)
99
- )
100
- Bridgetown.logger.debug("")
101
- end
101
+ Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)
102
102
 
103
- Bridgetown.logger.info("", "----")
103
+ site.generators.each do |generator|
104
+ name = plugin_name_for(generator)
105
+ name_components = name.split("::")
106
+ last_name = name_components.pop
107
+ name_components.push last_name.magenta
108
+ Bridgetown.logger.info("", name_components.join("::"))
109
+ Bridgetown.logger.debug(
110
+ "", "PATH: #{generator_path_for(generator)}"
111
+ )
112
+ Bridgetown.logger.debug("")
113
+ end
114
+ end
104
115
 
105
- Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)
116
+ protected
106
117
 
107
- site.generators.each do |generator|
108
- name = plugin_name_for(generator)
109
- name_components = name.split("::")
110
- last_name = name_components.pop
111
- name_components.push last_name.magenta
112
- Bridgetown.logger.info("", name_components.join("::"))
113
- Bridgetown.logger.debug(
114
- "", "PATH: " + generator_path_for(generator)
115
- )
116
- Bridgetown.logger.debug("")
118
+ def plugin_name_for(plugin)
119
+ klass = plugin.is_a?(Class) ? plugin : plugin.class
120
+ klass.respond_to?(:custom_name) ? klass.custom_name : klass.name
117
121
  end
118
- end
119
122
 
120
- long_desc <<-DOC
121
- Open a directory (content, layouts, etc.) within the plugin origin. \n
122
- First run bridgetown plugins list to view source manifests currently
123
- set up on your site.\n
124
- Then look for the origin of the manifest and the folder you'd like to
125
- open.\n
126
- So for example, with an origin of SamplePlugin and a folder of
127
- Layouts, you'd run:\n
128
- bridgetown plugins cd SamplePlugin/Layouts
129
- DOC
130
- desc "cd <origin/dir>", "Open content folder within the plugin origin"
131
-
132
- # This is super useful if you want to copy files out of plugins to override.
133
- #
134
- # Example:
135
- # bridgetown plugins cd AwesomePlugin/layouts
136
- # cp -r * $BRIDGETOWN_SITE/src/_layouts
137
- #
138
- # Now all the plugin's layouts will be in the site repo directly.
139
- #
140
- def cd(arg)
141
- config_options = configuration_with_overrides(options)
142
- config_options.run_initializers! context: :static
143
-
144
- directive = arg.split("/")
145
- unless directive[1]
146
- Bridgetown.logger.warn("Oops!", "Your command needs to be in the <origin/dir> format")
147
- return
123
+ def builder_path_for(plugin)
124
+ klass = plugin.is_a?(Class) ? plugin : plugin.class
125
+ klass.instance_method(:build).source_location[0]
148
126
  end
149
127
 
150
- manifest = config_options.source_manifests.find do |source_manifest|
151
- source_manifest.origin.to_s == directive[0]
128
+ def converter_path_for(plugin)
129
+ klass = plugin.is_a?(Class) ? plugin : plugin.class
130
+ klass.instance_method(:convert).source_location[0]
152
131
  end
153
132
 
154
- if manifest.respond_to?(directive[1].downcase)
155
- dir = manifest.send(directive[1].downcase)
156
- Bridgetown.logger.info("Opening the #{dir.green} folder for" \
157
- " #{manifest.origin.to_s.cyan}…")
158
- Bridgetown.logger.info("Type #{"exit".yellow} when you're done to" \
159
- " return to your site root.")
160
- puts
161
-
162
- # rubocop: disable Style/RedundantCondition
163
- Dir.chdir dir do
164
- ENV["BRIDGETOWN_SITE"] = config_options.root_dir
165
- if ENV["SHELL"]
166
- system(ENV["SHELL"])
167
- else
168
- system("/bin/sh")
169
- end
170
- end
171
- # rubocop: enable Style/RedundantCondition
172
-
173
- puts
174
- Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
175
- else
176
- Bridgetown.logger.warn("Oops!", "I wasn't able to find the" \
177
- " #{directive[1]} folder for #{directive[0]}")
133
+ def generator_path_for(plugin)
134
+ klass = plugin.is_a?(Class) ? plugin : plugin.class
135
+ klass.instance_method(:generate).source_location[0]
178
136
  end
179
137
  end
180
138
 
181
- desc "new NAME", "Create a new plugin NAME (snake_case_name_preferred)"
182
- def new(name)
183
- folder_name = name.underscore
184
- module_name = folder_name.camelize
185
-
186
- run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
187
- new_gemspec = "#{folder_name}.gemspec"
188
-
189
- inside name do # rubocop:todo Metrics/BlockLength
190
- destroy_existing_repo
191
- initialize_new_repo
192
-
193
- FileUtils.mv "sample_plugin.gemspec", new_gemspec
194
- gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
195
- gsub_file new_gemspec, "bridgetown-sample-plugin", name
196
- gsub_file new_gemspec, "sample_plugin", folder_name
197
- gsub_file new_gemspec, "SamplePlugin", module_name
198
-
199
- gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
200
- gsub_file "package.json", "bridgetown-sample-plugin", name
201
- gsub_file "package.json", "sample_plugin", folder_name
202
-
203
- FileUtils.mv "lib/sample_plugin.rb", "lib/#{folder_name}.rb"
204
- gsub_file "lib/#{folder_name}.rb", "sample_plugin", folder_name
205
- gsub_file "lib/#{folder_name}.rb", "SamplePlugin", module_name
206
-
207
- FileUtils.mv "lib/sample_plugin", "lib/#{folder_name}"
208
- gsub_file "lib/#{folder_name}/builder.rb", "SamplePlugin", module_name
209
- gsub_file "lib/#{folder_name}/builder.rb", "sample_plugin", folder_name
210
- gsub_file "lib/#{folder_name}/version.rb", "SamplePlugin", module_name
211
-
212
- FileUtils.mv "test/test_sample_plugin.rb", "test/test_#{folder_name}.rb"
213
- gsub_file "test/test_#{folder_name}.rb", "SamplePlugin", module_name
214
- gsub_file "test/test_#{folder_name}.rb", "sample plugin", module_name
215
- gsub_file "test/helper.rb", "sample_plugin", folder_name
216
- gsub_file "test/fixtures/src/index.html", "sample_plugin", folder_name
217
- gsub_file "test/fixtures/config/initializers.rb", "sample_plugin", folder_name
218
-
219
- FileUtils.mv "components/sample_plugin", "components/#{folder_name}"
220
- FileUtils.mv "content/sample_plugin", "content/#{folder_name}"
221
- FileUtils.mv "layouts/sample_plugin", "layouts/#{folder_name}"
222
-
223
- gsub_file "layouts/#{folder_name}/layout.html", "sample_plugin", folder_name
224
- gsub_file "content/#{folder_name}/example_page.md", "sample_plugin", folder_name
225
- gsub_file "components/#{folder_name}/layout_help.liquid", "sample_plugin", folder_name
226
-
227
- gsub_file "components/#{folder_name}/plugin_component.rb", "SamplePlugin", module_name
228
-
229
- gsub_file "frontend/javascript/index.js", "sample_plugin", folder_name
230
- gsub_file "frontend/javascript/index.js", "SamplePlugin", module_name
231
- gsub_file "frontend/styles/index.css", "sample_plugin", folder_name
139
+ class New < Bridgetown::Command
140
+ using Bridgetown::Refinements
141
+ include Freyia::Setup
142
+ include Automations
143
+ include GitHelpers
144
+
145
+ self.description = "Create a new plugin"
146
+
147
+ one :name, "(snake_case_name_preferred)", required: true
148
+
149
+ def call # rubocop:disable Metrics
150
+ self.source_paths = [Dir.pwd]
151
+ self.destination_root = Dir.pwd
152
+
153
+ folder_name = name.underscore
154
+ module_name = folder_name.camelize
155
+
156
+ run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
157
+ new_gemspec = "#{folder_name}.gemspec"
158
+
159
+ inside name do # rubocop:todo Metrics/BlockLength
160
+ destroy_existing_repo
161
+ initialize_new_repo
162
+
163
+ FileUtils.mv "sample_plugin.gemspec", new_gemspec
164
+ gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
165
+ gsub_file new_gemspec, "bridgetown-sample-plugin", name
166
+ gsub_file new_gemspec, "sample_plugin", folder_name
167
+ gsub_file new_gemspec, "SamplePlugin", module_name
168
+
169
+ gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
170
+ gsub_file "package.json", "bridgetown-sample-plugin", name
171
+ gsub_file "package.json", "sample_plugin", folder_name
172
+
173
+ FileUtils.mv "lib/sample_plugin.rb", "lib/#{folder_name}.rb"
174
+ gsub_file "lib/#{folder_name}.rb", "sample_plugin", folder_name
175
+ gsub_file "lib/#{folder_name}.rb", "SamplePlugin", module_name
176
+
177
+ FileUtils.mv "lib/sample_plugin", "lib/#{folder_name}"
178
+ gsub_file "lib/#{folder_name}/builder.rb", "SamplePlugin", module_name
179
+ gsub_file "lib/#{folder_name}/builder.rb", "sample_plugin", folder_name
180
+ gsub_file "lib/#{folder_name}/version.rb", "SamplePlugin", module_name
181
+
182
+ FileUtils.mv "test/test_sample_plugin.rb", "test/test_#{folder_name}.rb"
183
+ gsub_file "test/test_#{folder_name}.rb", "SamplePlugin", module_name
184
+ gsub_file "test/test_#{folder_name}.rb", "sample plugin", module_name
185
+ gsub_file "test/helper.rb", "sample_plugin", folder_name
186
+ gsub_file "test/fixtures/src/index.html", "sample_plugin", folder_name
187
+ gsub_file "test/fixtures/config/initializers.rb", "sample_plugin", folder_name
188
+
189
+ FileUtils.mv "components/sample_plugin", "components/#{folder_name}"
190
+ FileUtils.mv "content/sample_plugin", "content/#{folder_name}"
191
+ FileUtils.mv "layouts/sample_plugin", "layouts/#{folder_name}"
192
+
193
+ gsub_file "layouts/#{folder_name}/layout.html", "sample_plugin", folder_name
194
+ gsub_file "content/#{folder_name}/example_page.md", "sample_plugin", folder_name
195
+ gsub_file "components/#{folder_name}/layout_help.liquid", "sample_plugin", folder_name
196
+
197
+ gsub_file "components/#{folder_name}/plugin_component.rb", "SamplePlugin", module_name
198
+
199
+ gsub_file "frontend/javascript/index.js", "sample_plugin", folder_name
200
+ gsub_file "frontend/javascript/index.js", "SamplePlugin", module_name
201
+ gsub_file "frontend/styles/index.css", "sample_plugin", folder_name
202
+ end
203
+ say ""
204
+ say_status "Done!", "Have fun writing your new #{name} plugin :)"
205
+ say_status "Remember:", "Don't forget to rename the SamplePlugin " \
206
+ "code identifiers and paths to your own " \
207
+ "identifier, as well as update your README " \
208
+ "and CHANGELOG files as necessary."
232
209
  end
233
- say ""
234
- say_status "Done!", "Have fun writing your new #{name} plugin :)"
235
- say_status "Remember:", "Don't forget to rename the SamplePlugin" \
236
- " code identifiers and paths to your own" \
237
- " identifier, as well as update your README" \
238
- " and CHANGELOG files as necessary."
239
210
  end
240
211
 
241
- protected
212
+ class CD < Bridgetown::Command
213
+ include ConfigurationOverridable
214
+
215
+ self.description = "Open content folder within the plugin origin"
216
+
217
+ one :path, <<~DOC.strip, required: true
218
+ Open a directory (content, layouts, etc.) within the plugin origin. \n
219
+ #{format("%c[0m", 27)}First: run bridgetown plugins list to view source manifests currently
220
+ #{format("%c[0m", 27)}set up on your site.\n
221
+ #{format("%c[0m", 27)}Then: look for the origin of the manifest and the folder you'd like to
222
+ #{format("%c[0m", 27)}open. Your project path is saved as the $BRIDGETOWN_SITE env var.\n
223
+ #{format("%c[0m", 27)}So for example, with an origin of SamplePlugin and a folder of
224
+ #{format("%c[0m", 27)}Layouts, you'd run:\n
225
+ $ bridgetown plugins cd SamplePlugin/Layouts
226
+ $ cp -r * $BRIDGETOWN_SITE/src/_layouts\n\n<path>
227
+ DOC
228
+
229
+ # This is super useful if you want to copy files out of plugins to override.
230
+ #
231
+ # Example:
232
+ # bridgetown plugins cd AwesomePlugin/layouts
233
+ # cp -r * $BRIDGETOWN_SITE/src/_layouts
234
+ #
235
+ # Now all the plugin's layouts will be in the site repo directly.
236
+ #
237
+ def call # rubocop:disable Metrics
238
+ config_options = configuration_with_overrides(@options)
239
+ config_options.run_initializers! context: :static
240
+
241
+ directive = path.split("/")
242
+ unless directive[1]
243
+ Bridgetown.logger.warn("Oops!", "Your command needs to be in the <origin/dir> format")
244
+ return
245
+ end
242
246
 
243
- def plugin_name_for(plugin)
244
- klass = plugin.is_a?(Class) ? plugin : plugin.class
245
- klass.respond_to?(:custom_name) ? klass.custom_name : klass.name
246
- end
247
+ manifest = config_options.source_manifests.find do |source_manifest|
248
+ source_manifest.origin.to_s == directive[0]
249
+ end
247
250
 
248
- def builder_path_for(plugin)
249
- klass = plugin.is_a?(Class) ? plugin : plugin.class
250
- klass.instance_method(:build).source_location[0]
251
- end
251
+ if manifest.respond_to?(directive[1].downcase)
252
+ dir = manifest.send(directive[1].downcase)
253
+ Bridgetown.logger.info("Opening the #{dir.green} folder for " \
254
+ "#{manifest.origin.to_s.cyan}…")
255
+ Bridgetown.logger.info("Type #{"exit".yellow} when you're done to " \
256
+ "return to your site root.")
257
+ puts
258
+
259
+ Dir.chdir dir do
260
+ ENV["BRIDGETOWN_SITE"] = config_options.root_dir
261
+ system ENV.fetch("SHELL", "/bin/sh")
262
+ end
252
263
 
253
- def converter_path_for(plugin)
254
- klass = plugin.is_a?(Class) ? plugin : plugin.class
255
- klass.instance_method(:convert).source_location[0]
264
+ puts
265
+ Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
266
+ else
267
+ Bridgetown.logger.warn("Oops!", "I wasn't able to find the " \
268
+ "#{directive[1]} folder for #{directive[0]}")
269
+ end
270
+ end
256
271
  end
257
272
 
258
- def generator_path_for(plugin)
259
- klass = plugin.is_a?(Class) ? plugin : plugin.class
260
- klass.instance_method(:generate).source_location[0]
273
+ nested :command, {
274
+ "list" => List,
275
+ "new" => New,
276
+ "cd" => CD,
277
+ }
278
+
279
+ def call
280
+ if @command
281
+ @command.call
282
+ else
283
+ print_usage
284
+ end
261
285
  end
262
286
  end
287
+
288
+ register_command :plugins, Plugins
263
289
  end
264
290
  end
@@ -7,9 +7,18 @@ module Bridgetown
7
7
  @registrations ||= []
8
8
  end
9
9
 
10
- def self.register(&block)
10
+ def self.register(klass = nil, name = nil, &block)
11
+ block ||= proc { register(klass, name) }
12
+
11
13
  registrations << block
12
14
  end
15
+
16
+ def self.load_registrations(command)
17
+ registrations.each do |block|
18
+ command.instance_exec(&block)
19
+ end
20
+ @registrations = []
21
+ end
13
22
  end
14
23
  end
15
24
  end
@@ -28,45 +28,31 @@ module Bridgetown
28
28
  end
29
29
 
30
30
  module Commands
31
- class Start < Thor::Group
32
- extend BuildOptions
33
- extend Summarizable
31
+ class Start < Bridgetown::Command
34
32
  include ConfigurationOverridable
33
+ include Freyia::Setup
35
34
  include Inclusive
36
35
 
37
- Registrations.register do
38
- register(Start, "start", "start", Start.summary)
39
- register(Start, "dev", "dev", "Alias of start")
36
+ self.description = "Start the web server, frontend bundler, and Bridgetown watcher"
37
+
38
+ options do
39
+ BuildOptions.include_options(self)
40
+ option "-P/--port <NUM>",
41
+ "Serve your site on the specified port. Defaults to 4000",
42
+ type: Integer
43
+ option "-B/--bind <IP>", "IP address for the server to bind to", default: "0.0.0.0"
44
+ option "--skip-frontend", "Don't load the frontend bundler (always true for production)"
45
+ option "--skip-live-reload",
46
+ "Don't use the live reload functionality (always true for production)"
40
47
  end
41
48
 
42
- class_option :port,
43
- aliases: "-P",
44
- type: :numeric,
45
- desc: "Serve your site on the specified port. Defaults to 4000."
46
- class_option :bind,
47
- aliases: "-B",
48
- type: :string,
49
- default: "0.0.0.0",
50
- desc: "URL for the server to bind to."
51
- class_option :skip_frontend,
52
- type: :boolean,
53
- desc: "Don't load the frontend bundler (always true for production)."
54
- class_option :skip_live_reload,
55
- type: :boolean,
56
- desc: "Don't use the live reload functionality (always true for production)."
57
-
58
- def self.banner
59
- "bridgetown start [options]"
60
- end
61
- summary "Start the web server, frontend bundler, and Bridgetown watcher"
62
-
63
- def start
49
+ def call # rubocop:disable Metrics
64
50
  pid_tracker = packages[Bridgetown::Foundation::Packages::PidTracker]
65
51
  Bridgetown.logger.writer.enable_prefix
66
52
  Bridgetown::Commands::Build.print_startup_message
67
53
  sleep 0.25
68
54
 
69
- options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
55
+ options = HashWithDotAccess::Hash.new(self.options)
70
56
  options[:start_command] = true
71
57
 
72
58
  # Load Bridgetown configuration into thread memory
@@ -90,8 +76,8 @@ module Bridgetown
90
76
 
91
77
  bt_options.skip_live_reload ||= !server.using_puma?
92
78
 
93
- build_args = ["-w"] + ARGV.reject { |arg| arg == "start" }
94
- build_pid = Process.fork { Bridgetown::Commands::Build.start(build_args) }
79
+ build_args = ["-w"] + Array(ARGV[1..])
80
+ build_pid = Process.fork { Bridgetown::Commands::Build[*build_args].() }
95
81
  pid_tracker.add_pid(build_pid, file: :bridgetown)
96
82
 
97
83
  after_stop_callback = -> {
@@ -141,5 +127,11 @@ module Bridgetown
141
127
  options[:port] || ENV.fetch("BRIDGETOWN_PORT", config.port || 4000)
142
128
  end
143
129
  end
130
+
131
+ Dev = Start.dup
132
+ Dev.description = "Alias for the start command"
133
+
134
+ register_command :start, Start
135
+ register_command :dev, Dev
144
136
  end
145
137
  end