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