devcenter 0.0.2 → 0.0.3
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.
- data/lib/devcenter.rb +1 -0
- data/lib/devcenter/cli.rb +9 -2
- data/lib/devcenter/commands/base.rb +2 -0
- data/lib/devcenter/commands/open.rb +3 -4
- data/lib/devcenter/logger.rb +17 -0
- data/lib/devcenter/previewer.rb +1 -0
- data/lib/devcenter/previewer/web_app.rb +22 -2
- data/lib/devcenter/version.rb +1 -1
- metadata +2 -1
data/lib/devcenter.rb
CHANGED
data/lib/devcenter/cli.rb
CHANGED
@@ -13,7 +13,10 @@ command :open do |c|
|
|
13
13
|
c.summary = 'Open the article with the given slug in the default browser'
|
14
14
|
c.description = c.summary
|
15
15
|
c.example 'devcenter open process-model', 'Opens https://devcenter.heroku.com/articles/process-model in the default browser'
|
16
|
+
c.option '--debug', 'Output internal log to help debugging'
|
16
17
|
c.action do |args, options|
|
18
|
+
options.default :debug => false
|
19
|
+
Devcenter::Logger.active = options.debug
|
17
20
|
Devcenter::Commands::Open.run(args[0])
|
18
21
|
end
|
19
22
|
end
|
@@ -24,8 +27,10 @@ command :pull do |c|
|
|
24
27
|
c.description = c.summary
|
25
28
|
c.example 'devcenter pull process-model', 'Saves the content of the article with the "process-model" slug to a local process-model.md file in the current directory'
|
26
29
|
c.option '--force', 'Skip confirmation and overwrite existing local file'
|
30
|
+
c.option '--debug', 'Output internal log to help debugging'
|
27
31
|
c.action do |args, options|
|
28
|
-
options.default :force => false
|
32
|
+
options.default :force => false, :debug => false
|
33
|
+
Devcenter::Logger.active = options.debug
|
29
34
|
Devcenter::Commands::Pull.run(args[0], options.force)
|
30
35
|
end
|
31
36
|
end
|
@@ -38,8 +43,10 @@ command :preview do |c|
|
|
38
43
|
|
39
44
|
c.option '--host HOST', String, 'Host where the preview will be available'
|
40
45
|
c.option '--port PORT_NUMBER', Integer, 'Port where the preview will be available'
|
46
|
+
c.option '--debug', 'Output internal log to help debugging'
|
41
47
|
c.action do |args, options|
|
42
|
-
options.default :host => '127.0.0.1', :port => 3000
|
48
|
+
options.default :host => '127.0.0.1', :port => 3000, :debug => false
|
49
|
+
Devcenter::Logger.active = options.debug
|
43
50
|
Devcenter::Commands::Preview.run(args[0], options.host, options.port)
|
44
51
|
end
|
45
52
|
end
|
@@ -15,14 +15,13 @@ module Devcenter::Commands
|
|
15
15
|
|
16
16
|
def run
|
17
17
|
url = article_url(@slug)
|
18
|
+
log "Connecting to #{url}"
|
18
19
|
head = Excon.head(url)
|
19
20
|
case head.status
|
20
21
|
when 200
|
21
|
-
|
22
|
+
log "Page found, opening"
|
22
23
|
launchy = Launchy.open(url)
|
23
|
-
if launchy.respond_to?(:join)
|
24
|
-
launchy.join
|
25
|
-
end
|
24
|
+
launchy.join if launchy.respond_to?(:join)
|
26
25
|
when 301, 302
|
27
26
|
say "Redirected to #{head.headers['Location']}"
|
28
27
|
when 404
|
data/lib/devcenter/previewer.rb
CHANGED
@@ -11,6 +11,7 @@ module Devcenter::Previewer
|
|
11
11
|
def preview(slug, md_path, host, port)
|
12
12
|
server = WebServer.new(host, port, WebApp, true)
|
13
13
|
file_listener_callback = Proc.new do |modified, added, removed|
|
14
|
+
modified.each{ |f| Devcenter::Logger.log "File modified: #{f}" }
|
14
15
|
WebApp.send_server_event
|
15
16
|
end
|
16
17
|
|
@@ -2,6 +2,8 @@ module Devcenter::Previewer
|
|
2
2
|
|
3
3
|
class WebApp < Sinatra::Base
|
4
4
|
|
5
|
+
include Devcenter::Logger
|
6
|
+
|
5
7
|
set :logging, false
|
6
8
|
set connections: []
|
7
9
|
set :public_folder, File.dirname(__FILE__)
|
@@ -17,17 +19,34 @@ module Devcenter::Previewer
|
|
17
19
|
get '/stream', provides: 'text/event-stream' do
|
18
20
|
stream :keep_open do |conn|
|
19
21
|
settings.connections << conn
|
20
|
-
|
21
|
-
|
22
|
+
log "New incoming connection (#{settings.connections.size} open)"
|
23
|
+
|
24
|
+
# refresh connection before browser times out
|
25
|
+
EventMachine::PeriodicTimer.new(20) do
|
26
|
+
log "Refreshing connection"
|
27
|
+
conn << ":refreshing \n\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
conn.callback do
|
31
|
+
settings.connections.delete(conn)
|
32
|
+
log "Connection closed locally (#{settings.connections.size} open)"
|
33
|
+
end
|
34
|
+
|
35
|
+
conn.errback do
|
22
36
|
conn.close
|
23
37
|
settings.connections.delete(conn)
|
38
|
+
settings.connections.delete(conn)
|
39
|
+
log "Connection closed externally (#{settings.connections.size} open)"
|
24
40
|
end
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
28
44
|
get '/:slug' do
|
45
|
+
log "Local article requested: #{params[:slug]}"
|
29
46
|
src_path = File.join(Dir.pwd, "#{params[:slug]}.md")
|
47
|
+
log "Parsing"
|
30
48
|
@article = parse_article(src_path)
|
49
|
+
log "Serving"
|
31
50
|
erb :article
|
32
51
|
end
|
33
52
|
|
@@ -45,6 +64,7 @@ module Devcenter::Previewer
|
|
45
64
|
end
|
46
65
|
|
47
66
|
def self.send_server_event
|
67
|
+
Devcenter::Logger.log "Serving server side event to #{settings.connections.size} connections"
|
48
68
|
settings.connections.each do |conn|
|
49
69
|
conn << "data: reload\n\n"
|
50
70
|
end
|
data/lib/devcenter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devcenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -228,6 +228,7 @@ files:
|
|
228
228
|
- lib/devcenter/commands/pull.rb
|
229
229
|
- lib/devcenter/helpers.rb
|
230
230
|
- lib/devcenter/layout.html
|
231
|
+
- lib/devcenter/logger.rb
|
231
232
|
- lib/devcenter/md_parser.rb
|
232
233
|
- lib/devcenter/previewer.rb
|
233
234
|
- lib/devcenter/previewer/assets/images/public/article-icon-large.png
|