munge 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24e988722288862121d7457950447fbab2c86f92
4
- data.tar.gz: 17714169a9382dfc2ff42b966c3f4650409d0aba
3
+ metadata.gz: 21f94ee6721dd5a6248f8cc682e7c20b25e37c3c
4
+ data.tar.gz: 4bc2576726939c6ec80482b94fdb05d700dfeab2
5
5
  SHA512:
6
- metadata.gz: d0661b313d6ec45bd7f3b762d31706d9c44b83dc2d29bd1b88792aba609e94073f0d617d2456d0ae2d30de77622a195c813dcfb933e20c8af7e3848e98fa143d
7
- data.tar.gz: f2b2b49dd321267749c44c88963ebe92dfe57e64f70e9069579b87fab7774e02670897f1830095ecdbe96e618930e7987a7c07eb8e8abf8bf93daba68cf71465
6
+ metadata.gz: b5953027d4225360dfe10436c2c65956cdffe57657e766709b753948f6a212295bcf6aeb198127719749c15db09cdb19fd27cce7eb7b16887cf47a7d75e36d8b
7
+ data.tar.gz: 38649c10faff0d936d49b72f2f72a2a05e2fd134f599030f6d7ac589b05758699b9098e3cce14c2035d069333290cdb9145690d6c134236d96277db674863231
@@ -25,6 +25,7 @@ module Munge
25
25
  )
26
26
  end
27
27
 
28
+ # @return [Array<String>] list of updated items routes
28
29
  def call
29
30
  @runner.write
30
31
  end
@@ -2,15 +2,26 @@ module Munge
2
2
  module Cli
3
3
  module Commands
4
4
  class Server
5
- def initialize(bootloader)
5
+ def initialize(bootloader, livereload:)
6
6
  @bootloader = bootloader
7
- @listener = listener
7
+ @listener = listener
8
+ @livereload =
9
+ if livereload
10
+ if Gem.loaded_specs.key?("reel")
11
+ Munge::Extras::Livereload::Main.new(true)
12
+ else
13
+ STDERR.puts "Gem `reel` is not installed. Check that your Ruby version is compatible"
14
+ Munge::Extras::Livereload::Main.new(false)
15
+ end
16
+ else
17
+ Munge::Extras::Livereload::Main.new(false)
18
+ end
8
19
  end
9
20
 
10
21
  def call
11
22
  @listener.start
12
23
 
13
- system("munge build")
24
+ munge_build
14
25
 
15
26
  system("munge view")
16
27
  rescue Interrupt
@@ -23,9 +34,14 @@ module Munge
23
34
  require "listen"
24
35
 
25
36
  listen = Listen.to(@bootloader.root_path) do
26
- system("munge build")
37
+ built_files = munge_build
38
+
39
+ @livereload.notify_changes(files: built_files)
40
+
41
+ GC.start
27
42
  end
28
43
 
44
+ ignore(listen, ".sass-cache")
29
45
  ignore(listen, ENV["BUILD_ROOT"])
30
46
  ignore(listen, @bootloader.config[:output_path])
31
47
 
@@ -34,9 +50,25 @@ module Munge
34
50
 
35
51
  def ignore(listener, pattern)
36
52
  if pattern
37
- listener.ignore(/^#{pattern}/)
53
+ listener.ignore(/^#{Regexp.escape(pattern)}/)
38
54
  end
39
55
  end
56
+
57
+ def munge_build
58
+ bootloader =
59
+ Munge::Bootloader.new(root_path: @bootloader.root_path)
60
+
61
+ build_command =
62
+ Munge::Cli::Commands::Build.new(
63
+ bootloader,
64
+ dry_run: false,
65
+ reporter: "Default",
66
+ verbosity: "written",
67
+ build_root: ENV["BUILD_ROOT"]
68
+ )
69
+
70
+ build_command.call
71
+ end
40
72
  end
41
73
  end
42
74
  end
@@ -27,11 +27,12 @@ module Munge
27
27
  end
28
28
 
29
29
  desc "server", "Run the development server"
30
+ method_option :livereload, desc: "Reload browser on update", default: Gem.loaded_specs.key?("reel"), type: :boolean
30
31
  def server
31
32
  ENV["MUNGE_ENV"] ||= "development"
32
33
  ENV["BUILD_ROOT"] ||= "tmp/development-build"
33
34
 
34
- Commands::Server.new(bootloader).call
35
+ Commands::Server.new(bootloader, **symbolized_options).call
35
36
  end
36
37
 
37
38
  desc "update", "Use with caution: override local configs with pristine version (useful after bumping version in Gemfile)"
data/lib/munge/config.rb CHANGED
@@ -27,6 +27,8 @@ module Munge
27
27
  self[key_from_setter(method_name)] = arguments.first
28
28
  elsif key?(method_name)
29
29
  self[method_name]
30
+ else
31
+ super
30
32
  end
31
33
  end
32
34
 
@@ -0,0 +1,40 @@
1
+ module Munge
2
+ module Extras
3
+ module Livereload
4
+ class Messaging
5
+ def hello
6
+ JSON.generate(
7
+ command: "hello",
8
+ protocols: [the_protocol],
9
+ serverName: "munge-livereload"
10
+ )
11
+ end
12
+
13
+ def reload(changed_file)
14
+ JSON.generate(
15
+ command: "reload",
16
+ path: changed_file,
17
+ liveCSS: "false"
18
+ )
19
+ end
20
+
21
+ def valid_handshake?(socket_data)
22
+ client_handshake = JSON.parse(socket_data)
23
+
24
+ return false if client_handshake["command"] != "hello"
25
+ return false if !client_handshake["protocols"].include?(the_protocol)
26
+
27
+ true
28
+ rescue
29
+ false
30
+ end
31
+
32
+ private
33
+
34
+ def the_protocol
35
+ "http://livereload.com/protocols/official-7".freeze
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,57 @@
1
+ module Munge
2
+ module Extras
3
+ module Livereload
4
+ class Server < Reel::Server::HTTP
5
+ def initialize(host = "127.0.0.1", port = 35729)
6
+ super(host, port, &method(:on_connection))
7
+ @update_client = UpdateClient.new(self)
8
+ @messaging = Messaging.new
9
+ @sockets = []
10
+ end
11
+
12
+ def notify_reload(changed_files)
13
+ @sockets.each do |socket|
14
+ begin
15
+ changed_files.each do |file|
16
+ socket << @messaging.reload(file)
17
+ end
18
+ rescue Reel::SocketError
19
+ end
20
+ end
21
+ end
22
+
23
+ def on_connection(connection)
24
+ connection.each_request do |request|
25
+ if request.websocket?
26
+ handle_websocket(connection, request)
27
+ else
28
+ handle_request(request)
29
+ end
30
+ end
31
+ end
32
+
33
+ def handle_websocket(_connection, request)
34
+ socket = request.websocket
35
+ if socket.url == "/livereload"
36
+ # Ordering of handshake doesn't seem to matter
37
+ socket << @messaging.hello
38
+
39
+ if @messaging.valid_handshake?(socket.read)
40
+ @sockets.push(socket)
41
+ end
42
+ end
43
+ rescue Reel::SocketError
44
+ end
45
+
46
+ def handle_request(request)
47
+ if request.path == "/livereload.js"
48
+ livejs = File.expand_path("vendor/livereload.js", File.dirname(__FILE__))
49
+ request.respond(:ok, File.read(livejs))
50
+ else
51
+ request.respond(:not_found, "not found")
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ module Munge
2
+ module Extras
3
+ module Livereload
4
+ class UpdateClient
5
+ include Celluloid
6
+ include Celluloid::Notifications
7
+
8
+ def initialize(webserver)
9
+ @webserver = webserver
10
+ subscribe("changed_files", :notify_reload)
11
+ end
12
+
13
+ def notify_reload(_topic, changed_files)
14
+ @webserver.notify_reload(changed_files)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Munge
2
+ module Extras
3
+ module Livereload
4
+ class UpdateServer
5
+ include Celluloid
6
+ include Celluloid::Notifications
7
+
8
+ def notify(files = [])
9
+ publish("changed_files", files)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end