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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -2
- data/bin/bridgetown +19 -7
- data/bridgetown-core.gemspec +8 -6
- data/lib/bridgetown-core/collection.rb +4 -3
- data/lib/bridgetown-core/command.rb +97 -0
- data/lib/bridgetown-core/commands/application.rb +208 -0
- data/lib/bridgetown-core/commands/apply.rb +17 -29
- data/lib/bridgetown-core/commands/build.rb +9 -16
- data/lib/bridgetown-core/commands/clean.rb +7 -10
- data/lib/bridgetown-core/commands/concerns/{actions.rb → automations.rb} +103 -17
- data/lib/bridgetown-core/commands/concerns/build_options.rb +24 -60
- data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +2 -4
- data/lib/bridgetown-core/commands/configure.rb +24 -24
- data/lib/bridgetown-core/commands/console.rb +38 -34
- data/lib/bridgetown-core/commands/esbuild.rb +14 -24
- data/lib/bridgetown-core/commands/help.rb +24 -0
- data/lib/bridgetown-core/commands/new.rb +38 -60
- data/lib/bridgetown-core/commands/plugins.rb +237 -211
- data/lib/bridgetown-core/commands/registrations.rb +10 -1
- data/lib/bridgetown-core/commands/start.rb +23 -31
- data/lib/bridgetown-core/commands/thor_shim.rb +94 -0
- data/lib/bridgetown-core/component.rb +3 -3
- data/lib/bridgetown-core/concerns/publishable.rb +1 -3
- data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
- data/lib/bridgetown-core/configuration/configuration_dsl.rb +2 -2
- data/lib/bridgetown-core/configuration.rb +27 -7
- data/lib/bridgetown-core/converters/erb_templates.rb +31 -21
- data/lib/bridgetown-core/converters/ruby_templates.rb +14 -13
- data/lib/bridgetown-core/converters/serbea_templates.rb +5 -2
- data/lib/bridgetown-core/entry_filter.rb +1 -4
- data/lib/bridgetown-core/front_matter/defaults.rb +1 -1
- data/lib/bridgetown-core/front_matter/importer.rb +7 -1
- data/lib/bridgetown-core/front_matter/loaders.rb +1 -1
- data/lib/bridgetown-core/front_matter/ruby.rb +3 -9
- data/lib/bridgetown-core/generated_page.rb +2 -2
- data/lib/bridgetown-core/generators/prototype_generator.rb +1 -1
- data/lib/bridgetown-core/helpers.rb +10 -11
- data/lib/bridgetown-core/hooks.rb +2 -3
- data/lib/bridgetown-core/locale/en.yml +30 -0
- data/lib/bridgetown-core/model/base.rb +5 -5
- data/lib/bridgetown-core/model/builder_origin.rb +1 -1
- data/lib/bridgetown-core/model/origin.rb +5 -1
- data/lib/bridgetown-core/model/plugin_origin.rb +3 -1
- data/lib/bridgetown-core/model/repo_origin.rb +3 -1
- data/lib/bridgetown-core/rack/routes.rb +1 -1
- data/lib/bridgetown-core/reader.rb +2 -2
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +31 -7
- data/lib/bridgetown-core/resource/base.rb +16 -7
- data/lib/bridgetown-core/resource/destination.rb +1 -1
- data/lib/bridgetown-core/resource/permalink_processor.rb +4 -4
- data/lib/bridgetown-core/static_file.rb +1 -1
- data/lib/bridgetown-core/tags/class_map.rb +0 -2
- data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +8 -11
- data/lib/bridgetown-core/{ruby_template_view.rb → template_view.rb} +108 -4
- data/lib/bridgetown-core/utils/initializers.rb +28 -1
- data/lib/bridgetown-core/utils/loaders_manager.rb +2 -1
- data/lib/bridgetown-core/utils.rb +19 -1
- data/lib/bridgetown-core/watcher.rb +16 -8
- data/lib/bridgetown-core.rb +5 -10
- data/lib/roda/plugins/bridgetown_server.rb +1 -1
- data/lib/site_template/README.md +10 -8
- metadata +84 -70
- data/lib/bridgetown-core/commands/base.rb +0 -123
- data/lib/bridgetown-core/commands/concerns/summarizable.rb +0 -13
- data/lib/bridgetown-core/configurations/.keep +0 -0
- data/lib/bridgetown-core/configurations/stimulus.rb +0 -59
- data/lib/bridgetown-core/configurations/turbo/turbo_transitions.js +0 -48
- data/lib/bridgetown-core/configurations/turbo.rb +0 -35
- data/lib/bridgetown-core/configurations/vercel/vercel.json +0 -45
- data/lib/bridgetown-core/configurations/vercel/vercel_url.rb +0 -12
- data/lib/bridgetown-core/configurations/vercel.rb +0 -4
- data/lib/bridgetown-core/inflector.rb +0 -40
|
@@ -2,14 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
4
|
module Commands
|
|
5
|
-
|
|
5
|
+
# Automation tasks to aid in setting up new Bridgetown site configs or plugin setup.
|
|
6
|
+
# Also includes all of the tasks provided by Freyia
|
|
7
|
+
module Automations
|
|
8
|
+
include Freyia::Setup
|
|
9
|
+
|
|
10
|
+
def self.included(klass)
|
|
11
|
+
klass.extend Freyia::Setup::ClassMethods
|
|
12
|
+
end
|
|
13
|
+
|
|
6
14
|
using Bridgetown::Refinements
|
|
7
15
|
|
|
8
16
|
GITHUB_REGEX = %r!https://github\.com!
|
|
9
17
|
GITHUB_TREE_REGEX = %r!#{GITHUB_REGEX}/.*/.*/tree/.*/?!
|
|
10
18
|
GITHUB_BLOB_REGEX = %r!#{GITHUB_REGEX}/.*/.*/blob/!
|
|
11
19
|
GITHUB_REPO_REGEX = %r!github\.com/(.*?/[^/]*)!
|
|
20
|
+
GITLAB_REGEX = %r!https://gitlab\.com!
|
|
21
|
+
GITLAB_TREE_REGEX = %r!#{GITLAB_REGEX}/.*/.*/-/tree/.*/?!
|
|
22
|
+
GITLAB_BLOB_REGEX = %r!#{GITLAB_REGEX}/.*/.*/-/blob/!
|
|
23
|
+
GITLAB_REPO_REGEX = %r!gitlab\.com/(.*?/[^/]*)!
|
|
24
|
+
CODEBERG_REGEX = %r!https://codeberg\.org!
|
|
25
|
+
CODEBERG_TREE_REGEX = %r!#{CODEBERG_REGEX}/.*/.*/src/branch/.*/?!
|
|
26
|
+
CODEBERG_REPO_REGEX = %r!codeberg\.org/(.*?/[^/]*)!
|
|
12
27
|
|
|
28
|
+
# Creates a new Builder class with the provided filename and Ruby code
|
|
29
|
+
#
|
|
30
|
+
# @param filename [String]
|
|
31
|
+
# @param data [String] Ruby code, if block not provided
|
|
13
32
|
def create_builder(filename, data = nil)
|
|
14
33
|
say_status :create_builder, filename
|
|
15
34
|
data ||= yield if block_given?
|
|
@@ -27,6 +46,10 @@ module Bridgetown
|
|
|
27
46
|
create_file("plugins/builders/#{filename}", data, verbose: false)
|
|
28
47
|
end
|
|
29
48
|
|
|
49
|
+
# Adds a new JavaScript import statement to the end of existing import statements (if any)
|
|
50
|
+
#
|
|
51
|
+
# @param data [String] Ruby code, if block not provided
|
|
52
|
+
# @param filename [String] supply a filename if the default `index.js` isn't desired
|
|
30
53
|
def javascript_import(data = nil, filename: "index.js") # rubocop:todo Metrics/PerceivedComplexity
|
|
31
54
|
data ||= yield if block_given?
|
|
32
55
|
data += "\n" unless data[-1] == "\n"
|
|
@@ -54,6 +77,12 @@ module Bridgetown
|
|
|
54
77
|
end
|
|
55
78
|
end
|
|
56
79
|
|
|
80
|
+
# Uses `bundle add` to add a new gem to the project `Gemfile`
|
|
81
|
+
#
|
|
82
|
+
# @param gemname [String]
|
|
83
|
+
# @param group [String] normally the gem isn't added to any group, but you can specify
|
|
84
|
+
# a particular group
|
|
85
|
+
# @param version [String] useful if you need to force a specific version or range
|
|
57
86
|
def add_gem(gemname, group: nil, version: nil)
|
|
58
87
|
options = +""
|
|
59
88
|
options += " -v \"#{version}\"" if version
|
|
@@ -66,6 +95,10 @@ module Bridgetown
|
|
|
66
95
|
end
|
|
67
96
|
alias_method :add_bridgetown_plugin, :add_gem
|
|
68
97
|
|
|
98
|
+
# Add an `init` statement to the project's `config/initializers.rb` file
|
|
99
|
+
#
|
|
100
|
+
# @param name [Symbol] initializer / plugin name
|
|
101
|
+
# @param data [String] additional Ruby code, if block not provided
|
|
69
102
|
def add_initializer(name, data = "")
|
|
70
103
|
say_status :initializer, name
|
|
71
104
|
data = yield if block_given?
|
|
@@ -84,6 +117,11 @@ module Bridgetown
|
|
|
84
117
|
before: %r!^end$!, verbose: false, force: false
|
|
85
118
|
end
|
|
86
119
|
|
|
120
|
+
# Similar to the `add_initializer` method, but supports adding arbitrary Ruby code of any
|
|
121
|
+
# kind to the `config/initializers.rb` file
|
|
122
|
+
#
|
|
123
|
+
# @param name [Symbol, String] name of configuration (purely for user display feedback)
|
|
124
|
+
# @param data [String] Ruby code, if block not provided
|
|
87
125
|
def ruby_configure(name, data = "")
|
|
88
126
|
say_status :configure, name
|
|
89
127
|
data = yield if block_given?
|
|
@@ -101,6 +139,10 @@ module Bridgetown
|
|
|
101
139
|
before: %r!^end$!, verbose: false, force: false
|
|
102
140
|
end
|
|
103
141
|
|
|
142
|
+
# Given the name of a gem, it will analyze that gem's metadata looking for a suitable NPM
|
|
143
|
+
# companion package. (Requires `npm_add` to be defined.)
|
|
144
|
+
#
|
|
145
|
+
# @param gemname [Symbol]
|
|
104
146
|
def add_npm_for_gem(gemname)
|
|
105
147
|
say_status :add_npm, gemname
|
|
106
148
|
|
|
@@ -112,14 +154,23 @@ module Bridgetown
|
|
|
112
154
|
end
|
|
113
155
|
alias_method :add_yarn_for_gem, :add_npm_for_gem
|
|
114
156
|
|
|
157
|
+
# Adds the provided NPM package to the project's `package.json`
|
|
158
|
+
#
|
|
159
|
+
# @param package_details [String] the package name, and any optional flags
|
|
115
160
|
def add_npm_package(package_details)
|
|
116
161
|
run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_install_command} #{package_details}" # rubocop:disable Layout
|
|
117
162
|
end
|
|
118
163
|
|
|
164
|
+
# Removes an NPM package
|
|
165
|
+
#
|
|
166
|
+
# @param package_details [String] the package name, and any optional flags
|
|
119
167
|
def remove_npm_package(package_details)
|
|
120
168
|
run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_uninstall_command} #{package_details}" # rubocop:disable Layout
|
|
121
169
|
end
|
|
122
170
|
|
|
171
|
+
# Calls Freyia's `apply` method after transforming the URL according to Automations rules
|
|
172
|
+
#
|
|
173
|
+
# @param url [String] URL to a file or a repo
|
|
123
174
|
def apply_from_url(url)
|
|
124
175
|
apply transform_automation_url(url.dup)
|
|
125
176
|
end
|
|
@@ -127,6 +178,7 @@ module Bridgetown
|
|
|
127
178
|
private
|
|
128
179
|
|
|
129
180
|
def determine_remote_filename(arg)
|
|
181
|
+
arg = arg.sub(%r!\?.*$!, "") # chop query string if need be
|
|
130
182
|
if arg.end_with?(".rb")
|
|
131
183
|
arg.split("/").then do |segments|
|
|
132
184
|
arg.sub!(%r!/#{segments.last}$!, "")
|
|
@@ -138,36 +190,70 @@ module Bridgetown
|
|
|
138
190
|
end
|
|
139
191
|
|
|
140
192
|
# TODO: option to download and confirm remote automation?
|
|
141
|
-
#
|
|
193
|
+
# @param arg [String]
|
|
142
194
|
def transform_automation_url(arg)
|
|
143
195
|
return arg unless arg.start_with?("http")
|
|
144
196
|
|
|
145
197
|
remote_file = determine_remote_filename(arg)
|
|
146
|
-
github_match = GITHUB_REGEX.match(arg)
|
|
147
198
|
|
|
148
|
-
arg =
|
|
199
|
+
arg = case arg
|
|
200
|
+
when GITHUB_REGEX
|
|
201
|
+
transform_github_url arg
|
|
202
|
+
when %r{^https://gist.github.com}
|
|
149
203
|
arg.sub( # rubocop:disable Style/StringConcatenation
|
|
150
204
|
"https://gist.github.com", "https://gist.githubusercontent.com"
|
|
151
205
|
) + "/raw"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if github_tree_match
|
|
158
|
-
new_url.sub("/tree/", "/")
|
|
159
|
-
elsif github_blob_match
|
|
160
|
-
new_url.sub("/blob/", "/")
|
|
161
|
-
else
|
|
162
|
-
"#{new_url}/#{Bridgetown::Utils.default_github_branch_name(arg)}"
|
|
163
|
-
end
|
|
206
|
+
when GITLAB_REGEX
|
|
207
|
+
transform_gitlab_url arg
|
|
208
|
+
when CODEBERG_REGEX
|
|
209
|
+
transform_codeberg_url arg
|
|
164
210
|
else
|
|
165
211
|
arg
|
|
166
212
|
end
|
|
167
213
|
|
|
168
214
|
"#{arg}/#{remote_file}"
|
|
169
215
|
end
|
|
170
|
-
|
|
216
|
+
|
|
217
|
+
def transform_github_url(url)
|
|
218
|
+
new_url = url.sub(GITHUB_REGEX, "https://raw.githubusercontent.com")
|
|
219
|
+
tree_match = GITHUB_TREE_REGEX.match?(url)
|
|
220
|
+
blob_match = GITHUB_BLOB_REGEX.match?(url)
|
|
221
|
+
|
|
222
|
+
if tree_match
|
|
223
|
+
new_url.sub("/tree/", "/")
|
|
224
|
+
elsif blob_match
|
|
225
|
+
new_url.sub("/blob/", "/")
|
|
226
|
+
else
|
|
227
|
+
"#{new_url}/#{Bridgetown::Utils.default_github_branch_name(url)}"
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def transform_gitlab_url(url)
|
|
232
|
+
new_url = url.dup
|
|
233
|
+
tree_match = GITLAB_TREE_REGEX.match?(url)
|
|
234
|
+
blob_match = GITLAB_BLOB_REGEX.match?(url)
|
|
235
|
+
|
|
236
|
+
if tree_match
|
|
237
|
+
new_url.sub("/tree/", "/raw/")
|
|
238
|
+
elsif blob_match
|
|
239
|
+
new_url.sub("/blob/", "/raw/")
|
|
240
|
+
else
|
|
241
|
+
"#{new_url}/-/raw/#{Bridgetown::Utils.default_gitlab_branch_name(url)}"
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def transform_codeberg_url(url)
|
|
246
|
+
new_url = url.dup
|
|
247
|
+
tree_match = CODEBERG_TREE_REGEX.match?(url)
|
|
248
|
+
|
|
249
|
+
if tree_match
|
|
250
|
+
new_url.sub("/src/", "/raw/")
|
|
251
|
+
else
|
|
252
|
+
"#{new_url}/raw/branch/#{Bridgetown::Utils.default_codeberg_branch_name(url)}"
|
|
253
|
+
end
|
|
254
|
+
end
|
|
171
255
|
end
|
|
256
|
+
|
|
257
|
+
Actions = Automations # alias
|
|
172
258
|
end
|
|
173
259
|
end
|
|
@@ -3,66 +3,30 @@
|
|
|
3
3
|
module Bridgetown
|
|
4
4
|
module Commands
|
|
5
5
|
module BuildOptions
|
|
6
|
-
def self.
|
|
7
|
-
klass.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
klass.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
klass.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
klass.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
klass.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
desc: "Plugins directory (defaults to plugins)"
|
|
31
|
-
klass.class_option :layouts_dir,
|
|
32
|
-
desc: "Layouts directory (defaults to src/_layouts)"
|
|
33
|
-
klass.class_option :future,
|
|
34
|
-
type: :boolean,
|
|
35
|
-
desc: "Publishes posts with a future date"
|
|
36
|
-
klass.class_option :url,
|
|
37
|
-
aliases: "-u",
|
|
38
|
-
desc: "Override the configured url for the website"
|
|
39
|
-
klass.class_option :base_path,
|
|
40
|
-
aliases: "-b",
|
|
41
|
-
desc: "Serve the website from the given base path"
|
|
42
|
-
klass.class_option :force_polling,
|
|
43
|
-
type: :boolean,
|
|
44
|
-
desc: "Force watch to use polling"
|
|
45
|
-
klass.class_option :unpublished,
|
|
46
|
-
type: :boolean,
|
|
47
|
-
aliases: "-U",
|
|
48
|
-
desc: "Render posts that were marked as unpublished"
|
|
49
|
-
klass.class_option :disable_disk_cache,
|
|
50
|
-
type: :boolean,
|
|
51
|
-
desc: "Disable caching to disk"
|
|
52
|
-
klass.class_option :profile,
|
|
53
|
-
type: :boolean,
|
|
54
|
-
desc: "Generate a Liquid rendering profile"
|
|
55
|
-
klass.class_option :quiet,
|
|
56
|
-
aliases: "-q",
|
|
57
|
-
type: :boolean,
|
|
58
|
-
desc: "Silence output."
|
|
59
|
-
klass.class_option :verbose,
|
|
60
|
-
aliases: "-V",
|
|
61
|
-
type: :boolean,
|
|
62
|
-
desc: "Print verbose output."
|
|
63
|
-
klass.class_option :strict_front_matter,
|
|
64
|
-
type: :boolean,
|
|
65
|
-
desc: "Fail if errors are present in front matter"
|
|
6
|
+
def self.include_options(klass) # rubocop:disable Metrics/MethodLength
|
|
7
|
+
klass.option "-t/--trace", "Show the full backtrace when an error occurs during watch mode"
|
|
8
|
+
klass.option "--config <FILE1,FILE2>", "Custom configuration file(s)" do |value|
|
|
9
|
+
value.split(%r{\s*,\s*})
|
|
10
|
+
end
|
|
11
|
+
klass.option "-s/--source <SOURCE>", "Source directory (defaults to src)"
|
|
12
|
+
klass.option "-d/--destination <DESTINATION>", "Destination directory (defaults to output)"
|
|
13
|
+
klass.option "-r/--root-dir <DIR>", "The top-level root folder " \
|
|
14
|
+
"where config files are located"
|
|
15
|
+
klass.option "-p/--plugins-dir <DIR1,DIR2>",
|
|
16
|
+
"Plugins directory (defaults to plugins)" do |value|
|
|
17
|
+
value.split(%r{\s*,\s*})
|
|
18
|
+
end
|
|
19
|
+
klass.option "--layouts-dir <DIR>", "Layouts directory (defaults to src/_layouts)"
|
|
20
|
+
klass.option "--future", "Publishes posts with a future date"
|
|
21
|
+
klass.option "-u/--url <URL>", "Override the configured url for the website"
|
|
22
|
+
klass.option "-b/--base-path", "Serve the website from the given base path"
|
|
23
|
+
klass.option "--force-polling", "Force watch to use polling"
|
|
24
|
+
klass.option "-U/--unpublished", "Render posts that were marked as unpublished"
|
|
25
|
+
klass.option "--disable-disk-cache", "Disable caching to disk"
|
|
26
|
+
klass.option "--profile", "Generate a Liquid rendering profile"
|
|
27
|
+
klass.option "-q/--quiet", "Silence output"
|
|
28
|
+
klass.option "-V/--verbose", "Print verbose output"
|
|
29
|
+
klass.option "--strict-front-matter", "Fail if errors are present in front matter"
|
|
66
30
|
end
|
|
67
31
|
end
|
|
68
32
|
end
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
module Bridgetown
|
|
4
4
|
module Commands
|
|
5
5
|
module ConfigurationOverridable
|
|
6
|
-
def self.
|
|
6
|
+
def self.include_options(klass)
|
|
7
7
|
desc = "The environment used for this command (aka development, test, production, etc.)"
|
|
8
|
-
klass.
|
|
9
|
-
aliases: "-e",
|
|
10
|
-
desc:
|
|
8
|
+
klass.option "-e/--environment <ENV>", desc
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
# Create a full Bridgetown configuration with the options passed in as overrides
|
|
@@ -2,45 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
4
|
module Commands
|
|
5
|
-
class Configure <
|
|
6
|
-
include
|
|
7
|
-
include Actions
|
|
8
|
-
extend Summarizable
|
|
5
|
+
class Configure < Bridgetown::Command
|
|
6
|
+
include Automations
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
register(Configure, "configure", "configure CONFIGURATION", Configure.summary)
|
|
12
|
-
end
|
|
8
|
+
self.description = "Set up bundled Bridgetown configurations"
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
"bridgetown configure CONFIGURATION(S)"
|
|
16
|
-
end
|
|
17
|
-
summary "Set up bundled Bridgetown configurations"
|
|
10
|
+
many :configurations, "One or more configuration names, separated by spaces"
|
|
18
11
|
|
|
19
|
-
def self.
|
|
20
|
-
|
|
12
|
+
def self.source_root
|
|
13
|
+
File.expand_path("../configurations", __dir__)
|
|
21
14
|
end
|
|
22
15
|
|
|
23
|
-
def
|
|
16
|
+
def call(new_site_dir: nil)
|
|
17
|
+
self.source_paths = [self.class.source_root]
|
|
18
|
+
self.destination_root = new_site_dir || Dir.pwd
|
|
19
|
+
|
|
20
|
+
unless configurations
|
|
21
|
+
print_usage
|
|
22
|
+
list_configurations
|
|
23
|
+
return
|
|
24
|
+
end
|
|
25
|
+
|
|
24
26
|
@logger = Bridgetown.logger
|
|
25
|
-
list_configurations if args.empty?
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
configurations.each do |configuration|
|
|
28
29
|
configure configuration
|
|
29
|
-
rescue
|
|
30
|
+
rescue Freyia::Error
|
|
30
31
|
@logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
def self.source_root
|
|
35
|
-
File.expand_path("../configurations", __dir__)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
35
|
protected
|
|
39
36
|
|
|
40
37
|
def configure(configuration)
|
|
41
38
|
configuration_file = find_in_source_paths("#{configuration}.rb")
|
|
42
39
|
|
|
43
|
-
inside(
|
|
40
|
+
inside(destination_root) do
|
|
44
41
|
@templates_dir = File.expand_path("../configurations/#{configuration}", __dir__)
|
|
45
42
|
apply configuration_file, verbose: false
|
|
46
43
|
end
|
|
@@ -48,7 +45,8 @@ module Bridgetown
|
|
|
48
45
|
|
|
49
46
|
def list_configurations
|
|
50
47
|
say "Please specify a valid packaged configuration from the below list:\n\n"
|
|
51
|
-
|
|
48
|
+
|
|
49
|
+
configuration_files.each do |configuration|
|
|
52
50
|
configuration = set_color configuration, :blue, :bold
|
|
53
51
|
say configuration
|
|
54
52
|
end
|
|
@@ -58,7 +56,7 @@ module Bridgetown
|
|
|
58
56
|
say "For more info, check out the docs at: #{docs_url}"
|
|
59
57
|
end
|
|
60
58
|
|
|
61
|
-
def
|
|
59
|
+
def configuration_files
|
|
62
60
|
inside self.class.source_root do
|
|
63
61
|
return Dir.glob("*.rb").map { |file| file.sub(".rb", "") }.sort
|
|
64
62
|
end
|
|
@@ -70,5 +68,7 @@ module Bridgetown
|
|
|
70
68
|
end
|
|
71
69
|
end
|
|
72
70
|
end
|
|
71
|
+
|
|
72
|
+
register_command :configure, Configure
|
|
73
73
|
end
|
|
74
74
|
end
|
|
@@ -25,39 +25,23 @@ module Bridgetown
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
module Commands
|
|
28
|
-
class Console <
|
|
29
|
-
extend Summarizable
|
|
28
|
+
class Console < Bridgetown::Command
|
|
30
29
|
include ConfigurationOverridable
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
register(Console, "console", "console", Console.summary)
|
|
34
|
-
end
|
|
31
|
+
self.description = "Invoke an IRB console with the site loaded"
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
options do
|
|
34
|
+
ConfigurationOverridable.include_options(self)
|
|
35
|
+
option "--blank", "Skip reading content and running generators before opening console"
|
|
36
|
+
option "--bypass-ap", "Don't load AmazingPrint when IRB opens"
|
|
37
|
+
option "--config <FILE1,FILE2>", "Custom configuration file(s)" do |value|
|
|
38
|
+
value.split(%r{\s*,\s*})
|
|
39
|
+
end
|
|
40
|
+
option "-s/--server-config", "Load server configurations"
|
|
41
|
+
option "-V/--verbose", "Print verbose output"
|
|
38
42
|
end
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class_option :config,
|
|
42
|
-
type: :array,
|
|
43
|
-
banner: "FILE1 FILE2",
|
|
44
|
-
desc: "Custom configuration file(s)"
|
|
45
|
-
class_option :"bypass-ap",
|
|
46
|
-
type: :boolean,
|
|
47
|
-
desc: "Don't load AmazingPrint when IRB opens"
|
|
48
|
-
class_option :blank,
|
|
49
|
-
type: :boolean,
|
|
50
|
-
desc: "Skip reading content and running generators before opening console"
|
|
51
|
-
class_option :"server-config",
|
|
52
|
-
aliases: "-s",
|
|
53
|
-
type: :boolean,
|
|
54
|
-
desc: "Load server configurations"
|
|
55
|
-
class_option :verbose,
|
|
56
|
-
aliases: "-V",
|
|
57
|
-
type: :boolean,
|
|
58
|
-
desc: "Print verbose output."
|
|
59
|
-
|
|
60
|
-
def console # rubocop:disable Metrics
|
|
43
|
+
|
|
44
|
+
def call # rubocop:disable Metrics
|
|
61
45
|
require "irb"
|
|
62
46
|
new_history_behavior = false
|
|
63
47
|
begin
|
|
@@ -66,7 +50,7 @@ module Bridgetown
|
|
|
66
50
|
# Code path for Ruby 3.3+
|
|
67
51
|
new_history_behavior = true
|
|
68
52
|
end
|
|
69
|
-
require "amazing_print" unless options[:
|
|
53
|
+
require "amazing_print" unless options[:bypass_ap]
|
|
70
54
|
|
|
71
55
|
Bridgetown.logger.adjust_verbosity(**options)
|
|
72
56
|
|
|
@@ -76,9 +60,19 @@ module Bridgetown
|
|
|
76
60
|
Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
|
|
77
61
|
|
|
78
62
|
config_options = configuration_with_overrides(options)
|
|
79
|
-
|
|
63
|
+
|
|
64
|
+
if options[:server_config]
|
|
80
65
|
require "bridgetown-core/rack/boot"
|
|
81
66
|
Bridgetown::Rack.boot
|
|
67
|
+
begin
|
|
68
|
+
require "rack/test"
|
|
69
|
+
IRB::ExtendCommandBundle.include ::Rack::Test::Methods
|
|
70
|
+
ConsoleMethods.module_eval do
|
|
71
|
+
def app = Roda.subclasses[0].app
|
|
72
|
+
end
|
|
73
|
+
@rack_test_installed = true
|
|
74
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
|
75
|
+
end
|
|
82
76
|
else
|
|
83
77
|
config_options.run_initializers! context: :console
|
|
84
78
|
end
|
|
@@ -92,13 +86,21 @@ module Bridgetown
|
|
|
92
86
|
workspace.main.define_singleton_method(:site) { Bridgetown::Current.site }
|
|
93
87
|
workspace.main.define_singleton_method(:collections) { site.collections }
|
|
94
88
|
workspace.main.define_singleton_method(:helpers) do
|
|
95
|
-
Bridgetown::
|
|
89
|
+
Bridgetown::TemplateView::Helpers.new
|
|
96
90
|
end
|
|
97
91
|
irb = IRB::Irb.new(workspace)
|
|
98
92
|
IRB.conf[:IRB_RC]&.call(irb.context)
|
|
99
93
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
|
100
94
|
irb.context.io.load_history if new_history_behavior
|
|
101
|
-
Bridgetown.logger.info "Console:", "Your site is now available as #{"site".cyan}"
|
|
95
|
+
Bridgetown.logger.info "Console:", "Your site is now available as #{"site".cyan}."
|
|
96
|
+
if options[:server_config]
|
|
97
|
+
Bridgetown.logger.info "",
|
|
98
|
+
"Your Roda app is available as #{Roda.subclasses[0].to_s.cyan}."
|
|
99
|
+
if @rack_test_installed
|
|
100
|
+
Bridgetown.logger.info "", "You can use #{"Rack::Test".magenta} methods like #{"get".cyan}, #{"post".cyan}, and #{"last_response".cyan} to inspect" # rubocop:disable Layout/LineLength
|
|
101
|
+
Bridgetown.logger.info "", " static & dynamic routes in your application."
|
|
102
|
+
end
|
|
103
|
+
end
|
|
102
104
|
Bridgetown.logger.info "",
|
|
103
105
|
"You can also access #{"collections".cyan} or perform a " \
|
|
104
106
|
"#{"reload!".cyan}"
|
|
@@ -109,7 +111,7 @@ module Bridgetown
|
|
|
109
111
|
|
|
110
112
|
begin
|
|
111
113
|
catch(:IRB_EXIT) do
|
|
112
|
-
unless options[:
|
|
114
|
+
unless options[:bypass_ap]
|
|
113
115
|
AmazingPrint.defaults = {
|
|
114
116
|
indent: 2,
|
|
115
117
|
}
|
|
@@ -123,5 +125,7 @@ module Bridgetown
|
|
|
123
125
|
end
|
|
124
126
|
end
|
|
125
127
|
end
|
|
128
|
+
|
|
129
|
+
register_command :console, Console
|
|
126
130
|
end
|
|
127
131
|
end
|
|
@@ -2,30 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
4
|
module Commands
|
|
5
|
-
class Esbuild <
|
|
6
|
-
include
|
|
7
|
-
extend Summarizable
|
|
5
|
+
class Esbuild < Bridgetown::Command
|
|
6
|
+
include Automations
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
register(Esbuild, "esbuild", "esbuild ACTION", Esbuild.summary)
|
|
11
|
-
end
|
|
8
|
+
self.description = "Perform actions on the Bridgetown esbuild configuration"
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
"bridgetown esbuild ACTION"
|
|
15
|
-
end
|
|
16
|
-
summary "Perform actions on the Bridgetown esbuild configuration"
|
|
10
|
+
one :command, "setup, update, migrate-from-webpack"
|
|
17
11
|
|
|
18
12
|
def self.exit_on_failure?
|
|
19
13
|
true
|
|
20
14
|
end
|
|
21
15
|
|
|
22
|
-
def
|
|
16
|
+
def call(new_site_dir: nil)
|
|
23
17
|
@logger = Bridgetown.logger
|
|
24
|
-
return show_actions
|
|
18
|
+
return show_actions unless command
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
self.source_paths = [File.expand_path("../commands/esbuild", __dir__)]
|
|
21
|
+
self.destination_root = new_site_dir || config.root_dir
|
|
22
|
+
|
|
23
|
+
if supported_actions.include?(command.to_sym)
|
|
24
|
+
perform command
|
|
29
25
|
else
|
|
30
26
|
@logger.error "Error:".red, "🚨 Please enter a valid action."
|
|
31
27
|
say "\n"
|
|
@@ -33,14 +29,6 @@ module Bridgetown
|
|
|
33
29
|
end
|
|
34
30
|
end
|
|
35
31
|
|
|
36
|
-
def self.source_root
|
|
37
|
-
File.expand_path("./esbuild", __dir__)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def self.destination_root
|
|
41
|
-
config.root_dir
|
|
42
|
-
end
|
|
43
|
-
|
|
44
32
|
protected
|
|
45
33
|
|
|
46
34
|
def config
|
|
@@ -56,7 +44,7 @@ module Bridgetown
|
|
|
56
44
|
|
|
57
45
|
def perform(action)
|
|
58
46
|
automation = find_in_source_paths("#{action}.rb")
|
|
59
|
-
inside(
|
|
47
|
+
inside(destination_root) do
|
|
60
48
|
apply automation, verbose: false
|
|
61
49
|
end
|
|
62
50
|
end
|
|
@@ -79,5 +67,7 @@ module Bridgetown
|
|
|
79
67
|
}
|
|
80
68
|
end
|
|
81
69
|
end
|
|
70
|
+
|
|
71
|
+
register_command :esbuild, Esbuild
|
|
82
72
|
end
|
|
83
73
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bridgetown
|
|
4
|
+
module Commands
|
|
5
|
+
class Help < Bridgetown::Command
|
|
6
|
+
self.description = "Show detailed command usage information and exit"
|
|
7
|
+
|
|
8
|
+
one :command, "The name of a Bridgetown command", required: true
|
|
9
|
+
|
|
10
|
+
def call
|
|
11
|
+
found_command = parent.class.table[:command].commands[command]
|
|
12
|
+
|
|
13
|
+
found_command&.new(name: command)&.print_usage
|
|
14
|
+
|
|
15
|
+
return if found_command
|
|
16
|
+
|
|
17
|
+
puts "Unknown command: #{command}\n\n"
|
|
18
|
+
parent.print_usage
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
register_command :help, Help
|
|
23
|
+
end
|
|
24
|
+
end
|