kdwatch 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaba18036cbe879e4f88d5b74513ad4a5d36abb843234c83c35e688aaaf36e03
4
- data.tar.gz: ea272b95fef2f02ec9513539dee9f4f5126b4e65c3c6a97b0603d94fa7cd37e2
3
+ metadata.gz: c8a50fa7ebbda382c852684c4b440e2a75213450af0e02e68130d9fd8fccabb8
4
+ data.tar.gz: 366e1aef8fcc0144c8ccc6adc74ee5492fba1088febaeee9a47e699ce9f57496
5
5
  SHA512:
6
- metadata.gz: 603817fcb75e8b474a4f6bc7d58408c4d8fcc55f7cbd50d1cd6a48f8d21a8b2672f2b221697b9948412e2bf4825dd9925ae10f9a4be6a6360e7c5e54c94c9471
7
- data.tar.gz: 4237a7b045723de06320999301e0c388d879d6f5016b12c7170702b7b24981e302848eb76aad46513cde1a0d37792811165710c865a9cb597064dca17a54eed5
6
+ metadata.gz: 64ebdd540be0d137d8b436552044ec1b67f17ec7ad3eabfc9c64640fdfcc31249de52f4f9e62b1562031287908e232a815663a1d31b9be04ae80bc0d9578514a
7
+ data.tar.gz: 242b365d72a33ebc24f36b4743baf3af43a0018348d88dcdf1b9fbd95da72ff65c3ef670a822d7f3a34d55fd847ab574ca1f182cfc52157247482a604dbc04c5
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # Kdwatch
2
+
3
+ Autoreloading display of [kramdown-rfc][] document in browser
4
+
5
+ [kramdown-rfc]: http://rfc.space
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ $ pip3 install --upgrade xml2rfc
11
+ $ gem update
12
+ $ gem install kdwatch
13
+ ```
14
+
15
+ * For some reason, the initial `gem install` takes a couple of minutes,
16
+ during the first few of which it may seem nothing happens.
17
+ * If the above `pip3` doesn't work: in a pinch, kdrfc will use the IETF
18
+ web service for xml2rfc processing (but that may be a bit slower).
19
+ * Depending on system configuration, add `sudo` (but don't if it isn't
20
+ actually needed).
21
+
22
+ ## Usage
23
+
24
+ * Open a separate terminal window/screen.
25
+ * Go to a directory that has a single draft-*.md (or select one by
26
+ specifying the markdown file name on the command line) and run:
27
+
28
+ ```
29
+ $ kdwatch
30
+ ```
31
+
32
+ After about 10 seconds, a browser will open (or an error message will
33
+ pop up with the URL to use, which depends on the options given, but
34
+ defaults to <http://127.0.0.1:7991/>).
35
+
36
+ Now, whenever you do an editor save of the markdown file, after a
37
+ couple of seconds (1.6 s for my Intel Mac, 0.8 s for my M1 Mac) you
38
+ see an updated HTML in the browser.
39
+
40
+ You will need to keep the `kdwatch` terminal/screen open to see
41
+ potential error messages, e.g., if you break the markdown in some way.
42
+
43
+ ### There can only be one (per host/port)
44
+
45
+ There can only be one kdwatch active on each host and port. You will
46
+ need to specify a different port (or host!) to start more than one
47
+ pkdwatch.
48
+
49
+ * `-o host` to select an address on the serving host (default: 127.0.0.1)
50
+ * `-i` as a shortcut for `-o ::`
51
+ * `-p port` to select a port number (default: 7991)
52
+ * `-1` to `6` as a shortcut for `-p 7991` to `-p 7996` (must be last
53
+ option because of an idiosyncrasy of the optionparser library)
54
+
55
+ kdwatch has two flags to simplify handling servers that might be
56
+ accumulating on one host/port:
57
+
58
+ * `-e` to kill (SIGINT) any current holder of the port given and exit
59
+ * `-r` to do this, and to start a new instance
60
+
61
+ So the most likely use is going to be:
62
+
63
+ ```
64
+ kdwatch -r
65
+ ```
66
+
67
+ or, if your drafts are weirdly named or you need to select one out of
68
+ many
69
+
70
+ ```
71
+ kdwatch -r weird-draft.md
72
+ ```
73
+
74
+ ### This is a web server
75
+
76
+ The fun thing with the `-i` option is that you can replace the local
77
+ URL by filling in the hostname of the laptop and use the resulting URL
78
+ on a different browser (e.g., `http://mylaptop.local:7991` on your iPad or
79
+ another laptop), and save some screen real-estate on your laptop.
80
+
81
+ kdwatch essentially is a web server and, unless used on 127.0.0.1 (or
82
+ ::1), is accessible to anyone who can access your laptop over IP.
83
+
84
+ That may be a security problem -- do not specify non-local hosts
85
+ unless you are not “on the Internet” (or trust the way I cobble
86
+ together software).
87
+ If you did, maybe `kdwatch -e` before going there!
88
+
89
+ The web-server function may also be a feature -- it even can be used for joint viewing...
90
+
91
+ ### 7991, haven't I heard that number before?
92
+
93
+ The default port number was chosen after [RFC 7991], the initial (no
94
+ longer really authoritative) version of the v3 RFCXML specification,
95
+ and the port shortcuts 1 to 6 point to further RFCs from this series.
96
+ (7997 is a particularly lame RFC, so it cannot be chosen by a
97
+ shortcut [actually: this port is already registered for something else].)
98
+
99
+ [RFC 7991]: https://rfc-editor.org/rfc/rfc7991.html
100
+
101
+ ## Feedback, please
102
+
103
+ This has only been tested on macOS and briefly on Linux. No idea about WSL.
104
+ There is very little error handling yet, so restarts of the tool may
105
+ be required, or sometimes reloading in the browser (CMD-R/F5) is all
106
+ that is needed.
107
+
108
+ If you try it, please send feedback (and, in case of an error, *all*
109
+ output on the kdwatch terminal window, please).
110
+
111
+ Bug reports, pull requests, or simple suggestions are welcome on GitHub at
112
+ <https://github.com/cabo/kdwatch>, e.g., simply [submit an
113
+ issue][issues] or send me [mail][].
114
+
115
+ [issues]: https://github.com/cabo/kdwatch/issues
116
+ [mail]: mailto:cabo@tzi.org?Subject=kdwatch
117
+
118
+ ## License
119
+
120
+ The gem is available as open source under the terms of the [MIT License][].
121
+
122
+ [MIT License]: https://opensource.org/licenses/MIT
data/bin/kdwatch CHANGED
@@ -3,17 +3,77 @@ ENV["LANG"]="en_US.utf-8"
3
3
  ENV["LC_CTYPE"]="en_US.utf-8"
4
4
  ENV["KRAMDOWN_PERSISTENT"]="yes"
5
5
 
6
+
7
+ require 'optparse'
8
+ require 'ostruct'
9
+
10
+ require_relative "../lib/kdwatch/version"
11
+
6
12
  KDWATCH_PORT = 7991 # currently unregistered...
7
13
 
14
+ options = OpenStruct.new
15
+
16
+ op = OptionParser.new do |opts|
17
+ opts.banner = <<BANNER
18
+ Usage: kdwatch [options] draft-foo.md|.mkd|.xml
19
+ Version: #{Kdwatch::VERSION}
20
+ BANNER
21
+ opts.on("-V", "--version", "Show version and exit") do |v|
22
+ puts "kdwatch #{Kdwatch::Version}"
23
+ exit
24
+ end
25
+ opts.on("-H", "--help", "Show option summary and exit") do |v|
26
+ puts opts
27
+ exit
28
+ end
29
+ opts.on("-e", "--[no-]end", "End existing server and exit")
30
+ opts.on("-r", "--[no-]replace", "Replace existing server")
31
+ opts.on("-oNAME", "--host=NAME", String, "Server host (127.0.0.1)")
32
+ opts.on("-i", "--internet", 'Abbr. "on the Internet" (host = "::")')
33
+ opts.on("-pNUM", "--port=NUM", Integer, "Port number (#{KDWATCH_PORT})")
34
+ opts.on("-[1-6]", "--[1-6]", Integer, "Abbr. port number (#{KDWATCH_PORT/10}x), must be last")
35
+ end
36
+ begin
37
+ op.parse!(into: options)
38
+ rescue OptionParser::InvalidOption => e
39
+ warn "** #{e}"
40
+ warn op
41
+ exit 1
42
+ end
43
+
44
+ if options.internet
45
+ warn "** overriding host #{options.host} with ::" if options.host
46
+ options.host = "::"
47
+ else
48
+ options.host ||= "127.0.0.1"
49
+ end
50
+ if short_port = options[""]
51
+ port = short_port + KDWATCH_PORT/10*10
52
+ warn "** overriding port #{options.port} with #{port}" if options.port
53
+ options.port = port
54
+ else
55
+ options.port ||= KDWATCH_PORT
56
+ end
57
+
58
+ # p options
59
+
8
60
  ## -r: Kill any previous kdwatch and continue ("restart")
9
61
  ## -e: Kill any previous kdwatch and exit
10
- if ARGV[0] == "-e" || ARGV[0] == "-r"
62
+ if options.replace || options.end
11
63
  require 'open3'
12
64
 
13
65
  status = 1
14
- flag = ARGV.shift
15
66
 
16
- stdout_str, stderr_str, s = Open3.capture3("lsof -ti :#{KDWATCH_PORT} -s TCP:LISTEN")
67
+ lsof_host = case options.host
68
+ when "::", "0.0.0.0"
69
+ "" # can't do more specific with lsof; hope for the best
70
+ when /:/
71
+ "@'[#{options.host}]'"
72
+ else
73
+ "@'#{options.host}'"
74
+ end
75
+
76
+ stdout_str, stderr_str, s = Open3.capture3("lsof -ti #{lsof_host}:#{options.port} -s TCP:LISTEN")
17
77
  pids = if s.success? && stdout_str =~ /\A[0-9\s]*\z/ && stderr_str
18
78
  stdout_str.split
19
79
  else
@@ -22,7 +82,7 @@ if ARGV[0] == "-e" || ARGV[0] == "-r"
22
82
  []
23
83
  end
24
84
  if pids == []
25
- warn "** Nothing listening on kdwatch port" unless flag == "-r"
85
+ warn "** Nothing listening on kdwatch port" unless options.replace
26
86
  elsif pids.size != 1
27
87
  warn "** More than one process listening on kdwatch port, nothing done"
28
88
  else
@@ -32,7 +92,7 @@ if ARGV[0] == "-e" || ARGV[0] == "-r"
32
92
  warn "** #{pids[0]}: #{e.inspect}"
33
93
  end
34
94
  end
35
- exit(status) if flag == "-e"
95
+ exit(status) if options.end
36
96
  end
37
97
 
38
98
  ## Find an .mkd or a draft-*.md (excluding README.md and such)
@@ -42,8 +102,7 @@ if ARGV == []
42
102
  end
43
103
 
44
104
  if ARGV.size != 1
45
- warn "** Usage: #$0 [-r] [draft-foo.md]"
46
- warn "** #$0 -e"
105
+ warn op
47
106
  if warn_replace
48
107
  if ARGV.size > 1
49
108
  warn "** More than one draft file found #{ARGV.inspect}"
@@ -55,13 +114,17 @@ if ARGV.size != 1
55
114
  exit 1
56
115
  end
57
116
 
58
- ENV["KD_WATCH_SRC"] = ARGV[0]
117
+ ENV["KDWATCH_SRC"] = ARGV[0]
118
+ ENV["KDWATCH_HOST"] = options.host
119
+ ENV["KDWATCH_PORT"] = options.port.to_s
120
+ live_reload_port = options.port + 51234 # move up into ephemeral space
121
+ ENV["KDWATCH_LRPORT"] = live_reload_port.to_s
59
122
 
60
123
  File.write(".config.ru", <<HERE)
61
124
  require 'rack-livereload'
62
- use Rack::LiveReload, min_delay: 500, source: :vendored, no_swf: true
125
+ use Rack::LiveReload, min_delay: 500, source: :vendored, no_swf: true, port: #{live_reload_port}, live_reload_port: #{live_reload_port}
63
126
  require 'kdwatch-app.rb'
64
127
  run Sinatra::Application
65
128
  HERE
66
129
 
67
- exec("rackup -E production -s thin -p #{KDWATCH_PORT} .config.ru")
130
+ exec("rackup -E production -s thin -o #{options.host} -p #{options.port} .config.ru")
data/kdwatch.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency "bundler", '~> 2.2'
30
30
  spec.add_dependency "thin", '~> 1.8'
31
+ # spec.add_dependency "cabo-guard-livereload", '~> 2.5' #, require: false
31
32
  spec.add_dependency "guard-livereload", '~> 2.5' #, require: false
32
33
  spec.add_dependency "rack-livereload", '~> 0.3'
33
34
  spec.add_dependency "guard", '~> 2.17'
data/lib/kdwatch-app.rb CHANGED
@@ -11,8 +11,10 @@ require "sinatra"
11
11
  require "kramdown-rfc2629"
12
12
  require "net/http/persistent"
13
13
 
14
+ host = ENV["KDWATCH_HOST"]
15
+ port = ENV["KDWATCH_PORT"]
14
16
 
15
- sfn = ENV["KD_WATCH_SRC"]
17
+ sfn = ENV["KDWATCH_SRC"]
16
18
  fail "No source given" unless sfn
17
19
 
18
20
  dfn = File.join(File.dirname(sfn), "#{File.basename(sfn, ".*")}.html")
@@ -39,7 +41,7 @@ get "/rfc-local.css" do
39
41
  end
40
42
 
41
43
  File.write(".Guardfile", <<GF)
42
- guard 'livereload' do
44
+ guard :livereload, :port => #{ENV["KDWATCH_LRPORT"]} do
43
45
  watch("#{sfn}")
44
46
  end
45
47
  GF
@@ -49,7 +51,10 @@ spawn("guard -G .Guardfile", in: rd, close_others: true)
49
51
 
50
52
  # wrong: puts settings.port
51
53
 
52
- url = "http://127.0.0.1:7991"
54
+ host = "localhost" if host == "::" # work around macOS peculiarity
55
+ host = "[#{host}]" if host =~ /:/
56
+
57
+ url = "http://#{host}:#{port}"
53
58
 
54
59
  spawn("sleep 5; open #{url} || xdg-open #{url} || echo @@@ Please open #{url}")
55
60
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdwatch
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-04 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -133,6 +133,7 @@ files:
133
133
  - ".gitignore"
134
134
  - Gemfile
135
135
  - LICENSE.txt
136
+ - README.md
136
137
  - bin/kdwatch
137
138
  - kdwatch.gemspec
138
139
  - lib/kdwatch-app.rb