cable_ready 5.0.3 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/cable_ready.gemspec +1 -0
- data/lib/cable_ready/installer.rb +196 -169
- data/lib/cable_ready/version.rb +1 -1
- data/lib/install/action_cable.rb +29 -29
- data/lib/install/broadcaster.rb +13 -13
- data/lib/install/bundle.rb +9 -9
- data/lib/install/compression.rb +7 -7
- data/lib/install/config.rb +17 -17
- data/lib/install/development.rb +6 -6
- data/lib/install/esbuild.rb +28 -28
- data/lib/install/importmap.rb +25 -25
- data/lib/install/initializers.rb +2 -2
- data/lib/install/mrujs.rb +22 -22
- data/lib/install/npm_packages.rb +4 -4
- data/lib/install/shakapacker.rb +21 -21
- data/lib/install/spring.rb +7 -7
- data/lib/install/updatable.rb +7 -7
- data/lib/install/vite.rb +21 -21
- data/lib/install/webpacker.rb +22 -22
- data/lib/install/yarn.rb +9 -9
- data/yarn.lock +156 -306
- metadata +17 -8
- data/app/assets/javascripts/cable_ready.min.js +0 -2
- data/app/assets/javascripts/cable_ready.min.js.map +0 -1
- data/app/assets/javascripts/cable_ready.umd.min.js +0 -2
- data/app/assets/javascripts/cable_ready.umd.min.js.map +0 -1
- data/cable_ready.gemspec~ +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 370257c592bcb4dda3a9466cee960208bf00f23e9966d6bfbc74b5976f7aca93
|
4
|
+
data.tar.gz: a6d333775454cc46d636f0c0c0707449f9b31072307f8fbad7c8ccd565671de2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dca231343c358d9c33efe88ea21a05f1fec27f45c3d85cc34aed968aa6df7d6ae82beb754606504412ab18690f6b4a13811dee00f069748129bbaf8ed6ac8bd0
|
7
|
+
data.tar.gz: db45207f865f503508a0e0603e830c33f8c2b0c27e94af62d0f786fbdc6847242e1151ffafbe9524f186ea83b83bd2dc531e094df8776c690ae8b0d8a970ec07
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cable_ready (5.0.
|
4
|
+
cable_ready (5.0.4)
|
5
5
|
actionpack (>= 5.2)
|
6
6
|
actionview (>= 5.2)
|
7
7
|
activesupport (>= 5.2)
|
8
|
+
observer (~> 0.1)
|
8
9
|
railties (>= 5.2)
|
9
10
|
thread-local (>= 1.1.0)
|
10
11
|
|
@@ -114,6 +115,7 @@ GEM
|
|
114
115
|
racc (~> 1.4)
|
115
116
|
nokogiri (1.14.3-x86_64-linux)
|
116
117
|
racc (~> 1.4)
|
118
|
+
observer (0.1.2)
|
117
119
|
parallel (1.22.1)
|
118
120
|
parser (3.2.1.0)
|
119
121
|
ast (~> 2.4.1)
|
data/cable_ready.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |gem|
|
|
28
28
|
gem.add_dependency "activesupport", rails_version
|
29
29
|
gem.add_dependency "railties", rails_version
|
30
30
|
gem.add_dependency "thread-local", ">= 1.1.0"
|
31
|
+
gem.add_dependency "observer", "~> 0.1"
|
31
32
|
|
32
33
|
gem.add_development_dependency "magic_frozen_string_literal"
|
33
34
|
gem.add_development_dependency "mocha"
|
@@ -2,223 +2,250 @@
|
|
2
2
|
|
3
3
|
require "cable_ready/version"
|
4
4
|
|
5
|
-
|
5
|
+
module CableReady
|
6
|
+
class Installer
|
7
|
+
include Thor::Base
|
8
|
+
include Thor::Actions
|
6
9
|
|
7
|
-
|
8
|
-
relative_path = step_path + file
|
9
|
-
location = template_src + relative_path
|
10
|
+
source_root Dir.pwd
|
10
11
|
|
11
|
-
|
12
|
-
end
|
12
|
+
## Thor wrapper
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
end
|
14
|
+
def self.create_file(...)
|
15
|
+
new.create_file(...)
|
16
|
+
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
def self.append_file(...)
|
19
|
+
new.append_file(...)
|
20
|
+
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
25
|
-
end
|
22
|
+
def self.copy_file(...)
|
23
|
+
new.copy_file(...)
|
24
|
+
end
|
26
25
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
end
|
26
|
+
def self.say(...)
|
27
|
+
new.say(...)
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
say "❌ #{message}", :red
|
34
|
-
create_file "tmp/cable_ready_installer/halt", verbose: false
|
35
|
-
end
|
30
|
+
### general utilities
|
36
31
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
return
|
41
|
-
end
|
32
|
+
def self.fetch(step_path, file)
|
33
|
+
relative_path = step_path + file
|
34
|
+
location = template_src + relative_path
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
filename = path.to_path.split("/").last
|
36
|
+
Pathname.new(location)
|
37
|
+
end
|
46
38
|
|
47
|
-
|
48
|
-
|
49
|
-
path.delete if delete
|
50
|
-
yield
|
51
|
-
return
|
39
|
+
def self.complete_step(step)
|
40
|
+
create_file "tmp/cable_ready_installer/#{step}", verbose: false
|
52
41
|
end
|
53
|
-
backup_path.delete
|
54
|
-
end
|
55
42
|
|
56
|
-
|
57
|
-
|
43
|
+
def self.create_or_append(path, *args, &block)
|
44
|
+
FileUtils.touch(path)
|
45
|
+
append_file(path, *args, &block)
|
46
|
+
end
|
58
47
|
|
59
|
-
|
48
|
+
def self.current_template
|
49
|
+
ENV["LOCATION"].split("/").last.gsub(".rb", "")
|
50
|
+
end
|
60
51
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
52
|
+
def self.pack_path_missing?
|
53
|
+
return false unless pack_path.nil?
|
54
|
+
halt "#{friendly_pack_path} is missing. You need a valid application pack file to proceed."
|
55
|
+
end
|
66
56
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
end
|
57
|
+
def self.halt(message)
|
58
|
+
say "❌ #{message}", :red
|
59
|
+
create_file "tmp/cable_ready_installer/halt", verbose: false
|
60
|
+
end
|
71
61
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
62
|
+
def self.backup(path, delete: false)
|
63
|
+
if !path.exist?
|
64
|
+
yield
|
65
|
+
return
|
66
|
+
end
|
67
|
+
|
68
|
+
backup_path = Pathname.new("#{path}.bak")
|
69
|
+
old_path = path.relative_path_from(Rails.root).to_s
|
70
|
+
filename = path.to_path.split("/").last
|
71
|
+
|
72
|
+
if backup_path.exist?
|
73
|
+
if backup_path.read == path.read
|
74
|
+
path.delete if delete
|
75
|
+
yield
|
76
|
+
return
|
77
|
+
end
|
78
|
+
backup_path.delete
|
79
|
+
end
|
80
|
+
|
81
|
+
copy_file(path, backup_path, verbose: false)
|
82
|
+
path.delete if delete
|
76
83
|
|
77
|
-
|
78
|
-
create_or_append(package_list, "#{name}\n", verbose: false)
|
79
|
-
say "☑️ Enqueued #{name} to be added to dependencies"
|
80
|
-
end
|
84
|
+
yield
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
if path.read != backup_path.read
|
87
|
+
create_or_append(backups_path, "#{old_path}\n", verbose: false)
|
88
|
+
end
|
89
|
+
say "📦 #{old_path} backed up as #{filename}.bak"
|
90
|
+
end
|
86
91
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
end
|
92
|
+
def self.add_gem(name)
|
93
|
+
create_or_append(add_gem_list, "#{name}\n", verbose: false)
|
94
|
+
say "☑️ Added #{name} to the Gemfile"
|
95
|
+
end
|
91
96
|
|
92
|
-
def
|
93
|
-
|
94
|
-
|
97
|
+
def self.remove_gem(name)
|
98
|
+
create_or_append(remove_gem_list, "#{name}\n", verbose: false)
|
99
|
+
say "❎ Removed #{name} from Gemfile"
|
100
|
+
end
|
95
101
|
|
96
|
-
|
102
|
+
def self.add_package(name)
|
103
|
+
create_or_append(package_list, "#{name}\n", verbose: false)
|
104
|
+
say "☑️ Enqueued #{name} to be added to dependencies"
|
105
|
+
end
|
97
106
|
|
98
|
-
def
|
99
|
-
|
100
|
-
|
107
|
+
def self.add_dev_package(name)
|
108
|
+
create_or_append(dev_package_list, "#{name}\n", verbose: false)
|
109
|
+
say "☑️ Enqueued #{name} to be added to dev dependencies"
|
110
|
+
end
|
101
111
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
112
|
+
def self.drop_package(name)
|
113
|
+
create_or_append(drop_package_list, "#{name}\n", verbose: false)
|
114
|
+
say "❎ Enqueued #{name} to be removed from dependencies"
|
115
|
+
end
|
105
116
|
|
106
|
-
def
|
107
|
-
|
108
|
-
end
|
117
|
+
def self.gemfile_hash
|
118
|
+
Digest::MD5.hexdigest(gemfile_path.read)
|
119
|
+
end
|
109
120
|
|
110
|
-
|
111
|
-
@bundler ||= File.read("tmp/cable_ready_installer/bundler")
|
112
|
-
end
|
121
|
+
### memoized values
|
113
122
|
|
114
|
-
def
|
115
|
-
|
116
|
-
end
|
123
|
+
def self.cr_npm_version
|
124
|
+
@cr_npm_version ||= CableReady::VERSION.gsub(".pre", "-pre")
|
125
|
+
end
|
117
126
|
|
118
|
-
def
|
119
|
-
|
120
|
-
end
|
127
|
+
def self.package_json
|
128
|
+
@package_json ||= Rails.root.join("package.json")
|
129
|
+
end
|
121
130
|
|
122
|
-
def
|
123
|
-
|
124
|
-
end
|
131
|
+
def self.entrypoint
|
132
|
+
@entrypoint ||= File.read("tmp/cable_ready_installer/entrypoint")
|
133
|
+
end
|
125
134
|
|
126
|
-
def
|
127
|
-
|
128
|
-
end
|
135
|
+
def self.bundler
|
136
|
+
@bundler ||= File.read("tmp/cable_ready_installer/bundler")
|
137
|
+
end
|
129
138
|
|
130
|
-
def
|
131
|
-
|
132
|
-
end
|
139
|
+
def self.config_path
|
140
|
+
@config_path ||= Rails.root.join(entrypoint, "config")
|
141
|
+
end
|
133
142
|
|
134
|
-
def
|
135
|
-
|
136
|
-
|
137
|
-
Rails.root.join(entrypoint, "packs/application.js"),
|
138
|
-
Rails.root.join(entrypoint, "entrypoints/application.js")
|
139
|
-
].find(&:exist?)
|
140
|
-
end
|
143
|
+
def self.importmap_path
|
144
|
+
@importmap_path ||= Rails.root.join("config/importmap.rb")
|
145
|
+
end
|
141
146
|
|
142
|
-
def
|
143
|
-
|
144
|
-
end
|
147
|
+
def self.friendly_importmap_path
|
148
|
+
@friendly_importmap_path ||= importmap_path.relative_path_from(Rails.root).to_s
|
149
|
+
end
|
145
150
|
|
146
|
-
def
|
147
|
-
|
148
|
-
end
|
151
|
+
def self.pack
|
152
|
+
@pack ||= pack_path.read
|
153
|
+
end
|
149
154
|
|
150
|
-
def
|
151
|
-
|
152
|
-
end
|
155
|
+
def self.friendly_pack_path
|
156
|
+
@friendly_pack_path ||= pack_path.relative_path_from(Rails.root).to_s
|
157
|
+
end
|
153
158
|
|
154
|
-
def
|
155
|
-
|
156
|
-
|
159
|
+
def self.pack_path
|
160
|
+
@pack_path ||= [
|
161
|
+
Rails.root.join(entrypoint, "application.js"),
|
162
|
+
Rails.root.join(entrypoint, "packs/application.js"),
|
163
|
+
Rails.root.join(entrypoint, "entrypoints/application.js")
|
164
|
+
].find(&:exist?)
|
165
|
+
end
|
157
166
|
|
158
|
-
def
|
159
|
-
|
160
|
-
end
|
167
|
+
def self.package_list
|
168
|
+
@package_list ||= Rails.root.join("tmp/cable_ready_installer/npm_package_list")
|
169
|
+
end
|
161
170
|
|
162
|
-
def
|
163
|
-
|
164
|
-
end
|
171
|
+
def self.dev_package_list
|
172
|
+
@dev_package_list ||= Rails.root.join("tmp/cable_ready_installer/npm_dev_package_list")
|
173
|
+
end
|
165
174
|
|
166
|
-
def
|
167
|
-
|
168
|
-
end
|
175
|
+
def self.drop_package_list
|
176
|
+
@drop_package_list ||= Rails.root.join("tmp/cable_ready_installer/drop_npm_package_list")
|
177
|
+
end
|
169
178
|
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
"vite" => "..\/",
|
174
|
-
"webpacker" => "",
|
175
|
-
"shakapacker" => "",
|
176
|
-
"importmap" => "",
|
177
|
-
"esbuild" => ".\/"
|
178
|
-
}[bundler]
|
179
|
-
# standard:enable Style/RedundantStringEscape
|
180
|
-
end
|
179
|
+
def self.template_src
|
180
|
+
@template_src ||= File.read("tmp/cable_ready_installer/template_src")
|
181
|
+
end
|
181
182
|
|
182
|
-
def
|
183
|
-
|
184
|
-
end
|
183
|
+
def self.controllers_path
|
184
|
+
@controllers_path ||= Rails.root.join(entrypoint, "controllers")
|
185
|
+
end
|
185
186
|
|
186
|
-
def
|
187
|
-
|
188
|
-
end
|
187
|
+
def self.gemfile_path
|
188
|
+
@gemfile_path ||= Rails.root.join("Gemfile")
|
189
|
+
end
|
189
190
|
|
190
|
-
def
|
191
|
-
|
192
|
-
end
|
191
|
+
def self.gemfile
|
192
|
+
@gemfile ||= gemfile_path.read
|
193
|
+
end
|
193
194
|
|
194
|
-
def
|
195
|
-
|
196
|
-
|
195
|
+
def self.prefix
|
196
|
+
# standard:disable Style/RedundantStringEscape
|
197
|
+
@prefix ||= {
|
198
|
+
"vite" => "..\/",
|
199
|
+
"webpacker" => "",
|
200
|
+
"shakapacker" => "",
|
201
|
+
"importmap" => "",
|
202
|
+
"esbuild" => ".\/"
|
203
|
+
}[bundler]
|
204
|
+
# standard:enable Style/RedundantStringEscape
|
205
|
+
end
|
197
206
|
|
198
|
-
def
|
199
|
-
|
200
|
-
end
|
207
|
+
def self.application_record_path
|
208
|
+
@application_record_path ||= Rails.root.join("app/models/application_record.rb")
|
209
|
+
end
|
201
210
|
|
202
|
-
def
|
203
|
-
|
204
|
-
end
|
211
|
+
def self.action_cable_initializer_path
|
212
|
+
@action_cable_initializer_path ||= Rails.root.join("config/initializers/action_cable.rb")
|
213
|
+
end
|
205
214
|
|
206
|
-
def
|
207
|
-
|
208
|
-
end
|
215
|
+
def self.action_cable_initializer_working_path
|
216
|
+
@action_cable_initializer_working_path ||= Rails.root.join(working, "action_cable.rb")
|
217
|
+
end
|
209
218
|
|
210
|
-
def
|
211
|
-
|
212
|
-
end
|
219
|
+
def self.development_path
|
220
|
+
@development_path ||= Rails.root.join("config/environments/development.rb")
|
221
|
+
end
|
213
222
|
|
214
|
-
def
|
215
|
-
|
216
|
-
end
|
223
|
+
def self.development_working_path
|
224
|
+
@development_working_path ||= Rails.root.join(working, "development.rb")
|
225
|
+
end
|
217
226
|
|
218
|
-
def
|
219
|
-
|
220
|
-
end
|
227
|
+
def self.backups_path
|
228
|
+
@backups_path ||= Rails.root.join("tmp/cable_ready_installer/backups")
|
229
|
+
end
|
230
|
+
|
231
|
+
def self.add_gem_list
|
232
|
+
@add_gem_list ||= Rails.root.join("tmp/cable_ready_installer/add_gem_list")
|
233
|
+
end
|
234
|
+
|
235
|
+
def self.remove_gem_list
|
236
|
+
@remove_gem_list ||= Rails.root.join("tmp/cable_ready_installer/remove_gem_list")
|
237
|
+
end
|
221
238
|
|
222
|
-
def
|
223
|
-
|
239
|
+
def self.options_path
|
240
|
+
@options_path ||= Rails.root.join("tmp/cable_ready_installer/options")
|
241
|
+
end
|
242
|
+
|
243
|
+
def self.options
|
244
|
+
@options ||= YAML.safe_load(File.read(options_path))
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.working
|
248
|
+
@working ||= Rails.root.join("tmp/cable_ready_installer/working")
|
249
|
+
end
|
250
|
+
end
|
224
251
|
end
|
data/lib/cable_ready/version.rb
CHANGED
data/lib/install/action_cable.rb
CHANGED
@@ -6,11 +6,11 @@ require "cable_ready/installer"
|
|
6
6
|
if defined?(ActionCable::Engine)
|
7
7
|
say "✅ ActionCable::Engine is loaded and in scope"
|
8
8
|
else
|
9
|
-
halt "ActionCable::Engine is not loaded, please add or uncomment `require \"action_cable/engine\"` to your `config/application.rb`"
|
9
|
+
CableReady::Installer.halt "ActionCable::Engine is not loaded, please add or uncomment `require \"action_cable/engine\"` to your `config/application.rb`"
|
10
10
|
return
|
11
11
|
end
|
12
12
|
|
13
|
-
return if pack_path_missing?
|
13
|
+
return if CableReady::Installer.pack_path_missing?
|
14
14
|
|
15
15
|
# verify that the Action Cable pubsub config is created
|
16
16
|
cable_config = Rails.root.join("config/cable.yml")
|
@@ -35,7 +35,7 @@ elsif yaml["development"]["adapter"] == "async"
|
|
35
35
|
"url" => "<%= ENV.fetch(\"REDIS_URL\") { \"redis://localhost:6379/1\" } %>",
|
36
36
|
"channel_prefix" => "#{app_name}_development"
|
37
37
|
}
|
38
|
-
backup(cable_config) do
|
38
|
+
CableReady::Installer.backup(cable_config) do
|
39
39
|
cable_config.write(yaml.to_yaml)
|
40
40
|
end
|
41
41
|
say "✅ config/cable.yml was updated to use the redis adapter in development"
|
@@ -44,24 +44,24 @@ else
|
|
44
44
|
end
|
45
45
|
|
46
46
|
if Rails::VERSION::MAJOR >= 7
|
47
|
-
add_gem "redis@~> 5"
|
47
|
+
CableReady::Installer.add_gem "redis@~> 5"
|
48
48
|
else
|
49
|
-
add_gem "redis@~> 4"
|
49
|
+
CableReady::Installer.add_gem "redis@~> 4"
|
50
50
|
end
|
51
51
|
|
52
52
|
# install action-cable-redis-backport gem if using Action Cable < 7.1
|
53
53
|
unless ActionCable::VERSION::MAJOR >= 7 && ActionCable::VERSION::MINOR >= 1
|
54
|
-
if !gemfile.match?(/gem ['"]action-cable-redis-backport['"]/)
|
55
|
-
add_gem "action-cable-redis-backport@~> 1"
|
54
|
+
if !CableReady::Installer.gemfile.match?(/gem ['"]action-cable-redis-backport['"]/)
|
55
|
+
CableReady::Installer.add_gem "action-cable-redis-backport@~> 1"
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
# verify that the Action Cable channels folder and consumer class is available
|
60
60
|
step_path = "/app/javascript/channels/"
|
61
|
-
channels_path = Rails.root.join(entrypoint, "channels")
|
62
|
-
consumer_src = fetch(step_path, "consumer.js.tt")
|
61
|
+
channels_path = Rails.root.join(CableReady::Installer.entrypoint, "channels")
|
62
|
+
consumer_src = CableReady::Installer.fetch(step_path, "consumer.js.tt")
|
63
63
|
consumer_path = channels_path / "consumer.js"
|
64
|
-
index_src = fetch(step_path, "index.js.#{bundler}.tt")
|
64
|
+
index_src = CableReady::Installer.fetch(step_path, "index.js.#{CableReady::Installer.bundler}.tt")
|
65
65
|
index_path = channels_path / "index.js"
|
66
66
|
friendly_index_path = index_path.relative_path_from(Rails.root).to_s
|
67
67
|
|
@@ -73,7 +73,7 @@ if index_path.exist?
|
|
73
73
|
if index_path.read == index_src.read
|
74
74
|
say "✅ #{friendly_index_path} is present"
|
75
75
|
else
|
76
|
-
backup(index_path) do
|
76
|
+
CableReady::Installer.backup(index_path) do
|
77
77
|
copy_file(index_src, index_path, verbose: false)
|
78
78
|
end
|
79
79
|
say "✅ #{friendly_index_path} has been created"
|
@@ -85,43 +85,43 @@ end
|
|
85
85
|
# import Action Cable channels into application pack
|
86
86
|
channels_pattern = /import ['"](\.\.\/|\.\/)?channels['"]/
|
87
87
|
channels_commented_pattern = /\s*\/\/\s*#{channels_pattern}/
|
88
|
-
channel_import = "import \"#{prefix}channels\"\n"
|
88
|
+
channel_import = "import \"#{CableReady::Installer.prefix}channels\"\n"
|
89
89
|
|
90
|
-
if pack.match?(channels_pattern)
|
91
|
-
if pack.match?(channels_commented_pattern)
|
92
|
-
proceed = if options.key? "uncomment"
|
93
|
-
options["uncomment"]
|
90
|
+
if CableReady::Installer.pack.match?(channels_pattern)
|
91
|
+
if CableReady::Installer.pack.match?(channels_commented_pattern)
|
92
|
+
proceed = if CableReady::Installer.options.key? "uncomment"
|
93
|
+
CableReady::Installer.options["uncomment"]
|
94
94
|
else
|
95
95
|
!no?("✨ Action Cable seems to be commented out in your application.js. Do you want to uncomment it? (Y/n)")
|
96
96
|
end
|
97
97
|
|
98
98
|
if proceed
|
99
99
|
# uncomment_lines only works with Ruby comments 🙄
|
100
|
-
lines = pack_path.readlines
|
100
|
+
lines = CableReady::Installer.pack_path.readlines
|
101
101
|
matches = lines.select { |line| line =~ channels_commented_pattern }
|
102
102
|
lines[lines.index(matches.last).to_i] = channel_import
|
103
|
-
pack_path.write lines.join
|
104
|
-
say "✅ channels imported in #{friendly_pack_path}"
|
103
|
+
CableReady::Installer.pack_path.write lines.join
|
104
|
+
say "✅ channels imported in #{CableReady::Installer.friendly_pack_path}"
|
105
105
|
else
|
106
106
|
say "🤷 your Action Cable channels are not being imported in your application.js. We trust that you have a reason for this."
|
107
107
|
end
|
108
108
|
else
|
109
|
-
say "✅ channels imported in #{friendly_pack_path}"
|
109
|
+
say "✅ channels imported in #{CableReady::Installer.friendly_pack_path}"
|
110
110
|
end
|
111
111
|
else
|
112
|
-
lines = pack_path.readlines
|
112
|
+
lines = CableReady::Installer.pack_path.readlines
|
113
113
|
matches = lines.select { |line| line =~ /^import / }
|
114
114
|
lines.insert lines.index(matches.last).to_i + 1, channel_import
|
115
|
-
pack_path.write lines.join
|
116
|
-
say "✅ channels imported in #{friendly_pack_path}"
|
115
|
+
CableReady::Installer.pack_path.write lines.join
|
116
|
+
say "✅ channels imported in #{CableReady::Installer.friendly_pack_path}"
|
117
117
|
end
|
118
118
|
|
119
119
|
# create working copy of Action Cable initializer in tmp
|
120
|
-
if action_cable_initializer_path.exist?
|
121
|
-
FileUtils.cp(action_cable_initializer_path, action_cable_initializer_working_path)
|
120
|
+
if CableReady::Installer.action_cable_initializer_path.exist?
|
121
|
+
FileUtils.cp(CableReady::Installer.action_cable_initializer_path, CableReady::Installer.action_cable_initializer_working_path)
|
122
122
|
else
|
123
123
|
# create Action Cable initializer if it doesn't already exist
|
124
|
-
create_file(action_cable_initializer_working_path, verbose: false) do
|
124
|
+
create_file(CableReady::Installer.action_cable_initializer_working_path, verbose: false) do
|
125
125
|
<<~RUBY
|
126
126
|
# frozen_string_literal: true
|
127
127
|
|
@@ -131,8 +131,8 @@ else
|
|
131
131
|
end
|
132
132
|
|
133
133
|
# silence notoriously chatty Action Cable logs
|
134
|
-
if !action_cable_initializer_working_path.read.match?(/^[^#]*ActionCable.server.config.logger/)
|
135
|
-
append_file(action_cable_initializer_working_path, verbose: false) do
|
134
|
+
if !CableReady::Installer.action_cable_initializer_working_path.read.match?(/^[^#]*ActionCable.server.config.logger/)
|
135
|
+
append_file(CableReady::Installer.action_cable_initializer_working_path, verbose: false) do
|
136
136
|
<<~RUBY
|
137
137
|
ActionCable.server.config.logger = Logger.new(nil)
|
138
138
|
|
@@ -141,4 +141,4 @@ if !action_cable_initializer_working_path.read.match?(/^[^#]*ActionCable.server.
|
|
141
141
|
say "✅ Action Cable logger silenced for performance and legibility"
|
142
142
|
end
|
143
143
|
|
144
|
-
complete_step :action_cable
|
144
|
+
CableReady::Installer.complete_step :action_cable
|