hotwire-livereload 0.1.4 → 1.1.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 +72 -7
- data/app/assets/javascripts/hotwire-livereload.js +9 -3
- data/app/javascript/hotwire-livereload.js +10 -3
- data/lib/hotwire/livereload/engine.rb +33 -10
- data/lib/hotwire/livereload/version.rb +1 -1
- data/lib/hotwire/livereload.rb +1 -0
- data/lib/install/install.rb +13 -5
- data/lib/tasks/livereload_tasks.rake +21 -0
- metadata +5 -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: b6e414e66bbb4fbc76eef6000651aad79952f8f51ea70f19970691c780af09c2
|
4
|
+
data.tar.gz: 76540592b6138efb0365019b43ef04751a7071037f62814babbd05e96ff5bf01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bac450b366a58fe90bdadfdab8898f9592681bc97ff1d1cc2450db0be1fee0f6b32fadce34c5c66fb709266a7283932bee827413b56671ab36b72564238b6447
|
7
|
+
data.tar.gz: acd23ee5a23fce850579b5604ae2d5a2bd4c4d12134bf10bfd0a442a0dcdf96a396aa9bcbdda3aab2953f89d0d7988231cba40ace417c72ce8e37bd79045523a
|
data/README.md
CHANGED
@@ -1,16 +1,81 @@
|
|
1
1
|
# Hotwire::Livereload
|
2
2
|
|
3
|
-
Automatically reload Hotwire Turbo when
|
3
|
+
Automatically reload Hotwire Turbo when app files are modified.
|
4
4
|
|
5
|
-
https://user-images.githubusercontent.com/839922/
|
5
|
+
https://user-images.githubusercontent.com/839922/148676469-0acfa036-832e-4b40-aa05-1fdd945baa1f.mp4
|
6
6
|
|
7
|
-
##
|
7
|
+
## Gettings
|
8
8
|
|
9
|
-
|
9
|
+
Add `hotwire-livereload` to your Gemfile:
|
10
|
+
```
|
11
|
+
bundle add hotwire-livereload --group development
|
12
|
+
```
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
Run installer:
|
15
|
+
```
|
16
|
+
rails livereload:install
|
17
|
+
```
|
18
|
+
|
19
|
+
Folders listened by default:
|
20
|
+
- `app/views`
|
21
|
+
- `app/helpers`
|
22
|
+
- `app/javascript`
|
23
|
+
- `app/assets/stylesheets`
|
24
|
+
- `app/assets/javascripts`
|
25
|
+
- `app/assets/images`
|
26
|
+
- `app/components`
|
27
|
+
- `config/locales`
|
28
|
+
|
29
|
+
## Configuration
|
30
|
+
|
31
|
+
You can watch for changes in additional folders by adding them to `listen_paths`:
|
32
|
+
```ruby
|
33
|
+
# config/environments/development.rb
|
34
|
+
|
35
|
+
Rails.application.configure do
|
36
|
+
# ...
|
37
|
+
config.hotwire_livereload.listen_paths << Rails.root.join("app/custom_folder")
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
You can disable default listen paths and fully override them:
|
42
|
+
```ruby
|
43
|
+
# config/environments/development.rb
|
44
|
+
|
45
|
+
Rails.application.configure do
|
46
|
+
# ...
|
47
|
+
config.hotwire_livereload.disable_default_listeners = true
|
48
|
+
config.hotwire_livereload.listen_paths = [
|
49
|
+
Rails.root.join("app/assets/stylesheets"),
|
50
|
+
Rails.root.join("app/javascript")
|
51
|
+
]
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
If you don't have `data-turbo-track="reload"` attribute on your JS and CSS bundles you might need to setup force reloading. This will trigger full browser reloading for JS and CSS files only:
|
56
|
+
```ruby
|
57
|
+
# config/environments/development.rb
|
58
|
+
|
59
|
+
Rails.application.configure do
|
60
|
+
# ...
|
61
|
+
config.hotwire_livereload.force_reload_paths << Rails.root.join("app/assets/stylesheets")
|
62
|
+
config.hotwire_livereload.force_reload_paths << Rails.root.join("app/javascript")
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
## Disable livereload
|
67
|
+
|
68
|
+
To temporarily disable livereload use:
|
69
|
+
```bash
|
70
|
+
bin/rails livereload:disable
|
71
|
+
```
|
72
|
+
|
73
|
+
To re-enable:
|
74
|
+
```bash
|
75
|
+
bin/rails livereload:enable
|
76
|
+
```
|
77
|
+
|
78
|
+
No server restart is required. Disabling is managed by `tmp/livereload-disabled.txt` file.
|
14
79
|
|
15
80
|
## Development
|
16
81
|
|
@@ -601,9 +601,15 @@
|
|
601
601
|
var import_actioncable = __toModule(require_action_cable());
|
602
602
|
var import_debounce = __toModule(require_debounce());
|
603
603
|
var consumer = (0, import_actioncable.createConsumer)();
|
604
|
-
var received = (0, import_debounce.default)(() => {
|
605
|
-
|
606
|
-
|
604
|
+
var received = (0, import_debounce.default)(({ force_reload }) => {
|
605
|
+
const onErrorPage = document.title === "Action Controller: Exception caught";
|
606
|
+
if (onErrorPage || force_reload) {
|
607
|
+
console.log("[Hotwire::Livereload] Files changed. Force reloading..");
|
608
|
+
document.location.reload();
|
609
|
+
} else {
|
610
|
+
console.log("[Hotwire::Livereload] Files changed. Reloading..");
|
611
|
+
Turbo.visit(window.location.href);
|
612
|
+
}
|
607
613
|
}, 300);
|
608
614
|
consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
|
609
615
|
received,
|
@@ -2,9 +2,16 @@ import { createConsumer } from "@rails/actioncable"
|
|
2
2
|
import debounce from "debounce"
|
3
3
|
|
4
4
|
const consumer = createConsumer()
|
5
|
-
const received = debounce(() => {
|
6
|
-
|
7
|
-
|
5
|
+
const received = debounce(({force_reload}) => {
|
6
|
+
const onErrorPage = document.title === "Action Controller: Exception caught"
|
7
|
+
|
8
|
+
if (onErrorPage || force_reload) {
|
9
|
+
console.log("[Hotwire::Livereload] Files changed. Force reloading..")
|
10
|
+
document.location.reload()
|
11
|
+
} else {
|
12
|
+
console.log("[Hotwire::Livereload] Files changed. Reloading..")
|
13
|
+
Turbo.visit(window.location.href)
|
14
|
+
}
|
8
15
|
}, 300)
|
9
16
|
|
10
17
|
consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
|
@@ -8,6 +8,8 @@ module Hotwire
|
|
8
8
|
isolate_namespace Hotwire::Livereload
|
9
9
|
config.hotwire_livereload = ActiveSupport::OrderedOptions.new
|
10
10
|
config.hotwire_livereload.listen_paths ||= []
|
11
|
+
config.hotwire_livereload.force_reload_paths ||= []
|
12
|
+
config.hotwire_livereload.disable_default_listeners = false
|
11
13
|
config.autoload_once_paths = %W(
|
12
14
|
#{root}/app/channels
|
13
15
|
#{root}/app/helpers
|
@@ -27,20 +29,41 @@ module Hotwire
|
|
27
29
|
|
28
30
|
initializer "hotwire_livereload.set_configs" do |app|
|
29
31
|
options = app.config.hotwire_livereload
|
30
|
-
|
31
|
-
options.
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
|
33
|
+
unless options.disable_default_listeners
|
34
|
+
default_listen_paths = %w[
|
35
|
+
app/views
|
36
|
+
app/helpers
|
37
|
+
app/javascript
|
38
|
+
app/assets/stylesheets
|
39
|
+
app/assets/javascripts
|
40
|
+
app/assets/images
|
41
|
+
app/components
|
42
|
+
config/locales
|
43
|
+
].map { |p| Rails.root.join(p) }
|
44
|
+
options.listen_paths += default_listen_paths.select { |p| Dir.exist?(p) }
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
38
48
|
config.after_initialize do |app|
|
39
|
-
if Rails.env.development?
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
49
|
+
if Rails.env.development? && defined?(Rails::Server)
|
50
|
+
options = app.config.hotwire_livereload
|
51
|
+
listen_paths = options.listen_paths.map(&:to_s).uniq
|
52
|
+
force_reload_paths = options.force_reload_paths.map(&:to_s).uniq.join("|")
|
53
|
+
|
54
|
+
@listener = Listen.to(*listen_paths) do |modified, added, removed|
|
55
|
+
unless File.exists?(DISABLE_FILE)
|
56
|
+
changed = [modified, removed, added].flatten.uniq
|
57
|
+
return unless changed.any?
|
58
|
+
|
59
|
+
force_reload = force_reload_paths.present? && changed.any? do |path|
|
60
|
+
path.match(%r{#{force_reload_paths}})
|
61
|
+
end
|
62
|
+
|
63
|
+
ActionCable.server.broadcast("hotwire-reload", {
|
64
|
+
changed: changed,
|
65
|
+
force_reload: force_reload
|
66
|
+
})
|
44
67
|
end
|
45
68
|
end
|
46
69
|
@listener.start
|
data/lib/hotwire/livereload.rb
CHANGED
data/lib/install/install.rb
CHANGED
@@ -3,18 +3,26 @@ CABLE_CONFIG_PATH = Rails.root.join("config/cable.yml")
|
|
3
3
|
|
4
4
|
if APP_LAYOUT_PATH.exist?
|
5
5
|
say "Add Hotwire Livereload tag in application layout"
|
6
|
-
|
7
|
-
\n
|
6
|
+
content = <<-HTML
|
7
|
+
\n <% if Rails.env.development? %>
|
8
|
+
<%= javascript_include_tag "hotwire-livereload", defer: true %>
|
9
|
+
<% end %>
|
8
10
|
HTML
|
9
|
-
|
11
|
+
insert_into_file APP_LAYOUT_PATH, content.chop, before: /\s*<\/head>/
|
10
12
|
else
|
11
13
|
say "Default application.html.erb is missing!", :red
|
12
14
|
say %( Add <%= hotwire_livereload_tags %> within the <head> tag in your custom layout.)
|
13
15
|
end
|
14
16
|
|
15
17
|
if CABLE_CONFIG_PATH.exist?
|
16
|
-
|
17
|
-
|
18
|
+
gemfile = File.read(Rails.root.join("Gemfile"))
|
19
|
+
if gemfile.include?("redis")
|
20
|
+
say "Uncomment redis in Gemfile"
|
21
|
+
uncomment_lines "Gemfile", %(gem "redis")
|
22
|
+
else
|
23
|
+
say "Add redis to Gemfile"
|
24
|
+
gem "redis"
|
25
|
+
end
|
18
26
|
|
19
27
|
say "Switch development cable to use redis"
|
20
28
|
gsub_file CABLE_CONFIG_PATH.to_s, /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
|
@@ -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:
|
4
|
+
version: 1.1.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:
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -55,7 +55,7 @@ files:
|
|
55
55
|
- lib/hotwire/livereload/engine.rb
|
56
56
|
- lib/hotwire/livereload/version.rb
|
57
57
|
- lib/install/install.rb
|
58
|
-
- lib/tasks/
|
58
|
+
- lib/tasks/livereload_tasks.rake
|
59
59
|
homepage: https://github.com/kirillplatonov/hotwire-livereload
|
60
60
|
licenses:
|
61
61
|
- MIT
|
@@ -75,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.2.
|
78
|
+
rubygems_version: 3.2.32
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
|
-
summary: Automatically reload Hotwire Turbo when
|
81
|
+
summary: Automatically reload Hotwire Turbo when app files are modified.
|
82
82
|
test_files: []
|