bridgetown-core 2.2.1 → 2.2.2
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/lib/bridgetown-core/rack/live_reload.rb +63 -0
- data/lib/bridgetown-core/rack/routes.rb +12 -35
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ada32cd419f97f08f79cfc7a13630e040b1d41838d8d7045bc06374d9bbe12fc
|
|
4
|
+
data.tar.gz: eedd7b9d6b867a12a65e56cd85660aa2900d2154f08296dd58984d84e7bcaa48
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abb68767e3e6961f8144c045d48d3d540382a563e126349cf61ef053bf3ecc2195ebbab0134497b60c0539b49e7be741cc918553314328192db3f6b98a15193f
|
|
7
|
+
data.tar.gz: a6ad84682b36b5b85f6020dd29671d33fe86c92dd32842c23be51d54872566c9241c9ad01efbe2a62ca8e7e3361a20c22823991190b8f05a611a431c518806d1
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Style/RedundantBegin, Style/RedundantSelf
|
|
4
|
+
module Bridgetown
|
|
5
|
+
module Rack
|
|
6
|
+
class LiveReload
|
|
7
|
+
SLEEP_INTERVAL = 0.5
|
|
8
|
+
|
|
9
|
+
def initialize(file_to_check:, errors_file:)
|
|
10
|
+
@file_to_check = file_to_check
|
|
11
|
+
@errors_file = errors_file
|
|
12
|
+
|
|
13
|
+
@last_modified = self.current_modified
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def event_stream
|
|
17
|
+
proc do |stream|
|
|
18
|
+
begin
|
|
19
|
+
run_loop(stream)
|
|
20
|
+
ensure
|
|
21
|
+
stream.close
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def threaded_event_stream
|
|
27
|
+
proc do |stream|
|
|
28
|
+
Thread.new do
|
|
29
|
+
run_loop(stream)
|
|
30
|
+
ensure
|
|
31
|
+
stream.close
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def run_loop(stream)
|
|
39
|
+
loop do
|
|
40
|
+
latest_modified = current_modified
|
|
41
|
+
|
|
42
|
+
if @last_modified < latest_modified
|
|
43
|
+
stream.write "data: reloaded!\n\n"
|
|
44
|
+
break
|
|
45
|
+
elsif File.exist?(@errors_file)
|
|
46
|
+
stream.write "event: builderror\ndata: #{File.read(@errors_file).to_json}\n\n"
|
|
47
|
+
else
|
|
48
|
+
stream.write "data: #{latest_modified}\n\n"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
sleep SLEEP_INTERVAL
|
|
52
|
+
rescue Errno::EPIPE # User refreshed the page
|
|
53
|
+
break
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def current_modified
|
|
58
|
+
File.exist?(@file_to_check) ? File.stat(@file_to_check).mtime.to_i : 0
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
# rubocop:enable Style/RedundantBegin, Style/RedundantSelf
|
|
@@ -109,52 +109,29 @@ module Bridgetown
|
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
# @param app [Roda]
|
|
112
|
-
def setup_live_reload(app)
|
|
113
|
-
|
|
112
|
+
def setup_live_reload(app)
|
|
113
|
+
require_relative "live_reload"
|
|
114
|
+
|
|
114
115
|
file_to_check = Bridgetown.live_reload_path
|
|
115
116
|
errors_file = Bridgetown.build_errors_path
|
|
117
|
+
live_reload = Bridgetown::Rack::LiveReload.new(
|
|
118
|
+
file_to_check: file_to_check,
|
|
119
|
+
errors_file: errors_file
|
|
120
|
+
)
|
|
116
121
|
|
|
117
|
-
# rubocop:disable Metrics/BlockLength
|
|
118
122
|
app.request.get "_bridgetown/live_reload" do
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# https://github.com/puma/puma/issues/3569
|
|
125
|
-
unless defined? Falcon
|
|
126
|
-
trap(:INT) do
|
|
127
|
-
stream.close
|
|
128
|
-
raise Interrupt
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
loop do
|
|
133
|
-
new_mod = File.exist?(file_to_check) ? File.stat(file_to_check).mtime.to_i : 0
|
|
134
|
-
|
|
135
|
-
if @_mod < new_mod
|
|
136
|
-
stream.write "data: reloaded!\n\n"
|
|
137
|
-
break
|
|
138
|
-
elsif File.exist?(errors_file)
|
|
139
|
-
stream.write "event: builderror\ndata: #{File.read(errors_file).to_json}\n\n"
|
|
140
|
-
else
|
|
141
|
-
stream.write "data: #{new_mod}\n\n"
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
sleep sleep_interval
|
|
145
|
-
rescue Errno::EPIPE # User refreshed the page
|
|
146
|
-
break
|
|
123
|
+
event_stream =
|
|
124
|
+
if defined? Falcon
|
|
125
|
+
live_reload.event_stream
|
|
126
|
+
else
|
|
127
|
+
live_reload.threaded_event_stream
|
|
147
128
|
end
|
|
148
|
-
ensure
|
|
149
|
-
stream.close
|
|
150
|
-
end
|
|
151
129
|
|
|
152
130
|
app.request.halt [200, {
|
|
153
131
|
"Content-Type" => "text/event-stream",
|
|
154
132
|
"cache-control" => "no-cache",
|
|
155
133
|
}, event_stream,]
|
|
156
134
|
end
|
|
157
|
-
# rubocop:enable Metrics/BlockLength
|
|
158
135
|
end
|
|
159
136
|
end
|
|
160
137
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bridgetown-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.2.
|
|
4
|
+
version: 2.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bridgetown Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-06
|
|
11
|
+
date: 2026-07-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: addressable
|
|
@@ -72,14 +72,14 @@ dependencies:
|
|
|
72
72
|
requirements:
|
|
73
73
|
- - '='
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 2.2.
|
|
75
|
+
version: 2.2.2
|
|
76
76
|
type: :runtime
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - '='
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 2.2.
|
|
82
|
+
version: 2.2.2
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: csv
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -568,6 +568,7 @@ files:
|
|
|
568
568
|
- lib/bridgetown-core/plugin_manager.rb
|
|
569
569
|
- lib/bridgetown-core/rack/boot.rb
|
|
570
570
|
- lib/bridgetown-core/rack/default_config.ru
|
|
571
|
+
- lib/bridgetown-core/rack/live_reload.rb
|
|
571
572
|
- lib/bridgetown-core/rack/loader_hooks.rb
|
|
572
573
|
- lib/bridgetown-core/rack/logger.rb
|
|
573
574
|
- lib/bridgetown-core/rack/routes.rb
|