bridgetown-core 0.21.0.beta2 → 0.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bridgetown-core.gemspec +0 -1
- data/lib/bridgetown-core.rb +16 -15
- data/lib/bridgetown-core/cleaner.rb +2 -2
- data/lib/bridgetown-core/collection.rb +13 -8
- data/lib/bridgetown-core/commands/concerns/build_options.rb +2 -2
- data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
- data/lib/bridgetown-core/commands/configure.rb +4 -3
- data/lib/bridgetown-core/commands/new.rb +6 -6
- data/lib/bridgetown-core/commands/plugins.rb +14 -13
- data/lib/bridgetown-core/commands/serve.rb +1 -1
- data/lib/bridgetown-core/commands/webpack.rb +82 -0
- data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +12 -0
- data/lib/bridgetown-core/commands/webpack/setup.rb +4 -0
- data/lib/bridgetown-core/commands/webpack/update.rb +24 -0
- data/lib/bridgetown-core/commands/webpack/webpack.config.js +31 -0
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +130 -0
- data/lib/bridgetown-core/component.rb +36 -31
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +2 -2
- data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +18 -7
- data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
- data/lib/bridgetown-core/concerns/site/processable.rb +5 -4
- data/lib/bridgetown-core/concerns/validatable.rb +1 -1
- data/lib/bridgetown-core/configuration.rb +12 -5
- data/lib/bridgetown-core/configurations/bt-postcss.rb +6 -6
- data/lib/bridgetown-core/configurations/netlify.rb +1 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +14 -9
- data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +2 -2
- data/lib/bridgetown-core/converters/erb_templates.rb +1 -1
- data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
- data/lib/bridgetown-core/core_ext/psych.rb +19 -0
- data/lib/bridgetown-core/document.rb +2 -2
- data/lib/bridgetown-core/drops/resource_drop.rb +2 -1
- data/lib/bridgetown-core/drops/site_drop.rb +2 -0
- data/lib/bridgetown-core/entry_filter.rb +5 -3
- data/lib/bridgetown-core/filters/url_filters.rb +4 -8
- data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +25 -4
- data/lib/bridgetown-core/layout.rb +27 -10
- data/lib/bridgetown-core/model/repo_origin.rb +1 -1
- data/lib/bridgetown-core/publisher.rb +2 -2
- data/lib/bridgetown-core/reader.rb +1 -1
- data/lib/bridgetown-core/readers/data_reader.rb +1 -1
- data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
- data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
- data/lib/bridgetown-core/regenerator.rb +1 -1
- data/lib/bridgetown-core/related_posts.rb +5 -2
- data/lib/bridgetown-core/resource/base.rb +29 -7
- data/lib/bridgetown-core/resource/destination.rb +3 -1
- data/lib/bridgetown-core/resource/permalink_processor.rb +7 -3
- data/lib/bridgetown-core/resource/transformer.rb +4 -2
- data/lib/bridgetown-core/site.rb +4 -5
- data/lib/bridgetown-core/static_file.rb +3 -2
- data/lib/bridgetown-core/tags/highlight.rb +2 -15
- data/lib/bridgetown-core/utils.rb +1 -1
- data/lib/bridgetown-core/version.rb +1 -1
- data/lib/bridgetown-core/watcher.rb +1 -0
- data/lib/bridgetown-core/yaml_parser.rb +22 -0
- data/lib/site_template/bridgetown.config.yml +5 -1
- data/lib/site_template/config/.keep +0 -0
- data/lib/site_template/package.json.erb +8 -11
- data/lib/site_template/plugins/site_builder.rb +1 -1
- data/lib/site_template/src/_data/site_metadata.yml +1 -1
- metadata +12 -17
- data/lib/site_template/webpack.config.js.erb +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3ba931e1d2393d0b13861c33e41c465a4e422baac0f9a68e39699b8159a2c5c
|
4
|
+
data.tar.gz: ff03f8af4f51257689ec84b0b661b0ba22ceb16a9110c5715aab56645020219c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82407b17c101d072436853bb2892108b544d91d2667dbdef36696d674ce3af18a123920f0e33dd3acce352bf7ad48c9df162c03aba977d7dad2a23ad1dfbc20e
|
7
|
+
data.tar.gz: 6c6c47fbf536cf3e3104040ce480be88183b60df5220845fe8a163af32de700b9f358c9d2bf58d19985da42d66e4005765c3d47a5e3c29def6039f77a640447b
|
data/bridgetown-core.gemspec
CHANGED
@@ -47,7 +47,6 @@ Gem::Specification.new do |s|
|
|
47
47
|
s.add_runtime_dependency("liquid-component", ">= 0.1")
|
48
48
|
s.add_runtime_dependency("listen", "~> 3.0")
|
49
49
|
s.add_runtime_dependency("rouge", "~> 3.0")
|
50
|
-
s.add_runtime_dependency("safe_yaml", "~> 1.0")
|
51
50
|
s.add_runtime_dependency("terminal-table", "~> 1.8")
|
52
51
|
s.add_runtime_dependency("thor", "~> 1.1")
|
53
52
|
s.add_runtime_dependency("tilt", "~> 2.0")
|
data/lib/bridgetown-core.rb
CHANGED
@@ -28,6 +28,7 @@ require "logger"
|
|
28
28
|
require "set"
|
29
29
|
require "csv"
|
30
30
|
require "json"
|
31
|
+
require "yaml"
|
31
32
|
|
32
33
|
# 3rd party
|
33
34
|
require "active_support"
|
@@ -44,7 +45,6 @@ require "active_support/current_attributes"
|
|
44
45
|
require "active_support/descendants_tracker"
|
45
46
|
require "hash_with_dot_access"
|
46
47
|
require "addressable/uri"
|
47
|
-
require "safe_yaml/load"
|
48
48
|
require "liquid"
|
49
49
|
require "liquid-component"
|
50
50
|
require "kramdown"
|
@@ -62,21 +62,8 @@ module HashWithDotAccess
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
SafeYAML::OPTIONS[:suppress_warnings] = true
|
66
|
-
|
67
65
|
# Create our little String subclass for Ruby Front Matter
|
68
66
|
class Rb < String; end
|
69
|
-
SafeYAML::OPTIONS[:whitelisted_tags] = ["!ruby/string:Rb"]
|
70
|
-
|
71
|
-
if RUBY_VERSION.start_with?("3.0")
|
72
|
-
# workaround for Ruby 3 preview 2, maybe can remove later
|
73
|
-
# rubocop:disable Style/GlobalVars
|
74
|
-
old_verbose = $VERBOSE
|
75
|
-
$VERBOSE = nil
|
76
|
-
SafeYAML::SafeToRubyVisitor.const_set(:INITIALIZE_ARITY, 2)
|
77
|
-
$verbose = old_verbose
|
78
|
-
# rubocop:enable Style/GlobalVars
|
79
|
-
end
|
80
67
|
|
81
68
|
module Bridgetown
|
82
69
|
autoload :Cleaner, "bridgetown-core/cleaner"
|
@@ -128,6 +115,7 @@ module Bridgetown
|
|
128
115
|
autoload :Validatable, "bridgetown-core/concerns/validatable"
|
129
116
|
autoload :VERSION, "bridgetown-core/version"
|
130
117
|
autoload :Watcher, "bridgetown-core/watcher"
|
118
|
+
autoload :YAMLParser, "bridgetown-core/yaml_parser"
|
131
119
|
|
132
120
|
# extensions
|
133
121
|
require "bridgetown-core/commands/registrations"
|
@@ -145,6 +133,7 @@ module Bridgetown
|
|
145
133
|
require_all "bridgetown-core/drops"
|
146
134
|
require_all "bridgetown-core/generators"
|
147
135
|
require_all "bridgetown-core/tags"
|
136
|
+
require_all "bridgetown-core/core_ext"
|
148
137
|
|
149
138
|
class << self
|
150
139
|
# Tells you which Bridgetown environment you are building in so
|
@@ -268,9 +257,21 @@ end
|
|
268
257
|
|
269
258
|
module Bridgetown
|
270
259
|
module Model; end
|
271
|
-
module Resource
|
260
|
+
module Resource
|
261
|
+
def self.register_extension(mod)
|
262
|
+
if mod.const_defined?(:LiquidResource)
|
263
|
+
Bridgetown::Drops::ResourceDrop.include mod.const_get(:LiquidResource)
|
264
|
+
end
|
265
|
+
if mod.const_defined?(:RubyResource)
|
266
|
+
Bridgetown::Resource::Base.include mod.const_get(:RubyResource)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
272
270
|
end
|
273
271
|
|
272
|
+
# This method is available in Ruby 3, monkey patching for older versions
|
273
|
+
Psych.extend Bridgetown::CoreExt::Psych::SafeLoadFile unless Psych.respond_to?(:safe_load_file)
|
274
|
+
|
274
275
|
loader = Zeitwerk::Loader.new
|
275
276
|
loader.push_dir File.join(__dir__, "bridgetown-core/model"), namespace: Bridgetown::Model
|
276
277
|
loader.push_dir File.join(__dir__, "bridgetown-core/resource"), namespace: Bridgetown::Resource
|
@@ -101,7 +101,7 @@ module Bridgetown
|
|
101
101
|
#
|
102
102
|
# Returns a Set with the directory paths
|
103
103
|
def keep_dirs
|
104
|
-
site.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
|
104
|
+
site.config.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
|
105
105
|
end
|
106
106
|
|
107
107
|
# Private: Creates a regular expression from the config's keep_files array
|
@@ -112,7 +112,7 @@ module Bridgetown
|
|
112
112
|
#
|
113
113
|
# Returns the regular expression
|
114
114
|
def keep_file_regex
|
115
|
-
%r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.keep_files).source})!
|
115
|
+
%r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.config.keep_files).source})!
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -242,7 +242,7 @@ module Bridgetown
|
|
242
242
|
site.config.collections[label] || HashWithDotAccess::Hash.new
|
243
243
|
end
|
244
244
|
|
245
|
-
def merge_data_resources
|
245
|
+
def merge_data_resources # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
246
246
|
data_contents = {}
|
247
247
|
|
248
248
|
sanitize_filename = ->(name) do
|
@@ -256,11 +256,16 @@ module Bridgetown
|
|
256
256
|
segments.each_with_index do |segment, index|
|
257
257
|
sanitized_segment = sanitize_filename.(File.basename(segment, ".*"))
|
258
258
|
hsh = nested.empty? ? data_contents : data_contents.dig(*nested)
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
259
|
+
if !hsh.is_a?(Hash)
|
260
|
+
Bridgetown.logger.error(
|
261
|
+
"Error:",
|
262
|
+
"#{nested.join("/")} is not a Hash structure, #{segment} cannot be read"
|
263
|
+
)
|
264
|
+
elsif index == segments.length - 1
|
265
|
+
hsh[sanitized_segment] = data_resource.data.rows || data_resource.data
|
266
|
+
elsif !hsh.key?(sanitized_segment)
|
267
|
+
hsh[sanitized_segment] = {}
|
268
|
+
end
|
264
269
|
nested << sanitized_segment
|
265
270
|
end
|
266
271
|
end
|
@@ -287,7 +292,7 @@ module Bridgetown
|
|
287
292
|
Pathname(full_path).relative_path_from(Pathname(site.source)).to_s
|
288
293
|
)
|
289
294
|
resource = Bridgetown::Model::Base.find(id).to_resource.read!
|
290
|
-
resources << resource if site.unpublished || resource.published?
|
295
|
+
resources << resource if site.config.unpublished || resource.published?
|
291
296
|
end
|
292
297
|
|
293
298
|
private
|
@@ -298,7 +303,7 @@ module Bridgetown
|
|
298
303
|
|
299
304
|
def read_document(full_path)
|
300
305
|
doc = Document.new(full_path, site: site, collection: self).tap(&:read)
|
301
|
-
docs << doc if site.unpublished || doc.published?
|
306
|
+
docs << doc if site.config.unpublished || doc.published?
|
302
307
|
end
|
303
308
|
|
304
309
|
def sort_docs!
|
@@ -36,9 +36,9 @@ module Bridgetown
|
|
36
36
|
klass.class_option :limit_posts,
|
37
37
|
type: :numeric,
|
38
38
|
desc: "Limits the number of posts to parse and publish"
|
39
|
-
klass.class_option :
|
39
|
+
klass.class_option :base_path,
|
40
40
|
aliases: "-b",
|
41
|
-
desc: "Serve the website from the given base
|
41
|
+
desc: "Serve the website from the given base path"
|
42
42
|
klass.class_option :force_polling,
|
43
43
|
type: :boolean,
|
44
44
|
desc: "Force watch to use polling"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Commands
|
5
|
+
module GitHelpers
|
6
|
+
def initialize_new_repo
|
7
|
+
run "git init", abort_on_failure: true
|
8
|
+
`git symbolic-ref HEAD refs/heads/main` if user_default_branch.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy_existing_repo
|
12
|
+
run "rm -rf .git"
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_default_branch
|
16
|
+
@user_default_branch ||= `git config init.defaultbranch`.strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,6 +4,7 @@ module Bridgetown
|
|
4
4
|
module Commands
|
5
5
|
class Configure < Thor::Group
|
6
6
|
include Thor::Actions
|
7
|
+
include Actions
|
7
8
|
extend Summarizable
|
8
9
|
|
9
10
|
Registrations.register do
|
@@ -20,13 +21,13 @@ module Bridgetown
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def perform_configurations
|
23
|
-
logger = Bridgetown.logger
|
24
|
+
@logger = Bridgetown.logger
|
24
25
|
list_configurations if args.empty?
|
25
26
|
|
26
27
|
args.each do |configuration|
|
27
28
|
configure configuration
|
28
29
|
rescue Thor::Error
|
29
|
-
logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
|
30
|
+
@logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -40,7 +41,7 @@ module Bridgetown
|
|
40
41
|
configuration_file = find_in_source_paths("#{configuration}.rb")
|
41
42
|
|
42
43
|
inside(New.created_site_dir || Dir.pwd) do
|
43
|
-
|
44
|
+
apply configuration_file, verbose: false
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -4,6 +4,7 @@ module Bridgetown
|
|
4
4
|
module Commands
|
5
5
|
class New < Thor::Group
|
6
6
|
include Thor::Actions
|
7
|
+
include GitHelpers
|
7
8
|
extend Summarizable
|
8
9
|
|
9
10
|
Registrations.register do
|
@@ -85,10 +86,10 @@ module Bridgetown
|
|
85
86
|
)
|
86
87
|
template("Gemfile.erb", "Gemfile")
|
87
88
|
template("package.json.erb", "package.json")
|
88
|
-
template("webpack.config.js.erb", "webpack.config.js")
|
89
89
|
template("frontend/javascript/index.js.erb", "frontend/javascript/index.js")
|
90
90
|
|
91
91
|
options["use-postcss"] ? configure_postcss : configure_sass
|
92
|
+
invoke(Webpack, ["setup"], {})
|
92
93
|
end
|
93
94
|
|
94
95
|
def configure_sass
|
@@ -139,7 +140,7 @@ module Bridgetown
|
|
139
140
|
# rubocop:enable Metrics/PerceivedComplexity
|
140
141
|
|
141
142
|
def bundle_install(path)
|
142
|
-
unless Bridgetown.environment
|
143
|
+
unless Bridgetown.environment.test?
|
143
144
|
require "bundler"
|
144
145
|
Bridgetown.with_unbundled_env do
|
145
146
|
inside(path) do
|
@@ -155,10 +156,9 @@ module Bridgetown
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def git_init(path)
|
158
|
-
unless Bridgetown.environment
|
159
|
+
unless Bridgetown.environment.test?
|
159
160
|
inside(path) do
|
160
|
-
|
161
|
-
run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
|
161
|
+
initialize_new_repo
|
162
162
|
end
|
163
163
|
end
|
164
164
|
rescue SystemExit
|
@@ -166,7 +166,7 @@ module Bridgetown
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def yarn_install(path)
|
169
|
-
unless Bridgetown.environment
|
169
|
+
unless Bridgetown.environment.test?
|
170
170
|
inside(path) do
|
171
171
|
run "yarn install", abort_on_failure: true
|
172
172
|
end
|
@@ -5,6 +5,7 @@ module Bridgetown
|
|
5
5
|
class Plugins < Thor
|
6
6
|
include Thor::Actions
|
7
7
|
include ConfigurationOverridable
|
8
|
+
include GitHelpers
|
8
9
|
|
9
10
|
Registrations.register do
|
10
11
|
desc "plugins <command>", "List installed plugins or access plugin content"
|
@@ -144,15 +145,15 @@ module Bridgetown
|
|
144
145
|
name = folder_name.dasherize
|
145
146
|
module_name = folder_name.camelize
|
146
147
|
|
147
|
-
|
148
|
+
# TODO: upon 0.21 release, remove the explicit branch name!
|
149
|
+
run "git clone -b switch-to-minitest https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
|
148
150
|
new_gemspec = "#{name}.gemspec"
|
149
151
|
|
150
152
|
inside name do # rubocop:todo Metrics/BlockLength
|
151
|
-
|
152
|
-
|
153
|
-
run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
|
153
|
+
destroy_existing_repo
|
154
|
+
initialize_new_repo
|
154
155
|
|
155
|
-
|
156
|
+
FileUtils.mv "bridgetown-sample-plugin.gemspec", new_gemspec.to_s
|
156
157
|
gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
|
157
158
|
gsub_file new_gemspec, "bridgetown-sample-plugin", name
|
158
159
|
gsub_file new_gemspec, "sample-plugin", name
|
@@ -161,21 +162,21 @@ module Bridgetown
|
|
161
162
|
gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
|
162
163
|
gsub_file "package.json", "bridgetown-sample-plugin", name
|
163
164
|
|
164
|
-
|
165
|
+
FileUtils.mv "lib/sample-plugin.rb", "lib/#{name}.rb"
|
165
166
|
gsub_file "lib/#{name}.rb", "sample-plugin", name
|
166
167
|
gsub_file "lib/#{name}.rb", "SamplePlugin", module_name
|
167
168
|
|
168
|
-
|
169
|
+
FileUtils.mv "lib/sample-plugin", "lib/#{name}"
|
169
170
|
gsub_file "lib/#{name}/builder.rb", "SamplePlugin", module_name
|
170
171
|
gsub_file "lib/#{name}/version.rb", "SamplePlugin", module_name
|
171
172
|
|
172
|
-
|
173
|
-
gsub_file "
|
174
|
-
gsub_file "
|
173
|
+
FileUtils.mv "test/test_sample_plugin.rb", "test/test_#{folder_name}.rb"
|
174
|
+
gsub_file "test/test_#{folder_name}.rb", "SamplePlugin", module_name
|
175
|
+
gsub_file "test/helper.rb", "sample-plugin", name
|
175
176
|
|
176
|
-
|
177
|
-
|
178
|
-
|
177
|
+
FileUtils.mv "components/sample_plugin", "components/#{folder_name}"
|
178
|
+
FileUtils.mv "content/sample_plugin", "content/#{folder_name}"
|
179
|
+
FileUtils.mv "layouts/sample_plugin", "layouts/#{folder_name}"
|
179
180
|
|
180
181
|
gsub_file "layouts/#{folder_name}/layout.html", "sample_plugin", folder_name
|
181
182
|
gsub_file "content/#{folder_name}/example_page.md", "sample_plugin", folder_name
|
@@ -119,7 +119,7 @@ module Bridgetown
|
|
119
119
|
|
120
120
|
def start_up_webrick(opts, destination)
|
121
121
|
@server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
|
122
|
-
@server.mount(opts["
|
122
|
+
@server.mount(opts["base_path"].to_s, Servlet, destination, file_handler_opts)
|
123
123
|
|
124
124
|
Bridgetown.logger.info "Server address:", server_address(@server, opts)
|
125
125
|
launch_browser @server, opts if opts["open_url"]
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Commands
|
5
|
+
class Webpack < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
extend Summarizable
|
8
|
+
|
9
|
+
Registrations.register do
|
10
|
+
register(Webpack, "webpack", "webpack ACTION", Webpack.summary)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.banner
|
14
|
+
"bridgetown webpack ACTION"
|
15
|
+
end
|
16
|
+
summary "Perform actions on the bridgetown webpack configuration"
|
17
|
+
|
18
|
+
def self.exit_on_failure?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def webpack
|
23
|
+
@logger = Bridgetown.logger
|
24
|
+
return show_actions if args.empty?
|
25
|
+
|
26
|
+
action = args.first
|
27
|
+
if supported_actions.include?(action)
|
28
|
+
perform action
|
29
|
+
else
|
30
|
+
@logger.error "Error:".red, "🚨 Please enter a valid action."
|
31
|
+
say "\n"
|
32
|
+
show_actions
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.source_root
|
37
|
+
File.expand_path("./webpack", __dir__)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.destination_root
|
41
|
+
config.root_dir
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def config
|
47
|
+
@config ||= Bridgetown.configuration({ root_dir: Dir.pwd })
|
48
|
+
end
|
49
|
+
|
50
|
+
def package_json
|
51
|
+
@package_json ||= begin
|
52
|
+
package_json_file = File.read(Bridgetown.sanitized_path(config.root_dir, "package.json"))
|
53
|
+
JSON.parse(package_json_file)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def perform(action)
|
58
|
+
automation = find_in_source_paths("#{action}.rb")
|
59
|
+
inside(New.created_site_dir || Dir.pwd) do
|
60
|
+
apply automation, verbose: false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_actions
|
65
|
+
say "Available actions:\n".bold
|
66
|
+
|
67
|
+
longest_action = supported_actions.keys.max_by(&:size).size
|
68
|
+
supported_actions.each do |action, description|
|
69
|
+
say action.ljust(longest_action).to_s.bold.blue + "\t" + "# #{description}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def supported_actions
|
74
|
+
{
|
75
|
+
setup: "Sets up a webpack integration with Bridgetown in your project",
|
76
|
+
update: "Updates the Bridgetown webpack defaults to the latest available version",
|
77
|
+
"enable-postcss": "Configures PostCSS in your project",
|
78
|
+
}.with_indifferent_access
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
default_postcss_config = File.expand_path("../../../site_template/postcss.config.js.erb", __dir__)
|
4
|
+
|
5
|
+
template default_postcss_config, "postcss.config.js"
|
6
|
+
template "webpack.defaults.js.erb", "config/webpack.defaults.js", force: true
|
7
|
+
|
8
|
+
unless Bridgetown.environment.test?
|
9
|
+
packages = %w(postcss@8.3.0 postcss-loader@4.3.0 postcss-flexbugs-fixes postcss-preset-env)
|
10
|
+
run "yarn add -D #{packages.join(" ")}"
|
11
|
+
run "yarn remove sass sass-loader"
|
12
|
+
end
|