bridgetown-core 1.3.4 → 2.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -1
- data/bin/bridgetown +0 -6
- data/bin/bt +6 -0
- data/bridgetown-core.gemspec +10 -7
- data/lib/bridgetown-core/cleaner.rb +1 -1
- data/lib/bridgetown-core/collection.rb +37 -18
- data/lib/bridgetown-core/commands/build.rb +9 -22
- data/lib/bridgetown-core/commands/concerns/actions.rb +15 -8
- data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +1 -1
- data/lib/bridgetown-core/commands/console.rb +3 -0
- data/lib/bridgetown-core/commands/doctor.rb +2 -4
- data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +1 -1
- data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
- data/lib/bridgetown-core/commands/esbuild/update.rb +2 -2
- data/lib/bridgetown-core/commands/esbuild.rb +3 -3
- data/lib/bridgetown-core/commands/new.rb +32 -39
- data/lib/bridgetown-core/commands/start.rb +76 -60
- data/lib/bridgetown-core/component.rb +19 -13
- data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
- data/lib/bridgetown-core/concerns/prioritizable.rb +11 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +7 -18
- data/lib/bridgetown-core/concerns/site/content.rb +10 -9
- data/lib/bridgetown-core/concerns/site/extensible.rb +4 -6
- data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +161 -0
- data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
- data/lib/bridgetown-core/concerns/site/renderable.rb +31 -7
- data/lib/bridgetown-core/concerns/site/ssr.rb +23 -9
- data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
- data/lib/bridgetown-core/concerns/transformable.rb +3 -5
- data/lib/bridgetown-core/configuration/configuration_dsl.rb +23 -14
- data/lib/bridgetown-core/configuration.rb +67 -114
- data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -2
- data/lib/bridgetown-core/configurations/cypress/cypress_tasks +2 -2
- data/lib/bridgetown-core/configurations/cypress.rb +1 -1
- data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +3 -3
- data/lib/bridgetown-core/configurations/is-land.rb +1 -1
- data/lib/bridgetown-core/configurations/lit.rb +1 -1
- data/lib/bridgetown-core/configurations/open-props.rb +1 -1
- data/lib/bridgetown-core/configurations/purgecss.rb +1 -1
- data/lib/bridgetown-core/configurations/ruby2js.rb +1 -1
- data/lib/bridgetown-core/configurations/shoelace.rb +8 -20
- data/lib/bridgetown-core/configurations/stimulus.rb +17 -36
- data/lib/bridgetown-core/configurations/turbo.rb +1 -2
- data/lib/bridgetown-core/converter.rb +38 -10
- data/lib/bridgetown-core/converters/erb_templates.rb +9 -26
- data/lib/bridgetown-core/converters/identity.rb +1 -1
- data/lib/bridgetown-core/converters/liquid_templates.rb +2 -20
- data/lib/bridgetown-core/converters/ruby_templates.rb +61 -3
- data/lib/bridgetown-core/converters/serbea_templates.rb +12 -24
- data/lib/bridgetown-core/current.rb +19 -17
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/drop.rb +3 -3
- data/lib/bridgetown-core/drops/relations_drop.rb +3 -2
- data/lib/bridgetown-core/drops/site_drop.rb +0 -5
- data/lib/bridgetown-core/entry_filter.rb +4 -6
- data/lib/bridgetown-core/errors.rb +2 -2
- data/lib/bridgetown-core/filters/from_liquid.rb +6 -10
- data/lib/bridgetown-core/filters/localization_filters.rb +1 -1
- data/lib/bridgetown-core/filters/translation_filters.rb +2 -2
- data/lib/bridgetown-core/filters.rb +3 -3
- data/lib/bridgetown-core/front_matter/defaults.rb +225 -0
- data/lib/bridgetown-core/front_matter/importer.rb +34 -0
- data/lib/bridgetown-core/front_matter/loaders/base.rb +29 -0
- data/lib/bridgetown-core/front_matter/loaders/ruby.rb +113 -0
- data/lib/bridgetown-core/front_matter/loaders/yaml.rb +42 -0
- data/lib/bridgetown-core/front_matter/loaders.rb +44 -0
- data/lib/bridgetown-core/{utils/ruby_front_matter.rb → front_matter/ruby.rb} +5 -5
- data/lib/bridgetown-core/front_matter.rb +11 -0
- data/lib/bridgetown-core/generated_page.rb +71 -31
- data/lib/bridgetown-core/generators/prototype_generator.rb +30 -18
- data/lib/bridgetown-core/helpers.rb +36 -47
- data/lib/bridgetown-core/hooks.rb +5 -5
- data/lib/bridgetown-core/inflector.rb +40 -0
- data/lib/bridgetown-core/kramdown/parser/gfm.rb +2 -2
- data/lib/bridgetown-core/layout.rb +3 -3
- data/lib/bridgetown-core/log_adapter.rb +12 -13
- data/lib/bridgetown-core/log_writer.rb +4 -4
- data/lib/bridgetown-core/model/base.rb +17 -17
- data/lib/bridgetown-core/model/builder_origin.rb +5 -3
- data/lib/bridgetown-core/model/origin.rb +1 -3
- data/lib/bridgetown-core/model/repo_origin.rb +12 -14
- data/lib/bridgetown-core/plugin.rb +0 -1
- data/lib/bridgetown-core/plugin_manager.rb +38 -84
- data/lib/bridgetown-core/rack/boot.rb +0 -15
- data/lib/bridgetown-core/rack/routes.rb +30 -90
- data/lib/bridgetown-core/reader.rb +6 -4
- data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +2 -2
- data/lib/bridgetown-core/resource/base.rb +112 -29
- data/lib/bridgetown-core/resource/destination.rb +1 -1
- data/lib/bridgetown-core/resource/relations.rb +11 -8
- data/lib/bridgetown-core/resource/taxonomy_type.rb +3 -1
- data/lib/bridgetown-core/resource/transformer.rb +4 -4
- data/lib/bridgetown-core/ruby_template_view.rb +44 -28
- data/lib/bridgetown-core/signals.rb +95 -0
- data/lib/bridgetown-core/site.rb +22 -4
- data/lib/bridgetown-core/slot.rb +5 -5
- data/lib/bridgetown-core/static_file.rb +5 -7
- data/lib/bridgetown-core/tags/asset_path.rb +11 -2
- data/lib/bridgetown-core/tags/find.rb +3 -5
- data/lib/bridgetown-core/tags/highlight.rb +3 -3
- data/lib/bridgetown-core/tags/post_url.rb +1 -1
- data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +2 -2
- data/lib/bridgetown-core/utils/aux.rb +41 -41
- data/lib/bridgetown-core/utils/loaders_manager.rb +2 -21
- data/lib/bridgetown-core/utils/ruby_exec.rb +17 -0
- data/lib/bridgetown-core/utils.rb +46 -110
- data/lib/bridgetown-core/watcher.rb +21 -10
- data/lib/bridgetown-core.rb +35 -49
- data/lib/roda/plugins/bridgetown_server.rb +54 -12
- data/lib/roda/plugins/bridgetown_ssr.rb +13 -2
- data/lib/roda/plugins/ssg.rb +72 -0
- data/lib/site_template/.gitignore +9 -3
- data/lib/site_template/Gemfile.erb +3 -3
- data/lib/site_template/README.md +3 -4
- data/lib/site_template/Rakefile.erb +2 -15
- data/lib/site_template/TEMPLATES/erb/_partials/_head.erb +2 -2
- data/lib/site_template/TEMPLATES/serbea/_partials/_head.serb +2 -2
- data/lib/site_template/config/initializers.rb +60 -22
- data/lib/site_template/config/puma.rb +2 -0
- data/lib/site_template/package.json.erb +2 -27
- data/lib/site_template/src/index.md.erb +3 -3
- data/lib/site_template/src/posts.md.erb +8 -8
- data/lib/site_template/tmp/pids/.keep +0 -0
- metadata +98 -64
- data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +0 -12
- data/lib/bridgetown-core/commands/webpack/setup.rb +0 -4
- data/lib/bridgetown-core/commands/webpack/update.rb +0 -24
- data/lib/bridgetown-core/commands/webpack/webpack.config.js +0 -31
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +0 -135
- data/lib/bridgetown-core/commands/webpack.rb +0 -82
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +0 -52
- data/lib/bridgetown-core/concerns/liquid_renderable.rb +0 -30
- data/lib/bridgetown-core/core_ext/psych.rb +0 -15
- data/lib/bridgetown-core/drops/url_drop.rb +0 -152
- data/lib/bridgetown-core/frontmatter_defaults.rb +0 -223
- data/lib/bridgetown-core/rack/static_indexes.rb +0 -31
- data/lib/bridgetown-core/url.rb +0 -166
- data/lib/bridgetown-core/utils/ansi.rb +0 -57
- data/lib/bridgetown-core/version.rb +0 -6
- data/lib/site_template/bridgetown.config.yml +0 -33
@@ -1,20 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_model"
|
4
|
-
|
5
3
|
module Bridgetown
|
6
4
|
module Model
|
7
5
|
class Base
|
8
|
-
include
|
9
|
-
extend ActiveModel::Callbacks # also extends with DescendantsTracker
|
10
|
-
define_model_callbacks :load, :save, :destroy
|
6
|
+
include Bridgetown::RodaCallable
|
11
7
|
|
12
8
|
class << self
|
13
9
|
def find(id, site: Bridgetown::Current.site)
|
14
10
|
raise "A Bridgetown site must be initialized and added to Current" unless site
|
15
11
|
|
16
|
-
origin = origin_for_id(id, site:
|
17
|
-
klass_for_id(id, origin:
|
12
|
+
origin = origin_for_id(id, site:)
|
13
|
+
klass_for_id(id, origin:).new(origin.read)
|
18
14
|
end
|
19
15
|
|
20
16
|
def origin_for_id(id, site: Bridgetown::Current.site)
|
@@ -25,12 +21,12 @@ module Bridgetown
|
|
25
21
|
|
26
22
|
raise "No origin could be found for #{id}" unless origin_klass
|
27
23
|
|
28
|
-
origin_klass.new(id, site:
|
24
|
+
origin_klass.new(id, site:)
|
29
25
|
end
|
30
26
|
|
31
27
|
def klass_for_id(id, origin: nil)
|
32
28
|
Bridgetown::Model::Base.descendants.find do |klass|
|
33
|
-
klass.will_load_id?(id, origin:
|
29
|
+
klass.will_load_id?(id, origin:)
|
34
30
|
end || Bridgetown::Model::Base
|
35
31
|
end
|
36
32
|
|
@@ -44,7 +40,7 @@ module Bridgetown
|
|
44
40
|
site = builder.site
|
45
41
|
data = Bridgetown::Model::BuilderOrigin.new(
|
46
42
|
Bridgetown::Model::BuilderOrigin.id_for_builder_path(builder, path),
|
47
|
-
site:
|
43
|
+
site:
|
48
44
|
).read do
|
49
45
|
data[:_collection_] = site.collections[collection_name]
|
50
46
|
data
|
@@ -54,9 +50,7 @@ module Bridgetown
|
|
54
50
|
end
|
55
51
|
|
56
52
|
def initialize(attributes = {})
|
57
|
-
|
58
|
-
super
|
59
|
-
end
|
53
|
+
self.attributes = attributes
|
60
54
|
end
|
61
55
|
|
62
56
|
def id
|
@@ -82,9 +76,7 @@ module Bridgetown
|
|
82
76
|
raise "`#{origin.class}' doesn't allow writing of model objects"
|
83
77
|
end
|
84
78
|
|
85
|
-
|
86
|
-
origin.write(self)
|
87
|
-
end
|
79
|
+
origin.write(self)
|
88
80
|
end
|
89
81
|
|
90
82
|
# @return [Bridgetown::Resource::Base]
|
@@ -102,6 +94,11 @@ module Bridgetown
|
|
102
94
|
to_resource.read!.transform!
|
103
95
|
end
|
104
96
|
|
97
|
+
# Converts this model to a resource and returns the full output
|
98
|
+
#
|
99
|
+
# @return [String]
|
100
|
+
def call(*) = render_as_resource.output
|
101
|
+
|
105
102
|
# override if need be
|
106
103
|
# @return [Bridgetown::Site]
|
107
104
|
def site
|
@@ -130,6 +127,10 @@ module Bridgetown
|
|
130
127
|
@attributes ||= HashWithDotAccess::Hash.new
|
131
128
|
end
|
132
129
|
|
130
|
+
def attributes=(new_attributes)
|
131
|
+
attributes.update new_attributes
|
132
|
+
end
|
133
|
+
|
133
134
|
# Strip out keys like _origin_, _collection_, etc.
|
134
135
|
# @return [HashWithDotAccess::Hash]
|
135
136
|
def data_attributes
|
@@ -146,7 +147,6 @@ module Bridgetown
|
|
146
147
|
key = method_name.to_s
|
147
148
|
if key.end_with?("=")
|
148
149
|
key.chop!
|
149
|
-
# attribute_will_change!(key)
|
150
150
|
attributes[key] = args.first
|
151
151
|
return attributes[key]
|
152
152
|
end
|
@@ -34,9 +34,11 @@ module Bridgetown
|
|
34
34
|
@data
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
37
|
+
def front_matter_line_count = @data[:_front_matter_line_count_]
|
38
|
+
|
39
|
+
def original_path = @data[:_original_path_] || relative_path
|
40
|
+
|
41
|
+
def exists? = false
|
40
42
|
|
41
43
|
def read_data_from_builder
|
42
44
|
builder = Kernel.const_get(url.host.gsub(".", "::"))
|
@@ -4,8 +4,6 @@ module Bridgetown
|
|
4
4
|
module Model
|
5
5
|
# Abstract Superclass
|
6
6
|
class Origin
|
7
|
-
extend ActiveSupport::DescendantsTracker
|
8
|
-
|
9
7
|
EAGER_LOAD_DESCENDANTS = %i(BuilderOrigin RepoOrigin PluginOrigin).freeze
|
10
8
|
|
11
9
|
# @return [String]
|
@@ -30,7 +28,7 @@ module Bridgetown
|
|
30
28
|
|
31
29
|
return klass.collection_name.to_s == collection_name if klass.respond_to?(:collection_name)
|
32
30
|
|
33
|
-
klass.name ==
|
31
|
+
klass.name == site.config.inflector.classify(collection_name)
|
34
32
|
end
|
35
33
|
|
36
34
|
def read
|
@@ -3,13 +3,8 @@
|
|
3
3
|
module Bridgetown
|
4
4
|
module Model
|
5
5
|
class RepoOrigin < Origin
|
6
|
-
|
7
|
-
include Bridgetown::
|
8
|
-
|
9
|
-
YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m.freeze
|
10
|
-
RUBY_FRONT_MATTER_HEADER = %r!\A[~`#-]{3,}(?:ruby|<%|{%)\s*\n!.freeze
|
11
|
-
RUBY_FRONT_MATTER_REGEXP =
|
12
|
-
%r!#{RUBY_FRONT_MATTER_HEADER.source}(.*?\n?)^((?:%>|%})?[~`#-]{3,}\s*$\n?)!m.freeze
|
6
|
+
using Bridgetown::Refinements
|
7
|
+
include Bridgetown::FrontMatter::Importer
|
13
8
|
|
14
9
|
# @return [String]
|
15
10
|
attr_accessor :content
|
@@ -35,7 +30,7 @@ module Bridgetown
|
|
35
30
|
def new_with_collection_path(collection, relative_path, site: Bridgetown::Current.site)
|
36
31
|
collection = collection.label if collection.is_a?(Bridgetown::Collection)
|
37
32
|
|
38
|
-
new("repo://#{collection}.collection/#{relative_path}", site:
|
33
|
+
new("repo://#{collection}.collection/#{relative_path}", site:)
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
@@ -88,11 +83,9 @@ module Bridgetown
|
|
88
83
|
def collection
|
89
84
|
return @collection if @collection
|
90
85
|
|
91
|
-
collection_name =
|
92
|
-
url.host.chomp(".collection")
|
93
|
-
else
|
86
|
+
collection_name = url.host.ends_with?(".collection") ?
|
87
|
+
url.host.chomp(".collection") :
|
94
88
|
"pages"
|
95
|
-
end
|
96
89
|
@collection = site.collections[collection_name]
|
97
90
|
end
|
98
91
|
|
@@ -107,7 +100,7 @@ module Bridgetown
|
|
107
100
|
private
|
108
101
|
|
109
102
|
def in_data_collection?
|
110
|
-
original_path.extname.downcase.
|
103
|
+
original_path.extname.downcase.within?(self.class.data_file_extensions) &&
|
111
104
|
collection.data?
|
112
105
|
end
|
113
106
|
|
@@ -129,7 +122,12 @@ module Bridgetown
|
|
129
122
|
encoding: site.config["encoding"]).map(&:to_hash),
|
130
123
|
}
|
131
124
|
when ".rb"
|
132
|
-
process_ruby_data(
|
125
|
+
Bridgetown::Utils::RubyExec.process_ruby_data(
|
126
|
+
self,
|
127
|
+
File.read(original_path),
|
128
|
+
original_path,
|
129
|
+
1
|
130
|
+
)
|
133
131
|
when ".json"
|
134
132
|
json_data = JSON.parse(File.read(original_path))
|
135
133
|
json_data.is_a?(Array) ? { rows: json_data } : json_data
|
@@ -2,44 +2,12 @@
|
|
2
2
|
|
3
3
|
module Bridgetown
|
4
4
|
class PluginManager
|
5
|
-
|
6
|
-
YARN_DEPENDENCY_REGEXP = %r!(.+)@([^@]*)$!.freeze
|
5
|
+
NPM_DEPENDENCY_REGEXP = %r!(.+)@([^@]*)$!
|
7
6
|
|
8
7
|
attr_reader :site, :loaders_manager
|
9
8
|
|
10
9
|
@registered_plugins = Set.new
|
11
10
|
|
12
|
-
# @param source_manifest [Bridgetown::Configuration::SourceManifest]
|
13
|
-
def self.add_source_manifest(source_manifest)
|
14
|
-
unless source_manifest.is_a?(Bridgetown::Configuration::SourceManifest)
|
15
|
-
raise "You must add a SourceManifest instance"
|
16
|
-
end
|
17
|
-
|
18
|
-
unless Bridgetown::Current.preloaded_configuration
|
19
|
-
raise "A preloaded configuration must be present before adding source manifests"
|
20
|
-
end
|
21
|
-
|
22
|
-
Bridgetown::Deprecator.deprecation_message(
|
23
|
-
"The #{source_manifest.origin} plugin should switch from using `add_source_manifest' to " \
|
24
|
-
"the `source_manifest` initializer method"
|
25
|
-
)
|
26
|
-
|
27
|
-
Bridgetown::Current.preloaded_configuration.source_manifests << source_manifest
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.new_source_manifest(*_args, **kwargs)
|
31
|
-
unless Bridgetown::Current.preloaded_configuration
|
32
|
-
raise "A preloaded configuration must be present before adding source manifests"
|
33
|
-
end
|
34
|
-
|
35
|
-
Bridgetown::Deprecator.deprecation_message(
|
36
|
-
"The #{kwargs[:origin]} plugin should switch from using `new_source_manifest' to the " \
|
37
|
-
"`source_manifest` initializer method"
|
38
|
-
)
|
39
|
-
|
40
|
-
add_source_manifest(Bridgetown::Configuration::SourceManifest.new(**kwargs))
|
41
|
-
end
|
42
|
-
|
43
11
|
def self.add_registered_plugin(gem_or_plugin_file)
|
44
12
|
@registered_plugins << gem_or_plugin_file
|
45
13
|
end
|
@@ -50,23 +18,16 @@ module Bridgetown
|
|
50
18
|
def bundler_specs
|
51
19
|
@bundler_specs ||= Bundler.load.requested_specs
|
52
20
|
end
|
53
|
-
|
54
|
-
def source_manifests
|
55
|
-
Bridgetown::Deprecator.deprecation_message(
|
56
|
-
"Use the configuration's `source_manifests` method instead of the plugin manager"
|
57
|
-
)
|
58
|
-
|
59
|
-
Bridgetown::Current.preloaded_configuration.source_manifests
|
60
|
-
end
|
61
21
|
end
|
62
22
|
|
63
|
-
def self.setup_bundler
|
23
|
+
def self.setup_bundler
|
64
24
|
if !ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] &&
|
65
25
|
(Bundler::SharedHelpers.in_bundle? || Bridgetown.env.test?)
|
66
26
|
require "bundler"
|
67
27
|
|
68
28
|
require_relative "utils/initializers"
|
69
|
-
load_determined_bundler_environment
|
29
|
+
load_determined_bundler_environment
|
30
|
+
require_plugin_features
|
70
31
|
|
71
32
|
ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] = "true"
|
72
33
|
true
|
@@ -78,7 +39,7 @@ module Bridgetown
|
|
78
39
|
alias_method :require_from_bundler, :setup_bundler
|
79
40
|
end
|
80
41
|
|
81
|
-
def self.load_determined_bundler_environment
|
42
|
+
def self.load_determined_bundler_environment
|
82
43
|
boot_file = File.join("config", "boot.rb")
|
83
44
|
|
84
45
|
if File.file?(boot_file)
|
@@ -89,15 +50,22 @@ module Bridgetown
|
|
89
50
|
# Note: the default Bundler config will set up all gem groups,
|
90
51
|
# see: https://bundler.io/guides/groups.html
|
91
52
|
Bundler.setup(:default, Bridgetown.env)
|
92
|
-
|
93
|
-
|
94
|
-
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.require_plugin_features
|
57
|
+
bundler_specs.select do |loaded_gem|
|
58
|
+
loaded_gem.to_spec.metadata["bridgetown_features"] == "true"
|
59
|
+
end.each do |plugin_gem|
|
60
|
+
Bridgetown::Utils::RequireGems.require_with_graceful_fail(
|
61
|
+
"bridgetown/features/#{plugin_gem.name}"
|
62
|
+
)
|
95
63
|
end
|
96
64
|
end
|
97
65
|
|
98
66
|
def self.require_gem(name)
|
99
67
|
Bridgetown::Utils::RequireGems.require_with_graceful_fail(name)
|
100
|
-
plugins = Bridgetown::PluginManager.
|
68
|
+
plugins = Bridgetown::PluginManager.install_npm_dependencies(name:)
|
101
69
|
|
102
70
|
plugin_to_register = if plugins.length == 1
|
103
71
|
plugins.first
|
@@ -112,28 +80,11 @@ module Bridgetown
|
|
112
80
|
"Registered #{plugin_to_register.name}")
|
113
81
|
end
|
114
82
|
|
115
|
-
def self.legacy_require
|
116
|
-
Bundler.require(LEGACY_PLUGINS_GROUP).select do |dep|
|
117
|
-
(dep.groups & [LEGACY_PLUGINS_GROUP]).any? && dep.should_include?
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.legacy_yarn_and_register(required_gems, skip_yarn: false)
|
122
|
-
install_yarn_dependencies(required_gems) unless skip_yarn
|
123
|
-
|
124
|
-
required_gems.each do |installed_gem|
|
125
|
-
add_registered_plugin installed_gem
|
126
|
-
end
|
127
|
-
|
128
|
-
Bridgetown.logger.debug("PluginManager:",
|
129
|
-
"Required #{required_gems.map(&:name).join(", ")}")
|
130
|
-
end
|
131
|
-
|
132
83
|
def self.package_manager
|
133
|
-
@package_manager ||= if File.exist?("
|
134
|
-
"yarn"
|
135
|
-
elsif File.exist?("package-lock.json")
|
84
|
+
@package_manager ||= if File.exist?("package-lock.json")
|
136
85
|
"npm"
|
86
|
+
elsif File.exist?("yarn.lock")
|
87
|
+
"yarn"
|
137
88
|
elsif File.exist?("pnpm-lock.yaml")
|
138
89
|
"pnpm"
|
139
90
|
else
|
@@ -147,11 +98,11 @@ module Bridgetown
|
|
147
98
|
|
148
99
|
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
149
100
|
|
150
|
-
# Iterates through loaded gems and finds
|
151
|
-
# If that exact package hasn't been installed, execute
|
101
|
+
# Iterates through loaded gems and finds npm-add gemspec metadata.
|
102
|
+
# If that exact package hasn't been installed, execute npm i
|
152
103
|
#
|
153
104
|
# @return [Bundler::SpecSet]
|
154
|
-
def self.
|
105
|
+
def self.install_npm_dependencies(required_gems = bundler_specs, name: nil)
|
155
106
|
return required_gems unless File.exist?("package.json")
|
156
107
|
|
157
108
|
package_json = JSON.parse(File.read("package.json"))
|
@@ -166,34 +117,37 @@ module Bridgetown
|
|
166
117
|
|
167
118
|
# all right, time to install the package
|
168
119
|
gems_to_search.each do |loaded_gem|
|
169
|
-
|
170
|
-
next unless
|
120
|
+
npm_dependency = find_npm_dependency(loaded_gem)
|
121
|
+
next unless add_npm_dependency?(npm_dependency, package_json)
|
171
122
|
|
172
123
|
next if package_manager.empty?
|
173
124
|
|
174
|
-
cmd = "#{package_manager} #{package_manager_install_command} #{
|
125
|
+
cmd = "#{package_manager} #{package_manager_install_command} #{npm_dependency.join("@")}"
|
175
126
|
system cmd
|
176
127
|
end
|
177
128
|
|
178
129
|
gems_to_search
|
179
130
|
end
|
180
131
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
return nil if
|
132
|
+
def self.find_npm_dependency(loaded_gem)
|
133
|
+
npm_metadata = loaded_gem.to_spec&.metadata&.dig("npm-add") ||
|
134
|
+
loaded_gem.to_spec&.metadata&.dig("yarn-add")
|
135
|
+
npm_dependency = npm_metadata&.match(NPM_DEPENDENCY_REGEXP)
|
136
|
+
return nil if npm_dependency&.length != 3 || npm_dependency[2] == ""
|
186
137
|
|
187
|
-
|
138
|
+
npm_dependency[1..2]
|
188
139
|
end
|
189
140
|
|
190
|
-
|
191
|
-
|
141
|
+
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
142
|
+
|
143
|
+
def self.add_npm_dependency?(npm_dependency, package_json)
|
144
|
+
return false if npm_dependency.nil?
|
192
145
|
|
193
146
|
# check matching version number is see if it's already installed
|
194
147
|
if package_json["dependencies"]
|
195
|
-
current_version = package_json["dependencies"][
|
196
|
-
|
148
|
+
current_version = package_json["dependencies"][npm_dependency.first]
|
149
|
+
current_version = current_version.delete_prefix("^") if current_version
|
150
|
+
package_requires_updating?(current_version, npm_dependency.last)
|
197
151
|
else
|
198
152
|
true
|
199
153
|
end
|
@@ -3,27 +3,14 @@
|
|
3
3
|
require "zeitwerk"
|
4
4
|
require "roda"
|
5
5
|
require "json"
|
6
|
-
require "roda/plugins/public"
|
7
6
|
|
8
7
|
Bridgetown::Current.preloaded_configuration ||= Bridgetown.configuration
|
9
8
|
|
10
9
|
require_relative "logger"
|
11
10
|
require_relative "routes"
|
12
|
-
require_relative "static_indexes"
|
13
11
|
|
14
12
|
module Bridgetown
|
15
13
|
module Rack
|
16
|
-
class Roda < ::Roda
|
17
|
-
def self.inherited(klass)
|
18
|
-
Bridgetown::Deprecator.deprecation_message(
|
19
|
-
"The `Bridgetown::Rack::Roda' class will be removed in favor of using the " \
|
20
|
-
"`bridgetown_server' plugin in a future version"
|
21
|
-
)
|
22
|
-
super
|
23
|
-
klass.plugin :bridgetown_server
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
14
|
class << self
|
28
15
|
# @return [Bridgetown::Utils::LoadersManager]
|
29
16
|
attr_accessor :loaders_manager
|
@@ -76,7 +63,6 @@ module Bridgetown
|
|
76
63
|
|
77
64
|
loader.reload
|
78
65
|
loader.eager_load
|
79
|
-
Bridgetown::Rack::Routes.reload_subclasses
|
80
66
|
rescue SyntaxError => e
|
81
67
|
Bridgetown::Errors.print_build_error(e)
|
82
68
|
end.start
|
@@ -89,7 +75,6 @@ module Bridgetown
|
|
89
75
|
next unless load_path == server_folder
|
90
76
|
|
91
77
|
loader.eager_load
|
92
|
-
Bridgetown::Rack::Routes.reload_subclasses
|
93
78
|
end
|
94
79
|
|
95
80
|
loaders_manager.setup_loaders([server_folder])
|
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
module Bridgetown
|
4
4
|
module Rack
|
5
|
-
@interrupted = false
|
6
|
-
|
7
|
-
class << self
|
8
|
-
attr_accessor :interrupted
|
9
|
-
end
|
10
|
-
|
11
5
|
class Routes
|
12
6
|
include Bridgetown::Prioritizable
|
13
7
|
|
@@ -34,7 +28,7 @@ module Bridgetown
|
|
34
28
|
end
|
35
29
|
puts
|
36
30
|
puts "Routes:"
|
37
|
-
puts "
|
31
|
+
puts "=======\n"
|
38
32
|
if routes.blank?
|
39
33
|
puts "No routes found. Have you commented all of your routes?"
|
40
34
|
puts "Documentation: https://github.com/jeremyevans/roda-route_list#basic-usage-"
|
@@ -51,9 +45,6 @@ module Bridgetown
|
|
51
45
|
end
|
52
46
|
# rubocop:enable Bridgetown/NoPutsAllowed, Metrics/MethodLength
|
53
47
|
|
54
|
-
# @return [Hash<String, Class(Routes)>]
|
55
|
-
attr_accessor :tracked_subclasses
|
56
|
-
|
57
48
|
# @return [Proc]
|
58
49
|
attr_accessor :router_block
|
59
50
|
|
@@ -65,30 +56,9 @@ module Bridgetown
|
|
65
56
|
"#{priorities[priority]}#{self}" <=> "#{priorities[other.priority]}#{other}"
|
66
57
|
end
|
67
58
|
|
68
|
-
# @param base [Class(Routes)]
|
69
|
-
def inherited(base)
|
70
|
-
Bridgetown::Rack::Routes.track_subclass base
|
71
|
-
super
|
72
|
-
end
|
73
|
-
|
74
|
-
# @param klass [Class(Routes)]
|
75
|
-
def track_subclass(klass)
|
76
|
-
Bridgetown::Rack::Routes.tracked_subclasses ||= {}
|
77
|
-
Bridgetown::Rack::Routes.tracked_subclasses[klass.name] = klass
|
78
|
-
end
|
79
|
-
|
80
59
|
# @return [Array<Class(Routes)>]
|
81
60
|
def sorted_subclasses
|
82
|
-
Bridgetown::Rack::Routes.
|
83
|
-
end
|
84
|
-
|
85
|
-
# @return [void]
|
86
|
-
def reload_subclasses
|
87
|
-
Bridgetown::Rack::Routes.tracked_subclasses&.each_key do |klassname|
|
88
|
-
Kernel.const_get(klassname)
|
89
|
-
rescue NameError
|
90
|
-
Bridgetown::Rack::Routes.tracked_subclasses.delete klassname
|
91
|
-
end
|
61
|
+
Bridgetown::Rack::Routes.descendants.sort
|
92
62
|
end
|
93
63
|
|
94
64
|
# Add a router block via the current Routes class
|
@@ -118,36 +88,11 @@ module Bridgetown
|
|
118
88
|
new(roda_app).handle_routes
|
119
89
|
end
|
120
90
|
|
121
|
-
#
|
122
|
-
# depending on if there's a site `base_path` configured
|
91
|
+
# Set up live reload if allowed, then run through all the Routes blocks.
|
123
92
|
#
|
124
93
|
# @param roda_app [Roda]
|
125
94
|
# @return [void]
|
126
|
-
def
|
127
|
-
if Bridgetown::Current.preloaded_configuration.base_path == "/"
|
128
|
-
load_all_routes roda_app
|
129
|
-
return
|
130
|
-
end
|
131
|
-
|
132
|
-
# Support custom base_path configurations
|
133
|
-
roda_app.request.on(
|
134
|
-
Bridgetown::Current.preloaded_configuration.base_path.delete_prefix("/")
|
135
|
-
) do
|
136
|
-
load_all_routes roda_app
|
137
|
-
end
|
138
|
-
|
139
|
-
nil
|
140
|
-
end
|
141
|
-
|
142
|
-
# Run the Roda public plugin first, set up live reload if allowed, then
|
143
|
-
# run through all the Routes blocks. If the file-based router plugin
|
144
|
-
# is available, kick off that request process next.
|
145
|
-
#
|
146
|
-
# @param roda_app [Roda]
|
147
|
-
# @return [void]
|
148
|
-
def load_all_routes(roda_app)
|
149
|
-
roda_app.request.public
|
150
|
-
|
95
|
+
def load_all(roda_app)
|
151
96
|
if Bridgetown.env.development? &&
|
152
97
|
!Bridgetown::Current.preloaded_configuration.skip_live_reload
|
153
98
|
setup_live_reload roda_app
|
@@ -160,33 +105,40 @@ module Bridgetown
|
|
160
105
|
|
161
106
|
# @param app [Roda]
|
162
107
|
def setup_live_reload(app) # rubocop:disable Metrics
|
163
|
-
sleep_interval = 0.
|
108
|
+
sleep_interval = 0.5
|
164
109
|
file_to_check = File.join(Bridgetown::Current.preloaded_configuration.destination,
|
165
110
|
"index.html")
|
166
111
|
errors_file = Bridgetown.build_errors_path
|
167
112
|
|
168
113
|
app.request.get "_bridgetown/live_reload" do
|
169
|
-
app.response["Content-Type"] = "text/event-stream"
|
170
|
-
|
171
114
|
@_mod = File.exist?(file_to_check) ? File.stat(file_to_check).mtime.to_i : 0
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
115
|
+
event_stream = proc do |stream|
|
116
|
+
Thread.new do
|
117
|
+
loop do
|
118
|
+
new_mod = File.exist?(file_to_check) ? File.stat(file_to_check).mtime.to_i : 0
|
119
|
+
|
120
|
+
if @_mod < new_mod
|
121
|
+
stream.write "data: reloaded!\n\n"
|
122
|
+
break
|
123
|
+
elsif File.exist?(errors_file)
|
124
|
+
stream.write "event: builderror\ndata: #{File.read(errors_file).to_json}\n\n"
|
125
|
+
else
|
126
|
+
stream.write "data: #{new_mod}\n\n"
|
127
|
+
end
|
128
|
+
|
129
|
+
sleep sleep_interval
|
130
|
+
rescue Errno::EPIPE # User refreshed the page
|
180
131
|
break
|
181
|
-
elsif File.exist?(errors_file)
|
182
|
-
out << "event: builderror\ndata: #{File.read(errors_file).to_json}\n\n"
|
183
|
-
else
|
184
|
-
out << "data: #{new_mod}\n\n"
|
185
132
|
end
|
186
|
-
|
187
|
-
|
133
|
+
ensure
|
134
|
+
stream.close
|
188
135
|
end
|
189
136
|
end
|
137
|
+
|
138
|
+
app.request.halt [200, {
|
139
|
+
"Content-Type" => "text/event-stream",
|
140
|
+
"cache-control" => "no-cache",
|
141
|
+
}, event_stream,]
|
190
142
|
end
|
191
143
|
end
|
192
144
|
end
|
@@ -205,9 +157,9 @@ module Bridgetown
|
|
205
157
|
end
|
206
158
|
|
207
159
|
# Any missing methods are passed along to the underlying Roda app if possible
|
208
|
-
def method_missing(method_name,
|
160
|
+
def method_missing(method_name, ...)
|
209
161
|
if @_roda_app.respond_to?(method_name.to_sym)
|
210
|
-
@_roda_app.send
|
162
|
+
@_roda_app.send(method_name.to_sym, ...)
|
211
163
|
else
|
212
164
|
super
|
213
165
|
end
|
@@ -219,15 +171,3 @@ module Bridgetown
|
|
219
171
|
end
|
220
172
|
end
|
221
173
|
end
|
222
|
-
|
223
|
-
if defined?(Puma) && Bridgetown.env.development? &&
|
224
|
-
!Bridgetown::Current.preloaded_configuration.skip_live_reload
|
225
|
-
Puma::Launcher.class_eval do
|
226
|
-
alias_method :_old_stop, :stop
|
227
|
-
def stop
|
228
|
-
Bridgetown::Rack.interrupted = true
|
229
|
-
|
230
|
-
_old_stop
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
@@ -38,7 +38,7 @@ module Bridgetown
|
|
38
38
|
site.collections.each_value do |collection|
|
39
39
|
next if collection.data?
|
40
40
|
|
41
|
-
collection.read
|
41
|
+
collection.read unless site.ssr? && collection.metadata.skip_for_ssr
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -69,7 +69,7 @@ module Bridgetown
|
|
69
69
|
file_path = @site.in_source_dir(base, entry)
|
70
70
|
if File.directory?(file_path)
|
71
71
|
entries_dirs << entry
|
72
|
-
elsif
|
72
|
+
elsif FrontMatter::Loaders.front_matter?(file_path)
|
73
73
|
entries_pages << entry
|
74
74
|
else
|
75
75
|
entries_static_files << entry
|
@@ -78,7 +78,7 @@ module Bridgetown
|
|
78
78
|
|
79
79
|
retrieve_dirs(dir, entries_dirs)
|
80
80
|
retrieve_pages(dir, entries_pages)
|
81
|
-
retrieve_static_files(dir, entries_static_files)
|
81
|
+
retrieve_static_files(dir, entries_static_files) unless site.ssr?
|
82
82
|
end
|
83
83
|
|
84
84
|
# Recursively traverse directories with the read_directories function.
|
@@ -101,6 +101,8 @@ module Bridgetown
|
|
101
101
|
# @param entries_pages [Array<String>] page paths in the directory
|
102
102
|
# @return [void]
|
103
103
|
def retrieve_pages(dir, entries_pages)
|
104
|
+
return if site.ssr? && site.collections.pages.metadata.skip_for_ssr
|
105
|
+
|
104
106
|
entries_pages.each do |page_path|
|
105
107
|
site.collections.pages.read_resource(site.in_source_dir(dir, page_path))
|
106
108
|
end
|
@@ -129,7 +131,7 @@ module Bridgetown
|
|
129
131
|
#
|
130
132
|
# Returns the Array of filtered entries.
|
131
133
|
def filter_entries(entries, base_directory = nil)
|
132
|
-
EntryFilter.new(site, base_directory:
|
134
|
+
EntryFilter.new(site, base_directory:).filter(entries)
|
133
135
|
end
|
134
136
|
|
135
137
|
# Read the entries from a particular directory for processing
|