trmnl_preview 0.8.3 → 0.8.4
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/CHANGELOG.md +7 -0
- data/README.md +5 -0
- data/lib/trmnlp/app.rb +40 -7
- data/lib/trmnlp/commands/serve.rb +3 -0
- data/lib/trmnlp/config/plugin.rb +7 -2
- data/lib/trmnlp/version.rb +1 -1
- data/lib/trmnlp/watcher.rb +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9fe003b113f4c1d832529b4d01cc931a8eb63259f385db8d6ff2dfca919a7cb9
|
|
4
|
+
data.tar.gz: 2254239e25186dab5f29bebf22ea8a87a180362521cf89a40900d86dda9bb9fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5e588f871e595f7c8dd637b6a2203cc1bde1696b91a5c397b1c176c4306f28e4f96ecc76a583f23da75ab3355a4288897b2ee823c7d8e1d658a2114c13d6f6d
|
|
7
|
+
data.tar.gz: 55efd439389300e0b18fe29025446632dd04412564a6ff36f8bea60d06f12e324bf18c97429b237d90df3eda94262a6009158cd82df8aab30b3b629dd6d1ff5e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
# Changelog
|
|
3
3
|
|
|
4
|
+
## 0.8.4
|
|
5
|
+
|
|
6
|
+
- Fixed `trmnlp serve` hanging after switching between browser tabs. Live reload now uses `rack.hijack` so SSE connections release their Puma worker thread immediately instead of holding it for the lifetime of the tab.
|
|
7
|
+
- Fixed Ctrl-C requiring three presses to stop the dev server. filewatcher 3.0.1 was clobbering Puma's signal handlers with its own `trap('INT') { exit }`.
|
|
8
|
+
- Fixed scaffolded plugins silently skipping their transform when `settings.yml` had `serverless_language: ''`. The empty string was treated as truthy in Ruby and short-circuited the file-extension fallback.
|
|
9
|
+
- Docker examples in the README now use `--pull always` (and `pull_policy: always` for Compose) so a new release is picked up on the next `docker run` without a manual pull.
|
|
10
|
+
|
|
4
11
|
## 0.8.3
|
|
5
12
|
|
|
6
13
|
- `trmnlp init` and `trmnlp clone` now scaffold a `.github/workflows/trmnl.yml` CI workflow and a `.gitignore`, and run `git init -b main`, so a cloned plugin is ready to push to GitHub and deploy on every commit to `main`
|
data/README.md
CHANGED
|
@@ -203,11 +203,14 @@ trmnlp serve
|
|
|
203
203
|
|
|
204
204
|
```sh
|
|
205
205
|
docker run \
|
|
206
|
+
--pull always \
|
|
206
207
|
--publish 4567:4567 \
|
|
207
208
|
--volume "$(pwd):/plugin" \
|
|
208
209
|
trmnl/trmnlp serve
|
|
209
210
|
```
|
|
210
211
|
|
|
212
|
+
`--pull always` checks the registry on every run and pulls a newer image if one exists, so you don't have to remember to `docker pull` after each release.
|
|
213
|
+
|
|
211
214
|
Inside a container, `serve` binds to `0.0.0.0` automatically (it detects `/.dockerenv`) so the preview is reachable from your host browser. Outside Docker it binds to `127.0.0.1`.
|
|
212
215
|
|
|
213
216
|
Swap `serve` for any other command (`lint`, `login`, `clone`, etc.) to run it in a one-off container.
|
|
@@ -218,6 +221,7 @@ For running multiple commands (login, clone, serve), you can start an interactiv
|
|
|
218
221
|
|
|
219
222
|
```sh
|
|
220
223
|
docker run -it \
|
|
224
|
+
--pull always \
|
|
221
225
|
--publish 4567:4567 \
|
|
222
226
|
--volume "$HOME/.config/trmnlp:/root/.config/trmnlp" \
|
|
223
227
|
--volume "$(pwd):/plugin" \
|
|
@@ -244,6 +248,7 @@ For a checked-in config — like [`examples/hn-stories/`](examples/hn-stories/)
|
|
|
244
248
|
services:
|
|
245
249
|
trmnlp:
|
|
246
250
|
image: trmnl/trmnlp
|
|
251
|
+
pull_policy: always
|
|
247
252
|
command: ["serve"]
|
|
248
253
|
ports:
|
|
249
254
|
- "4567:4567"
|
data/lib/trmnlp/app.rb
CHANGED
|
@@ -77,17 +77,40 @@ module TRMNLP
|
|
|
77
77
|
JSON.pretty_generate(@user_data_assembler.call(device:))
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
# Live reload
|
|
81
|
-
#
|
|
82
|
-
#
|
|
80
|
+
# Live reload uses rack.hijack so the Puma worker thread is released the
|
|
81
|
+
# instant we have the raw socket — broadcasting then runs on our own
|
|
82
|
+
# thread, never competing with HTTP request workers. Adapted from the
|
|
83
|
+
# Faye::EventSource pattern in faye-websocket (lib/faye/rack_stream.rb)
|
|
84
|
+
# but without the EventMachine dependency: where Faye uses EM.attach to
|
|
85
|
+
# get a reactor callback on socket close, we detect close synchronously
|
|
86
|
+
# via the IOError/EPIPE raised by the next heartbeat write.
|
|
87
|
+
HEARTBEAT_SECONDS = 5
|
|
88
|
+
|
|
83
89
|
get '/live_reload' do
|
|
84
|
-
|
|
90
|
+
hijack = env['rack.hijack']
|
|
91
|
+
halt 500, 'rack.hijack unavailable' unless hijack
|
|
92
|
+
hijack.call
|
|
93
|
+
io = env['rack.hijack_io']
|
|
94
|
+
|
|
85
95
|
queue = Thread::Queue.new
|
|
86
96
|
@live_reload_clients << queue
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
|
|
98
|
+
Thread.new do
|
|
99
|
+
io.write("HTTP/1.1 200 OK\r\n" \
|
|
100
|
+
"Content-Type: text/event-stream\r\n" \
|
|
101
|
+
"Cache-Control: no-cache\r\n" \
|
|
102
|
+
"Connection: close\r\n\r\n")
|
|
103
|
+
run_live_reload_loop(io, queue)
|
|
104
|
+
rescue IOError, Errno::EPIPE, Errno::ECONNRESET
|
|
105
|
+
# client disconnected mid-write — normal termination
|
|
106
|
+
ensure
|
|
107
|
+
@live_reload_clients.delete(queue)
|
|
108
|
+
io.close
|
|
90
109
|
end
|
|
110
|
+
|
|
111
|
+
# -1 status tells the server we've hijacked the response. The body
|
|
112
|
+
# is never iterated; the thread above owns the socket from here.
|
|
113
|
+
[-1, {}, []]
|
|
91
114
|
end
|
|
92
115
|
|
|
93
116
|
get '/poll' do
|
|
@@ -128,6 +151,16 @@ module TRMNLP
|
|
|
128
151
|
|
|
129
152
|
private
|
|
130
153
|
|
|
154
|
+
# On timeout (queue idle), a colon-prefixed SSE comment line both
|
|
155
|
+
# keeps proxies awake and surfaces a dead client via the next
|
|
156
|
+
# io.write — the route's outer rescue then cleans up.
|
|
157
|
+
def run_live_reload_loop(io, queue)
|
|
158
|
+
loop do
|
|
159
|
+
message = queue.pop(timeout: HEARTBEAT_SECONDS)
|
|
160
|
+
io.write(message || ": heartbeat\n\n")
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
131
164
|
# ScreenGenerator is request-scoped — it carries the per-request width,
|
|
132
165
|
# height, and color_depth — so it is built here rather than on the shared
|
|
133
166
|
# Context graph. Screenshots are a serve-only concern and would not belong
|
|
@@ -22,6 +22,9 @@ module TRMNLP
|
|
|
22
22
|
App.set(:browser_pool, BrowserPool.new(driver_factory: FirefoxDriver.method(:build)))
|
|
23
23
|
App.set(:bind, options.bind)
|
|
24
24
|
App.set(:port, options.port)
|
|
25
|
+
# Each live-reload SSE connection holds a Puma thread for the tab's
|
|
26
|
+
# lifetime; the default 0:5 pool runs out fast with multiple tabs open.
|
|
27
|
+
App.set(:server_settings, Threads: '1:16')
|
|
25
28
|
permit_all_hosts if codespaces?
|
|
26
29
|
|
|
27
30
|
# Finally, start the app!
|
data/lib/trmnlp/config/plugin.rb
CHANGED
|
@@ -73,8 +73,13 @@ module TRMNLP
|
|
|
73
73
|
# Explicit language for transform.* code. If absent, the language
|
|
74
74
|
# is inferred from the file extension by Paths#transform_file.
|
|
75
75
|
# This one lives on the plugin (settings.yml) because production
|
|
76
|
-
# stores it on the plugin_setting record.
|
|
77
|
-
|
|
76
|
+
# stores it on the plugin_setting record. The scaffold emits
|
|
77
|
+
# `serverless_language: ''`, so empty strings collapse to nil here
|
|
78
|
+
# to let the `||` in the pipeline fall through to the inferred value.
|
|
79
|
+
def serverless_language
|
|
80
|
+
value = @config['serverless_language']
|
|
81
|
+
value unless value.to_s.empty?
|
|
82
|
+
end
|
|
78
83
|
|
|
79
84
|
# The TRMNL design-system version this plugin renders against.
|
|
80
85
|
# Lives on the plugin (settings.yml), like serverless_language,
|
data/lib/trmnlp/version.rb
CHANGED
data/lib/trmnlp/watcher.rb
CHANGED
|
@@ -4,6 +4,24 @@ require 'filewatcher'
|
|
|
4
4
|
|
|
5
5
|
require_relative 'reporter'
|
|
6
6
|
|
|
7
|
+
# filewatcher 3.0.1's #watch installs `trap('INT') { exit }` (and HUP/TERM)
|
|
8
|
+
# unconditionally, clobbering Puma's clean-shutdown handler — Ctrl-C then
|
|
9
|
+
# raises SystemExit instead of triggering Puma's graceful stop, which is
|
|
10
|
+
# why the container needs three SIGINTs to die. The gem offers no opt-out;
|
|
11
|
+
# its supported shutdown is Filewatcher#stop, which we're not using. We
|
|
12
|
+
# replace the trap-installing #watch with the rest of its body so signals
|
|
13
|
+
# fall through to whatever handler the host process installed (Puma).
|
|
14
|
+
Filewatcher.prepend(Module.new do
|
|
15
|
+
def watch(&on_update)
|
|
16
|
+
@on_update = on_update
|
|
17
|
+
@keep_watching = true
|
|
18
|
+
yield({ '' => '' }) if @immediate
|
|
19
|
+
main_cycle
|
|
20
|
+
@end_snapshot = current_snapshot
|
|
21
|
+
finalize(&on_update)
|
|
22
|
+
end
|
|
23
|
+
end)
|
|
24
|
+
|
|
7
25
|
module TRMNLP
|
|
8
26
|
class Watcher
|
|
9
27
|
def initialize(config:, user_data_assembler:, transform_pipeline:, reporter: Reporter.new)
|