hotwire-livereload 0.1.0 → 0.1.4

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
  SHA256:
3
- metadata.gz: e80daa28376d668cb49288182ab69de36a544c0367deab64359e99d1b1c5cb8e
4
- data.tar.gz: ba7057fa9ce97ea7801b5c993ff3172ff0fb0ba7820474fb0be467c01900d333
3
+ metadata.gz: 3f8001c1b5e1ae699af050da2c601fd29ee3242cdcdd87f1487b38d18a395978
4
+ data.tar.gz: 0fa2a43353fceb7e14908d1130cb7fcea7c71b59846888c3845e91922b5ac833
5
5
  SHA512:
6
- metadata.gz: 4eb10a968fa542b584bdd0184be9ecf6740b2633d2481f61df65681b7e476ae8273770d58b9a3a56d05baf6c2773d9fb9e9508263e179f3954d9fe86604b7d18
7
- data.tar.gz: 34a454aa9316357d37b89754394457b06ad5c3cf4b694bee5ce0e954d072b8f535341811c3d613a0f4f5114463e9e0239a6c2db98c3005eedb47db96af4ec803
6
+ metadata.gz: 7202fa592b12ab9ef913d0fc62979b998a53357f9d74731df1fe1990ebe1f358a628509ae4a6010ee8dec1fbcadb60281bf9e62def1e829da728af9eeb211684
7
+ data.tar.gz: 7b3b8dd4a60f103f2f2b9c673ceab137855a9ceaf583a6ed564384d1e1f617a80b06c7e751d09cdf801d583c7bea9ed60801accce6cd0c11203a1f0b9e996922
@@ -600,20 +600,18 @@
600
600
  // app/javascript/hotwire-livereload.js
601
601
  var import_actioncable = __toModule(require_action_cable());
602
602
  var import_debounce = __toModule(require_debounce());
603
- var endpoint = "/hotwire-livereload/cable";
604
- var uid = (Date.now() + (Math.random() * 100 | 0)).toString();
605
- var consumer = (0, import_actioncable.createConsumer)(`${endpoint}?uid=${uid}`);
603
+ var consumer = (0, import_actioncable.createConsumer)();
606
604
  var received = (0, import_debounce.default)(() => {
607
- console.log("Hotwire::Livereload files changed");
605
+ console.log("[Hotwire::Livereload] Files changed");
608
606
  Turbo.visit(window.location.href);
609
607
  }, 300);
610
608
  consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
611
609
  received,
612
610
  connected() {
613
- console.log("Hotwire::Livereload websocket connected");
611
+ console.log("[Hotwire::Livereload] Websocket connected");
614
612
  },
615
613
  disconnected() {
616
- console.log("Hotwire::Livereload websocket disconnected");
614
+ console.log("[Hotwire::Livereload] Websocket disconnected");
617
615
  }
618
616
  });
619
617
  })();
@@ -1,5 +1,5 @@
1
1
  class Hotwire::Livereload::ReloadChannel < ActionCable::Channel::Base
2
2
  def subscribed
3
- stream_from "reload"
3
+ stream_from "hotwire-reload"
4
4
  end
5
5
  end
@@ -1,20 +1,20 @@
1
1
  import { createConsumer } from "@rails/actioncable"
2
2
  import debounce from "debounce"
3
3
 
4
- const endpoint = "/hotwire-livereload/cable"
5
- const uid = (Date.now() + ((Math.random() * 100) | 0)).toString()
6
- const consumer = createConsumer(`${endpoint}?uid=${uid}`)
4
+ const consumer = createConsumer()
7
5
  const received = debounce(() => {
8
- console.log("Hotwire::Livereload files changed")
6
+ console.log("[Hotwire::Livereload] Files changed")
9
7
  Turbo.visit(window.location.href)
10
8
  }, 300)
11
9
 
12
10
  consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
13
11
  received,
12
+
14
13
  connected() {
15
- console.log("Hotwire::Livereload websocket connected")
14
+ console.log("[Hotwire::Livereload] Websocket connected")
16
15
  },
16
+
17
17
  disconnected() {
18
- console.log("Hotwire::Livereload websocket disconnected")
18
+ console.log("[Hotwire::Livereload] Websocket disconnected")
19
19
  },
20
20
  })
@@ -28,46 +28,28 @@ module Hotwire
28
28
  initializer "hotwire_livereload.set_configs" do |app|
29
29
  options = app.config.hotwire_livereload
30
30
  options.listen_paths = options.listen_paths.map(&:to_s)
31
- options.listen_paths << Rails.root.join("app", "views")
32
- end
33
-
34
- initializer "hotwire_livereload.cable.config" do |app|
35
- config_path = Hotwire::Livereload::Engine.root.join("config", "livereload_cable.yml")
36
- cable = Hotwire::Livereload::Engine.cable
37
-
38
- cable.cable = app.config_for(config_path).with_indifferent_access
39
- cable.mount_path = "/cable"
40
- cable.connection_class = -> { Hotwire::Livereload::Connection }
41
- cable.logger ||= Rails.logger
31
+ options.listen_paths << Rails.root.join("app/views")
32
+ options.listen_paths << Rails.root.join("app/helpers")
33
+ if Dir.exist?(Rails.root.join("app/javascript"))
34
+ options.listen_paths << Rails.root.join("app/javascript")
35
+ end
42
36
  end
43
37
 
44
38
  config.after_initialize do |app|
45
- return unless Rails.env.development?
46
-
47
- @listener = Listen.to(*app.config.hotwire_livereload.listen_paths) do |modified, added, removed|
48
- if modified.any? || removed.any? || added.any?
49
- Hotwire::Livereload::Engine.websocket.broadcast(
50
- "reload",
51
- { modified: modified, removed: removed, added: added }
52
- )
39
+ if Rails.env.development?
40
+ @listener = Listen.to(*app.config.hotwire_livereload.listen_paths) do |modified, added, removed|
41
+ if modified.any? || removed.any? || added.any?
42
+ content = { modified: modified, removed: removed, added: added }
43
+ ActionCable.server.broadcast("hotwire-reload", content)
44
+ end
53
45
  end
46
+ @listener.start
54
47
  end
55
- @listener.start
56
48
  end
57
49
 
58
50
  at_exit do
59
- return unless Rails.env.development?
60
-
61
- @listener&.stop
62
- end
63
-
64
- class << self
65
- def websocket
66
- @websocket ||= ActionCable::Server::Base.new(config: Hotwire::Livereload::Engine.cable)
67
- end
68
-
69
- def cable
70
- @cable ||= ActionCable::Server::Configuration.new
51
+ if Rails.env.development?
52
+ @listener&.stop
71
53
  end
72
54
  end
73
55
  end
@@ -1,5 +1,5 @@
1
1
  module Hotwire
2
2
  module Livereload
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -1,12 +1,23 @@
1
- route("mount Hotwire::Livereload::Engine, at: '/hotwire-livereload'")
1
+ APP_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
2
+ CABLE_CONFIG_PATH = Rails.root.join("config/cable.yml")
2
3
 
3
- if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
4
- say "Add Hotwire::Livereload tag in application layout"
5
- insert_into_file app_layout_path.to_s, before: /\s*<\/head>/ do <<-HTML
4
+ if APP_LAYOUT_PATH.exist?
5
+ say "Add Hotwire Livereload tag in application layout"
6
+ insert_into_file APP_LAYOUT_PATH, before: /\s*<\/head>/ do <<-HTML
6
7
  \n <%= hotwire_livereload_tags %>
7
8
  HTML
8
9
  end
9
10
  else
10
11
  say "Default application.html.erb is missing!", :red
11
- say %( Add <%= hotwire_livereload_tags %> within the <head> tag in your custom layout.)
12
+ say %( Add <%= hotwire_livereload_tags %> within the <head> tag in your custom layout.)
13
+ end
14
+
15
+ if CABLE_CONFIG_PATH.exist?
16
+ say "Enable redis in bundle"
17
+ uncomment_lines "Gemfile", %(gem 'redis')
18
+
19
+ say "Switch development cable to use redis"
20
+ gsub_file CABLE_CONFIG_PATH.to_s, /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
21
+ else
22
+ say 'ActionCable config file (config/cable.yml) is missing. Uncomment "gem \'redis\'" in your Gemfile and create config/cable.yml to use Hotwire Livereload.'
12
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire-livereload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Platonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-03 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -48,12 +48,9 @@ files:
48
48
  - MIT-LICENSE
49
49
  - README.md
50
50
  - app/assets/javascripts/hotwire-livereload.js
51
- - app/channels/hotwire/livereload/connection.rb
52
51
  - app/channels/hotwire/livereload/reload_channel.rb
53
52
  - app/helpers/hotwire/livereload/livereload_tags_helper.rb
54
53
  - app/javascript/hotwire-livereload.js
55
- - config/livereload_cable.yml
56
- - config/routes.rb
57
54
  - lib/hotwire/livereload.rb
58
55
  - lib/hotwire/livereload/engine.rb
59
56
  - lib/hotwire/livereload/version.rb
@@ -1,9 +0,0 @@
1
- class Hotwire::Livereload::Connection < ActionCable::Connection::Base
2
- identified_by :uid
3
-
4
- def connect
5
- self.uid = request.params[:uid]
6
- logger.add_tags(uid)
7
- logger.info "connected to Hotwire::Livereload"
8
- end
9
- end
@@ -1,2 +0,0 @@
1
- development:
2
- adapter: async
data/config/routes.rb DELETED
@@ -1,5 +0,0 @@
1
- Hotwire::Livereload::Engine.routes.draw do
2
- if Rails.env.development?
3
- mount Hotwire::Livereload::Engine.websocket => Hotwire::Livereload::Engine.cable.mount_path
4
- end
5
- end