stimulus_reflex 3.5.0.rc3 → 3.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +144 -101
- data/README.md +2 -2
- data/app/assets/javascripts/stimulus_reflex.js +15 -13
- data/app/assets/javascripts/stimulus_reflex.umd.js +15 -12
- data/app/channels/stimulus_reflex/channel.rb +49 -53
- data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +2 -2
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +1 -1
- data/lib/install/action_cable.rb +30 -30
- data/lib/install/broadcaster.rb +11 -11
- data/lib/install/bundle.rb +9 -9
- data/lib/install/compression.rb +5 -5
- data/lib/install/config.rb +22 -22
- data/lib/install/development.rb +19 -19
- data/lib/install/esbuild.rb +28 -28
- data/lib/install/example.rb +3 -3
- data/lib/install/importmap.rb +29 -29
- data/lib/install/initializers.rb +3 -3
- data/lib/install/mrujs.rb +25 -25
- data/lib/install/npm_packages.rb +7 -7
- data/lib/install/reflexes.rb +2 -2
- data/lib/install/shakapacker.rb +23 -23
- data/lib/install/spring.rb +7 -7
- data/lib/install/updatable.rb +7 -7
- data/lib/install/vite.rb +22 -22
- data/lib/install/webpacker.rb +27 -27
- data/lib/install/yarn.rb +9 -9
- data/lib/stimulus_reflex/html/document_fragment.rb +5 -3
- data/lib/stimulus_reflex/installer.rb +305 -277
- data/lib/stimulus_reflex/reflex.rb +14 -29
- data/lib/stimulus_reflex/reflex_data.rb +17 -17
- data/lib/stimulus_reflex/reflex_factory.rb +49 -26
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/stimulus_reflex.rb +2 -0
- data/lib/tasks/stimulus_reflex/stimulus_reflex.rake +8 -8
- data/package.json +10 -10
- data/stimulus_reflex.gemspec +10 -8
- data/web-test-runner.config.mjs +14 -0
- data/yarn.lock +1278 -830
- metadata +34 -42
@@ -1,355 +1,383 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "thor"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module StimulusReflex
|
6
|
+
class Installer
|
7
|
+
include Thor::Base
|
8
|
+
include Thor::Actions
|
8
9
|
|
9
|
-
|
10
|
-
end
|
10
|
+
source_root Dir.pwd
|
11
11
|
|
12
|
-
|
13
|
-
create_file "tmp/stimulus_reflex_installer/#{step}", verbose: false
|
14
|
-
end
|
12
|
+
## Thor wrapper
|
15
13
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
end
|
14
|
+
def self.create_file(...)
|
15
|
+
new.create_file(...)
|
16
|
+
end
|
20
17
|
|
21
|
-
def
|
22
|
-
|
23
|
-
end
|
18
|
+
def self.append_file(...)
|
19
|
+
new.append_file(...)
|
20
|
+
end
|
24
21
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
end
|
22
|
+
def self.copy_file(...)
|
23
|
+
new.copy_file(...)
|
24
|
+
end
|
29
25
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
end
|
26
|
+
def self.say(...)
|
27
|
+
new.say(...)
|
28
|
+
end
|
34
29
|
|
35
|
-
|
36
|
-
if !path.exist?
|
37
|
-
yield
|
38
|
-
return
|
39
|
-
end
|
30
|
+
### general utilities
|
40
31
|
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
def self.fetch(step_path, file)
|
33
|
+
relative_path = step_path + file
|
34
|
+
location = template_src + relative_path
|
44
35
|
|
45
|
-
|
46
|
-
if backup_path.read == path.read
|
47
|
-
path.delete if delete
|
48
|
-
yield
|
49
|
-
return
|
36
|
+
Pathname.new(location)
|
50
37
|
end
|
51
|
-
backup_path.delete
|
52
|
-
end
|
53
38
|
|
54
|
-
|
55
|
-
|
39
|
+
def self.complete_step(step)
|
40
|
+
create_file "tmp/stimulus_reflex_installer/#{step}", verbose: false
|
41
|
+
end
|
56
42
|
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
say "📦 #{old_path} backed up as #{filename}.bak"
|
63
|
-
end
|
48
|
+
def self.current_template
|
49
|
+
ENV["LOCATION"].split("/").last.gsub(".rb", "")
|
50
|
+
end
|
64
51
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
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
|
69
56
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
end
|
57
|
+
def self.halt(message)
|
58
|
+
say "❌ #{message}", :red
|
59
|
+
create_file "tmp/stimulus_reflex_installer/halt", verbose: false
|
60
|
+
end
|
74
61
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
62
|
+
def self.backup(path, delete: false)
|
63
|
+
if !path.exist?
|
64
|
+
yield
|
65
|
+
return
|
66
|
+
end
|
79
67
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
84
80
|
|
85
|
-
|
86
|
-
|
87
|
-
say "❎ Enqueued #{name} to be removed from dependencies"
|
88
|
-
end
|
81
|
+
copy_file(path, backup_path, verbose: false)
|
82
|
+
path.delete if delete
|
89
83
|
|
90
|
-
|
91
|
-
Digest::MD5.hexdigest(gemfile_path.read)
|
92
|
-
end
|
84
|
+
yield
|
93
85
|
|
94
|
-
|
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
|
95
91
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
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
|
99
96
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
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
|
103
101
|
|
104
|
-
def
|
105
|
-
|
106
|
-
|
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
|
107
106
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
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
|
111
111
|
|
112
|
-
def
|
113
|
-
|
114
|
-
|
115
|
-
end
|
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
|
116
116
|
|
117
|
-
def
|
118
|
-
|
119
|
-
|
120
|
-
"app/frontend",
|
121
|
-
"app/client",
|
122
|
-
"app/webpack"
|
123
|
-
].find { |path| File.exist?(Rails.root.join(path)) } || "app/javascript"
|
117
|
+
def self.gemfile_hash
|
118
|
+
Digest::MD5.hexdigest(gemfile_path.read)
|
119
|
+
end
|
124
120
|
|
125
|
-
|
126
|
-
puts "Where do JavaScript files live in your app? Our best guess is: \e[1m#{entrypoint}\e[22m 🤔"
|
127
|
-
puts "Press enter to accept this, or type a different path."
|
128
|
-
print "> "
|
121
|
+
### memoized values
|
129
122
|
|
130
|
-
|
131
|
-
|
123
|
+
def self.sr_npm_version
|
124
|
+
@sr_npm_version ||= StimulusReflex::VERSION.gsub(".pre", "-pre").gsub(".rc", "-rc")
|
125
|
+
end
|
132
126
|
|
133
|
-
|
127
|
+
def self.cr_npm_version
|
128
|
+
@cr_npm_version ||= CableReady::VERSION.gsub(".pre", "-pre").gsub(".rc", "-rc")
|
129
|
+
end
|
134
130
|
|
135
|
-
|
136
|
-
|
131
|
+
def self.package_json_path
|
132
|
+
@package_json_path ||= Rails.root.join("package.json")
|
133
|
+
end
|
137
134
|
|
138
|
-
def
|
139
|
-
|
140
|
-
end
|
135
|
+
def self.installer_entrypoint_path
|
136
|
+
create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/entrypoint")
|
137
|
+
end
|
141
138
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
139
|
+
def self.entrypoint
|
140
|
+
path = installer_entrypoint_path
|
141
|
+
@entrypoint ||= File.exist?(path) ? File.read(path) : auto_detect_entrypoint
|
142
|
+
end
|
145
143
|
|
146
|
-
|
147
|
-
|
144
|
+
def self.auto_detect_entrypoint
|
145
|
+
entrypoint = [
|
146
|
+
"app/javascript",
|
147
|
+
"app/frontend",
|
148
|
+
"app/client",
|
149
|
+
"app/webpack"
|
150
|
+
].find { |path| File.exist?(Rails.root.join(path)) } || "app/javascript"
|
148
151
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
elsif package_json_path.exist?
|
154
|
-
package_json = package_json_path.read
|
155
|
-
|
156
|
-
bundler = "webpacker" if package_json.include?('"@rails/webpacker":')
|
157
|
-
bundler = "esbuild" if package_json.include?('"esbuild":')
|
158
|
-
bundler = "vite" if package_json.include?('"vite":')
|
159
|
-
bundler = "shakapacker" if package_json.include?('"shakapacker":')
|
160
|
-
|
161
|
-
if !bundler
|
162
|
-
puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
|
163
|
-
exit
|
164
|
-
end
|
165
|
-
else
|
166
|
-
puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
|
167
|
-
exit
|
168
|
-
end
|
152
|
+
puts
|
153
|
+
puts "Where do JavaScript files live in your app? Our best guess is: \e[1m#{entrypoint}\e[22m 🤔"
|
154
|
+
puts "Press enter to accept this, or type a different path."
|
155
|
+
print "> "
|
169
156
|
|
170
|
-
|
171
|
-
|
172
|
-
print "> "
|
157
|
+
input = Rails.env.test? ? "tmp/app/javascript" : $stdin.gets.chomp
|
158
|
+
entrypoint = input unless input.blank?
|
173
159
|
|
174
|
-
|
160
|
+
File.write(installer_entrypoint_path, entrypoint)
|
175
161
|
|
176
|
-
|
177
|
-
|
178
|
-
puts "StimulusReflex installation supports: esbuild, webpacker, vite, shakapacker and importmap."
|
179
|
-
puts "Please run \e[1;94mrails stimulus_reflex:install [bundler]\e[0m to install StimulusReflex and CableReady."
|
180
|
-
exit
|
181
|
-
end
|
162
|
+
entrypoint
|
163
|
+
end
|
182
164
|
|
183
|
-
|
165
|
+
def self.installer_bundler_path
|
166
|
+
create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/bundler")
|
167
|
+
end
|
184
168
|
|
185
|
-
|
186
|
-
|
169
|
+
def self.bundler
|
170
|
+
path = installer_bundler_path
|
171
|
+
@bundler ||= File.exist?(path) ? File.read(path) : auto_detect_bundler
|
187
172
|
|
188
|
-
|
189
|
-
|
173
|
+
@bundler.inquiry
|
174
|
+
end
|
190
175
|
|
191
|
-
|
192
|
-
|
176
|
+
def self.auto_detect_bundler
|
177
|
+
# auto-detect build tool based on existing packages and configuration
|
178
|
+
if importmap_path.exist?
|
179
|
+
bundler = "importmap"
|
180
|
+
elsif package_json_path.exist?
|
181
|
+
package_json = package_json_path.read
|
182
|
+
|
183
|
+
bundler = "webpacker" if package_json.include?('"@rails/webpacker":')
|
184
|
+
bundler = "esbuild" if package_json.include?('"esbuild":')
|
185
|
+
bundler = "vite" if package_json.include?('"vite":')
|
186
|
+
bundler = "shakapacker" if package_json.include?('"shakapacker":')
|
187
|
+
|
188
|
+
if !bundler
|
189
|
+
puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
|
190
|
+
exit
|
191
|
+
end
|
192
|
+
else
|
193
|
+
puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
|
194
|
+
exit
|
195
|
+
end
|
193
196
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
+
puts
|
198
|
+
puts "It looks like you're using \e[1m#{bundler}\e[22m as your bundler. Is that correct? (Y/n)"
|
199
|
+
print "> "
|
197
200
|
|
198
|
-
|
199
|
-
end
|
201
|
+
input = $stdin.gets.chomp
|
200
202
|
|
201
|
-
|
202
|
-
|
203
|
-
|
203
|
+
if input.downcase == "n"
|
204
|
+
puts
|
205
|
+
puts "StimulusReflex installation supports: esbuild, webpacker, vite, shakapacker and importmap."
|
206
|
+
puts "Please run \e[1;94mrails stimulus_reflex:install[bundler]\e[0m to install StimulusReflex and CableReady."
|
207
|
+
exit
|
208
|
+
end
|
204
209
|
|
205
|
-
|
206
|
-
@importmap_path ||= Rails.root.join("config/importmap.rb")
|
207
|
-
end
|
210
|
+
File.write(installer_bundler_path, bundler)
|
208
211
|
|
209
|
-
|
210
|
-
|
211
|
-
end
|
212
|
+
bundler
|
213
|
+
end
|
212
214
|
|
213
|
-
def
|
214
|
-
|
215
|
-
end
|
215
|
+
def self.create_dir_if_not_exists(dir_path)
|
216
|
+
FileUtils.mkdir_p(dir_path)
|
216
217
|
|
217
|
-
|
218
|
-
|
219
|
-
end
|
218
|
+
Pathname.new(dir_path)
|
219
|
+
end
|
220
220
|
|
221
|
-
def
|
222
|
-
|
223
|
-
|
224
|
-
Rails.root.join(entrypoint, "packs/application.js"),
|
225
|
-
Rails.root.join(entrypoint, "entrypoints/application.js")
|
226
|
-
].find(&:exist?)
|
227
|
-
end
|
221
|
+
def self.create_dir_for_file_if_not_exists(file_path)
|
222
|
+
dir_path = File.dirname(file_path)
|
223
|
+
create_dir_if_not_exists(dir_path)
|
228
224
|
|
229
|
-
|
230
|
-
|
231
|
-
end
|
225
|
+
Pathname.new(file_path)
|
226
|
+
end
|
232
227
|
|
233
|
-
def
|
234
|
-
|
235
|
-
end
|
228
|
+
def self.config_path
|
229
|
+
@config_path ||= create_dir_if_not_exists(Rails.root.join(entrypoint, "config"))
|
230
|
+
end
|
236
231
|
|
237
|
-
def
|
238
|
-
|
239
|
-
end
|
232
|
+
def self.importmap_path
|
233
|
+
@importmap_path ||= Rails.root.join("config/importmap.rb")
|
234
|
+
end
|
240
235
|
|
241
|
-
def
|
242
|
-
|
243
|
-
end
|
236
|
+
def self.friendly_importmap_path
|
237
|
+
@friendly_importmap_path ||= importmap_path.relative_path_from(Rails.root).to_s
|
238
|
+
end
|
244
239
|
|
245
|
-
def
|
246
|
-
|
247
|
-
end
|
240
|
+
def self.pack
|
241
|
+
@pack ||= pack_path.read
|
242
|
+
end
|
248
243
|
|
249
|
-
def
|
250
|
-
|
251
|
-
end
|
244
|
+
def self.friendly_pack_path
|
245
|
+
@friendly_pack_path ||= pack_path.relative_path_from(Rails.root).to_s
|
246
|
+
end
|
252
247
|
|
253
|
-
def
|
254
|
-
|
255
|
-
|
248
|
+
def self.pack_path
|
249
|
+
@pack_path ||= [
|
250
|
+
Rails.root.join(entrypoint, "application.js"),
|
251
|
+
Rails.root.join(entrypoint, "packs/application.js"),
|
252
|
+
Rails.root.join(entrypoint, "entrypoints/application.js")
|
253
|
+
].find(&:exist?)
|
254
|
+
end
|
256
255
|
|
257
|
-
def
|
258
|
-
|
259
|
-
|
260
|
-
"vite" => "..\/",
|
261
|
-
"webpacker" => "",
|
262
|
-
"shakapacker" => "",
|
263
|
-
"importmap" => "",
|
264
|
-
"esbuild" => ".\/"
|
265
|
-
}[bundler]
|
266
|
-
# standard:enable Style/RedundantStringEscape
|
267
|
-
end
|
256
|
+
def self.package_list
|
257
|
+
@package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/npm_package_list")
|
258
|
+
end
|
268
259
|
|
269
|
-
def
|
270
|
-
|
271
|
-
end
|
260
|
+
def self.dev_package_list
|
261
|
+
@dev_package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/npm_dev_package_list")
|
262
|
+
end
|
272
263
|
|
273
|
-
def
|
274
|
-
|
275
|
-
end
|
264
|
+
def self.drop_package_list
|
265
|
+
@drop_package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/drop_npm_package_list")
|
266
|
+
end
|
276
267
|
|
277
|
-
def
|
278
|
-
|
279
|
-
end
|
268
|
+
def self.template_src
|
269
|
+
@template_src ||= File.read("tmp/stimulus_reflex_installer/template_src")
|
270
|
+
end
|
280
271
|
|
281
|
-
def
|
282
|
-
|
283
|
-
end
|
272
|
+
def self.controllers_path
|
273
|
+
@controllers_path ||= Rails.root.join(entrypoint, "controllers")
|
274
|
+
end
|
284
275
|
|
285
|
-
def
|
286
|
-
|
287
|
-
end
|
276
|
+
def self.gemfile_path
|
277
|
+
@gemfile_path ||= Rails.root.join("Gemfile")
|
278
|
+
end
|
288
279
|
|
289
|
-
def
|
290
|
-
|
291
|
-
end
|
280
|
+
def self.gemfile
|
281
|
+
@gemfile ||= gemfile_path.read
|
282
|
+
end
|
292
283
|
|
293
|
-
def
|
294
|
-
|
295
|
-
|
284
|
+
def self.prefix
|
285
|
+
# standard:disable Style/RedundantStringEscape
|
286
|
+
@prefix ||= {
|
287
|
+
"vite" => "..\/",
|
288
|
+
"webpacker" => "",
|
289
|
+
"shakapacker" => "",
|
290
|
+
"importmap" => "",
|
291
|
+
"esbuild" => ".\/"
|
292
|
+
}[bundler]
|
293
|
+
# standard:enable Style/RedundantStringEscape
|
294
|
+
end
|
296
295
|
|
297
|
-
def
|
298
|
-
|
299
|
-
end
|
296
|
+
def self.application_record_path
|
297
|
+
@application_record_path ||= Rails.root.join("app/models/application_record.rb")
|
298
|
+
end
|
300
299
|
|
301
|
-
def
|
302
|
-
|
303
|
-
end
|
300
|
+
def self.action_cable_initializer_path
|
301
|
+
@action_cable_initializer_path ||= Rails.root.join("config/initializers/action_cable.rb")
|
302
|
+
end
|
304
303
|
|
305
|
-
def
|
306
|
-
|
307
|
-
end
|
304
|
+
def self.action_cable_initializer_working_path
|
305
|
+
@action_cable_initializer_working_path ||= Rails.root.join(working, "action_cable.rb")
|
306
|
+
end
|
308
307
|
|
309
|
-
def
|
310
|
-
|
311
|
-
end
|
308
|
+
def self.development_path
|
309
|
+
@development_path ||= Rails.root.join("config/environments/development.rb")
|
310
|
+
end
|
311
|
+
|
312
|
+
def self.development_working_path
|
313
|
+
@development_working_path ||= Rails.root.join(working, "development.rb")
|
314
|
+
end
|
315
|
+
|
316
|
+
def self.backups_path
|
317
|
+
@backups_path ||= Rails.root.join("tmp/stimulus_reflex_installer/backups")
|
318
|
+
end
|
312
319
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
#
|
320
|
+
def self.add_gem_list
|
321
|
+
@add_gem_list ||= Rails.root.join("tmp/stimulus_reflex_installer/add_gem_list")
|
322
|
+
end
|
323
|
+
|
324
|
+
def self.remove_gem_list
|
325
|
+
@remove_gem_list ||= Rails.root.join("tmp/stimulus_reflex_installer/remove_gem_list")
|
326
|
+
end
|
327
|
+
|
328
|
+
def self.options_path
|
329
|
+
@options_path ||= Rails.root.join("tmp/stimulus_reflex_installer/options")
|
330
|
+
end
|
331
|
+
|
332
|
+
def self.options
|
333
|
+
@options ||= YAML.safe_load(File.read(options_path))
|
334
|
+
end
|
335
|
+
|
336
|
+
def self.working
|
337
|
+
@working ||= Rails.root.join("tmp/stimulus_reflex_installer/working")
|
338
|
+
end
|
339
|
+
|
340
|
+
### support for development step
|
341
|
+
|
342
|
+
def self.write_redis_recommendation(development_working, lines, index, gemfile)
|
343
|
+
# provide a recommendation for using redis-session-store, including commented source code
|
344
|
+
if !lines.index { |line| line.include?("StimulusReflex does not support :cookie_store") }
|
345
|
+
lines.insert index + 1, <<~RUBY
|
346
|
+
# StimulusReflex does not support :cookie_store, and we recommend switching to Redis.
|
347
|
+
# To use `redis-session-store`, make sure to add it to your Gemfile and run `bundle install
|
348
|
+
# config.session_store :redis_session_store,
|
349
|
+
# serializer: :json,
|
350
|
+
# on_redis_down: ->(*a) { Rails.logger.error("Redis down! \#{a.inspect}") },
|
351
|
+
# redis: {
|
352
|
+
# expire_after: 120.minutes,
|
353
|
+
# key_prefix: "session:",
|
354
|
+
# url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }
|
355
|
+
# }
|
340
356
|
RUBY
|
357
|
+
|
358
|
+
development_working.write lines.join
|
359
|
+
# add redis-session-store to Gemfile, but comment it out
|
360
|
+
if !gemfile.match?(/gem ['"]redis-session-store['"]/)
|
361
|
+
append_file(gemfile_path, verbose: false) do
|
362
|
+
<<~RUBY
|
363
|
+
|
364
|
+
# StimulusReflex recommends using Redis for session storage
|
365
|
+
# gem "redis-session-store", "0.11.5"
|
366
|
+
RUBY
|
367
|
+
end
|
368
|
+
say "💡 Added redis-session-store 0.11.5 to the Gemfile, commented out"
|
369
|
+
end
|
341
370
|
end
|
342
|
-
say "💡 Added redis-session-store 0.11.5 to the Gemfile, commented out"
|
343
371
|
end
|
344
|
-
end
|
345
|
-
end
|
346
372
|
|
347
|
-
def find_index(lines)
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
373
|
+
def self.find_index(lines)
|
374
|
+
# accomodate devs who modify their development.rb file structure
|
375
|
+
if (index = lines.index { |line| line =~ /caching-dev/ })
|
376
|
+
index += 3
|
377
|
+
else
|
378
|
+
index = lines.index { |line| line =~ /^Rails.application.configure do/ } + 1
|
379
|
+
end
|
380
|
+
index
|
381
|
+
end
|
353
382
|
end
|
354
|
-
index
|
355
383
|
end
|