ruby_native 0.17.1 → 0.17.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/ruby_native/cli/preview.rb +49 -6
- data/lib/ruby_native/version.rb +1 -1
- 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: a20e456fe2c38a3885bd29bc796da70a6ef238bf30de87297ca14f9f407d783d
|
|
4
|
+
data.tar.gz: b266e12b4c911bb57ba5c21eb6748f270a13a7449e27296fb5bf5fefb4b20d96
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a59080e79c82b040910d146ad1b3f214ef247a1f251783ba951400bf099bc1f161b41195b2230bb0da977988ae7850be1be6aff1e4f89c16a539b7b7dcef8f3
|
|
7
|
+
data.tar.gz: 289783ff033617cc3b77f697334e861985f98786562d978b923118c56638c0411931df89929bf9c771cbe77a88d71f38d6f177fbb1762c66badfdb039fa7379c
|
|
@@ -2,6 +2,7 @@ require "open3"
|
|
|
2
2
|
require "net/http"
|
|
3
3
|
require "uri"
|
|
4
4
|
require "resolv"
|
|
5
|
+
require "ruby_native/cli/credentials"
|
|
5
6
|
|
|
6
7
|
module RubyNative
|
|
7
8
|
class CLI
|
|
@@ -14,6 +15,8 @@ module RubyNative
|
|
|
14
15
|
DEFAULT_PORT = 3000
|
|
15
16
|
PORT_RANGE = (1..65_535)
|
|
16
17
|
OUTPUT_TAIL_LINES = 5
|
|
18
|
+
DEPLOY_URL = "https://rubynative.com/deploy"
|
|
19
|
+
QR_QUIET_ZONE = 4
|
|
17
20
|
|
|
18
21
|
def initialize(argv)
|
|
19
22
|
@url = parse_option(argv, "--url")
|
|
@@ -269,6 +272,17 @@ module RubyNative
|
|
|
269
272
|
require "rqrcode"
|
|
270
273
|
|
|
271
274
|
qr = RQRCode::QRCode.new(url, level: :l)
|
|
275
|
+
width = (qr.modules.size + QR_QUIET_ZONE * 2) * 2
|
|
276
|
+
columns = terminal_columns
|
|
277
|
+
|
|
278
|
+
# A row that wraps prints as two, and the code never scans. Longer tunnel
|
|
279
|
+
# hostnames make bigger codes, so a pane that fit yesterday can fail today.
|
|
280
|
+
if columns && columns < width
|
|
281
|
+
puts ""
|
|
282
|
+
puts "Your terminal is #{columns} columns wide and the QR code needs #{width}. Widen the window, or paste the URL into the Ruby Native app."
|
|
283
|
+
print_preview_details(url)
|
|
284
|
+
return
|
|
285
|
+
end
|
|
272
286
|
|
|
273
287
|
# Painted as background colors, not block glyphs: a glyph takes the terminal's
|
|
274
288
|
# foreground color, which prints the code inverted on a dark theme, and Android
|
|
@@ -281,23 +295,52 @@ module RubyNative
|
|
|
281
295
|
print qr.as_ansi(
|
|
282
296
|
light: "\e[48;2;255;255;255m",
|
|
283
297
|
dark: "\e[48;2;0;0;0m",
|
|
284
|
-
quiet_zone_size:
|
|
298
|
+
quiet_zone_size: QR_QUIET_ZONE
|
|
285
299
|
)
|
|
300
|
+
print_preview_details(url)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def print_preview_details(url)
|
|
286
304
|
puts ""
|
|
287
305
|
puts url
|
|
288
306
|
puts ""
|
|
289
|
-
puts "
|
|
290
|
-
puts "
|
|
307
|
+
puts "Download the Ruby Native app and scan the QR code: https://rubynative.com/try/download"
|
|
308
|
+
puts ""
|
|
291
309
|
if @url
|
|
292
|
-
puts "Keep this running and your Rails server reachable at #{@url}."
|
|
310
|
+
puts "Keep this running and your Rails server reachable at #{@url}. Press Ctrl+C to stop."
|
|
293
311
|
else
|
|
294
|
-
puts "Keep this running and your Rails server on port #{port_description} in another terminal."
|
|
312
|
+
puts "Keep this running and your Rails server on port #{port_description} in another terminal. Press Ctrl+C to stop."
|
|
295
313
|
end
|
|
296
|
-
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# Only a terminal can wrap the code; captured or piped output never does.
|
|
317
|
+
def terminal_columns
|
|
318
|
+
return unless $stdout.tty?
|
|
319
|
+
|
|
320
|
+
require "io/console"
|
|
321
|
+
IO.console&.winsize&.last
|
|
322
|
+
rescue StandardError
|
|
323
|
+
nil
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# Nobody has deployed from a machine that has never logged in, so the
|
|
327
|
+
# hint reaches first-time users and spares customers previewing day to day.
|
|
328
|
+
def never_logged_in?
|
|
329
|
+
Credentials.token.nil?
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def print_farewell
|
|
333
|
+
return unless never_logged_in?
|
|
334
|
+
|
|
335
|
+
puts ""
|
|
336
|
+
puts "Like what you see? `ruby_native deploy` puts a real app on your phone for good."
|
|
337
|
+
puts ""
|
|
338
|
+
puts "Free until you ship: #{DEPLOY_URL}"
|
|
297
339
|
end
|
|
298
340
|
|
|
299
341
|
def trap_interrupt
|
|
300
342
|
Signal.trap("INT") do
|
|
343
|
+
print_farewell
|
|
301
344
|
kill_tunnel
|
|
302
345
|
exit 0
|
|
303
346
|
end
|
data/lib/ruby_native/version.rb
CHANGED