hotwire-livereload 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -1
- data/app/assets/javascripts/hotwire-livereload.js +4 -6
- data/app/channels/hotwire/livereload/reload_channel.rb +1 -1
- data/app/javascript/hotwire-livereload.js +6 -6
- data/lib/hotwire/livereload/engine.rb +11 -27
- data/lib/hotwire/livereload/version.rb +1 -1
- data/lib/hotwire/livereload.rb +1 -0
- data/lib/install/install.rb +16 -5
- data/lib/tasks/livereload_tasks.rake +21 -0
- metadata +3 -6
- data/app/channels/hotwire/livereload/connection.rb +0 -9
- data/config/livereload_cable.yml +0 -2
- data/config/routes.rb +0 -5
- data/lib/tasks/hotwire/livereload/install.rake +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05ad19b6e77492fec265a2da6af3ddd9aa8b7b149ae284397644db40b553974b
|
4
|
+
data.tar.gz: 7f497acf2a34e1774d80c7a2fa1030b6a2eb9228cc2fe257b73a7cdad0e912fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 554901b08d7d257da5660c5020cbfb8bab03e987eff1d329337fa9943119c6e3a8bead3bc62c97edec32250f7c0bb5503b7d306373e794bd7908a208f211284a
|
7
|
+
data.tar.gz: 8e213677c64df89f7903d672c421b7faa9d8a5d12e136ef24e92e7dbc1a0deedc650d92cd882b06627f20e89ddcd4d46ea72943e22cf035152b9aff2e3284c02
|
data/README.md
CHANGED
@@ -10,7 +10,34 @@ The JavaScript for Hotwire::Livereload is installed via asset pipeline, which is
|
|
10
10
|
|
11
11
|
1. Add `hotwire-livereload` gem to your Gemfile: `gem 'hotwire-livereload'`
|
12
12
|
2. Run `./bin/bundle install`
|
13
|
-
3. Run `./bin/rails
|
13
|
+
3. Run `./bin/rails livereload:install`
|
14
|
+
|
15
|
+
## Configuration
|
16
|
+
|
17
|
+
You can watch for changes in additional folders by adding them to `listen_paths`. For example, you can watch for CSS changes:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
# config/environments/development.rb
|
21
|
+
|
22
|
+
Rails.application.configure do
|
23
|
+
# ...
|
24
|
+
config.hotwire_livereload.listen_paths << Rails.root.join("app/assets/stylesheets")
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
## Disable livereload
|
29
|
+
|
30
|
+
To temporarily disable livereload use:
|
31
|
+
```bash
|
32
|
+
bin/rails livereload:disable
|
33
|
+
```
|
34
|
+
|
35
|
+
To re-enable:
|
36
|
+
```bash
|
37
|
+
bin/rails livereload:enable
|
38
|
+
```
|
39
|
+
|
40
|
+
No server restart is required. Disabling is managed by `tmp/livereload-disabled.txt` file.
|
14
41
|
|
15
42
|
## Development
|
16
43
|
|
@@ -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
|
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
|
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
|
611
|
+
console.log("[Hotwire::Livereload] Websocket connected");
|
614
612
|
},
|
615
613
|
disconnected() {
|
616
|
-
console.log("Hotwire::Livereload
|
614
|
+
console.log("[Hotwire::Livereload] Websocket disconnected");
|
617
615
|
}
|
618
616
|
});
|
619
617
|
})();
|
@@ -1,20 +1,20 @@
|
|
1
1
|
import { createConsumer } from "@rails/actioncable"
|
2
2
|
import debounce from "debounce"
|
3
3
|
|
4
|
-
const
|
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
|
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
|
14
|
+
console.log("[Hotwire::Livereload] Websocket connected")
|
16
15
|
},
|
16
|
+
|
17
17
|
disconnected() {
|
18
|
-
console.log("Hotwire::Livereload
|
18
|
+
console.log("[Hotwire::Livereload] Websocket disconnected")
|
19
19
|
},
|
20
20
|
})
|
@@ -28,27 +28,21 @@ 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
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
if Rails.env.development?
|
39
|
+
if Rails.env.development? && defined?(Rails::Server)
|
46
40
|
@listener = Listen.to(*app.config.hotwire_livereload.listen_paths) do |modified, added, removed|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
unless File.exists?(DISABLE_FILE)
|
42
|
+
if (modified.any? || removed.any? || added.any?)
|
43
|
+
content = { modified: modified, removed: removed, added: added }
|
44
|
+
ActionCable.server.broadcast("hotwire-reload", content)
|
45
|
+
end
|
52
46
|
end
|
53
47
|
end
|
54
48
|
@listener.start
|
@@ -60,16 +54,6 @@ module Hotwire
|
|
60
54
|
@listener&.stop
|
61
55
|
end
|
62
56
|
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
|
71
|
-
end
|
72
|
-
end
|
73
57
|
end
|
74
58
|
end
|
75
59
|
end
|
data/lib/hotwire/livereload.rb
CHANGED
data/lib/install/install.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
|
-
|
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
|
4
|
-
say "Add Hotwire
|
5
|
-
insert_into_file
|
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 %(
|
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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :livereload do
|
2
|
+
desc "Install Hotwire::Livereload into the app"
|
3
|
+
task :install do
|
4
|
+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Disable Hotwire::Livereload"
|
8
|
+
task :disable do
|
9
|
+
FileUtils.mkdir_p("tmp")
|
10
|
+
FileUtils.touch Hotwire::Livereload::DISABLE_FILE
|
11
|
+
puts "Livereload disabled."
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Enable Hotwire::Livereload"
|
15
|
+
task :enable do
|
16
|
+
if File.exist?(Hotwire::Livereload::DISABLE_FILE)
|
17
|
+
File.delete Hotwire::Livereload::DISABLE_FILE
|
18
|
+
end
|
19
|
+
puts "Livereload enabled."
|
20
|
+
end
|
21
|
+
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2021-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -48,17 +48,14 @@ 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
|
60
57
|
- lib/install/install.rb
|
61
|
-
- lib/tasks/
|
58
|
+
- lib/tasks/livereload_tasks.rake
|
62
59
|
homepage: https://github.com/kirillplatonov/hotwire-livereload
|
63
60
|
licenses:
|
64
61
|
- MIT
|
data/config/livereload_cable.yml
DELETED
data/config/routes.rb
DELETED