stimulus_reflex 3.5.0.rc2 → 3.5.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +22 -18
- data/app/assets/javascripts/stimulus_reflex.js +8 -6
- data/app/assets/javascripts/stimulus_reflex.umd.js +8 -5
- data/app/channels/stimulus_reflex/channel.rb +49 -53
- data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +6 -18
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +6 -2
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +7 -2
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +6 -2
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +5 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.importmap.tt +7 -1
- data/lib/install/config.rb +5 -5
- data/lib/install/esbuild.rb +1 -1
- data/lib/install/importmap.rb +2 -2
- data/lib/install/mrujs.rb +10 -5
- data/lib/install/npm_packages.rb +1 -1
- data/lib/install/shakapacker.rb +1 -1
- data/lib/install/vite.rb +1 -1
- data/lib/install/webpacker.rb +1 -1
- data/lib/install/yarn.rb +4 -4
- data/lib/stimulus_reflex/cable_readiness.rb +1 -7
- data/lib/stimulus_reflex/installer.rb +88 -7
- 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/tasks/stimulus_reflex/stimulus_reflex.rake +21 -52
- data/package.json +3 -3
- data/stimulus_reflex.gemspec +2 -2
- data/yarn.lock +518 -444
- metadata +10 -10
data/lib/install/yarn.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
if !
|
5
|
+
if !package_json_path.exist?
|
6
6
|
say "⏩ No package.json file found. Skipping."
|
7
7
|
|
8
8
|
return
|
@@ -13,7 +13,7 @@ add = package_list.exist? ? package_list.readlines.map(&:chomp) : []
|
|
13
13
|
dev = dev_package_list.exist? ? dev_package_list.readlines.map(&:chomp) : []
|
14
14
|
drop = drop_package_list.exist? ? drop_package_list.readlines.map(&:chomp) : []
|
15
15
|
|
16
|
-
json = JSON.parse(
|
16
|
+
json = JSON.parse(package_json_path.read)
|
17
17
|
|
18
18
|
if add.present? || dev.present? || drop.present?
|
19
19
|
|
@@ -36,7 +36,7 @@ if add.present? || dev.present? || drop.present?
|
|
36
36
|
json["devDependencies"].delete(package)
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
package_json_path.write JSON.pretty_generate(json)
|
40
40
|
|
41
41
|
system "yarn install --silent"
|
42
42
|
else
|
@@ -46,7 +46,7 @@ end
|
|
46
46
|
if bundler == "esbuild" && json["scripts"]["build"] != "node esbuild.config.mjs"
|
47
47
|
json["scripts"]["build:default"] = json["scripts"]["build"]
|
48
48
|
json["scripts"]["build"] = "node esbuild.config.mjs"
|
49
|
-
|
49
|
+
package_json_path.write JSON.pretty_generate(json)
|
50
50
|
say "✅ Your yarn build script has been updated to use esbuild.config.mjs"
|
51
51
|
else
|
52
52
|
say "⏩ Your yarn build script is already setup. Skipping."
|
@@ -1,14 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/concern"
|
4
|
-
|
5
3
|
module StimulusReflex
|
6
4
|
module CableReadiness
|
7
|
-
|
8
|
-
|
9
|
-
prepended do
|
10
|
-
attr_reader :cable_ready
|
11
|
-
end
|
5
|
+
attr_reader :cable_ready
|
12
6
|
|
13
7
|
def initialize(*args, **kwargs)
|
14
8
|
super(*args, **kwargs)
|
@@ -101,24 +101,105 @@ def cr_npm_version
|
|
101
101
|
@cr_npm_version ||= CableReady::VERSION.gsub(".pre", "-pre").gsub(".rc", "-rc")
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
105
|
-
@
|
104
|
+
def package_json_path
|
105
|
+
@package_json_path ||= Rails.root.join("package.json")
|
106
|
+
end
|
107
|
+
|
108
|
+
def installer_entrypoint_path
|
109
|
+
create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/entrypoint")
|
106
110
|
end
|
107
111
|
|
108
112
|
def entrypoint
|
109
|
-
|
113
|
+
path = installer_entrypoint_path
|
114
|
+
@entrypoint ||= File.exist?(path) ? File.read(path) : auto_detect_entrypoint
|
115
|
+
end
|
116
|
+
|
117
|
+
def auto_detect_entrypoint
|
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"
|
124
|
+
|
125
|
+
puts
|
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 "> "
|
129
|
+
|
130
|
+
input = Rails.env.test? ? "tmp/app/javascript" : $stdin.gets.chomp
|
131
|
+
entrypoint = input unless input.blank?
|
132
|
+
|
133
|
+
File.write(installer_entrypoint_path, entrypoint)
|
134
|
+
|
135
|
+
entrypoint
|
136
|
+
end
|
137
|
+
|
138
|
+
def installer_bundler_path
|
139
|
+
create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/bundler")
|
110
140
|
end
|
111
141
|
|
112
142
|
def bundler
|
113
|
-
|
143
|
+
path = installer_bundler_path
|
144
|
+
@bundler ||= File.exist?(path) ? File.read(path) : auto_detect_bundler
|
145
|
+
|
146
|
+
@bundler.inquiry
|
147
|
+
end
|
148
|
+
|
149
|
+
def auto_detect_bundler
|
150
|
+
# auto-detect build tool based on existing packages and configuration
|
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
|
169
|
+
|
170
|
+
puts
|
171
|
+
puts "It looks like you're using \e[1m#{bundler}\e[22m as your bundler. Is that correct? (Y/n)"
|
172
|
+
print "> "
|
173
|
+
|
174
|
+
input = $stdin.gets.chomp
|
175
|
+
|
176
|
+
if input.downcase == "n"
|
177
|
+
puts
|
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
|
182
|
+
|
183
|
+
File.write(installer_bundler_path, bundler)
|
184
|
+
|
185
|
+
bundler
|
114
186
|
end
|
115
187
|
|
116
|
-
def
|
117
|
-
|
188
|
+
def create_dir_if_not_exists(dir_path)
|
189
|
+
FileUtils.mkdir_p(dir_path)
|
190
|
+
|
191
|
+
Pathname.new(dir_path)
|
192
|
+
end
|
193
|
+
|
194
|
+
def create_dir_for_file_if_not_exists(file_path)
|
195
|
+
dir_path = File.dirname(file_path)
|
196
|
+
create_dir_if_not_exists(dir_path)
|
197
|
+
|
198
|
+
Pathname.new(file_path)
|
118
199
|
end
|
119
200
|
|
120
201
|
def config_path
|
121
|
-
@config_path ||= Rails.root.join(entrypoint, "config")
|
202
|
+
@config_path ||= create_dir_if_not_exists(Rails.root.join(entrypoint, "config"))
|
122
203
|
end
|
123
204
|
|
124
205
|
def importmap_path
|
@@ -3,20 +3,6 @@
|
|
3
3
|
require "stimulus_reflex/cable_readiness"
|
4
4
|
require "stimulus_reflex/version_checker"
|
5
5
|
|
6
|
-
# TODO remove xpath_controller and xpath_element for v4
|
7
|
-
ClientAttributes = Struct.new(
|
8
|
-
:id,
|
9
|
-
:tab_id,
|
10
|
-
:reflex_controller,
|
11
|
-
:xpath_controller,
|
12
|
-
:xpath_element,
|
13
|
-
:permanent_attribute_name,
|
14
|
-
:version,
|
15
|
-
:npm_version,
|
16
|
-
:suppress_logging,
|
17
|
-
keyword_init: true
|
18
|
-
)
|
19
|
-
|
20
6
|
class StimulusReflex::Reflex
|
21
7
|
prepend StimulusReflex::CableReadiness
|
22
8
|
include StimulusReflex::VersionChecker
|
@@ -26,32 +12,27 @@ class StimulusReflex::Reflex
|
|
26
12
|
include CableReady::Identifiable
|
27
13
|
|
28
14
|
attr_accessor :payload, :headers
|
29
|
-
attr_reader :channel, :
|
30
|
-
|
31
|
-
alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name
|
15
|
+
attr_reader :channel, :reflex_data, :broadcaster
|
32
16
|
|
33
17
|
delegate :connection, :stream_name, to: :channel
|
34
18
|
delegate :controller_class, :flash, :session, to: :request
|
35
19
|
delegate :broadcast, :broadcast_halt, :broadcast_forbid, :broadcast_error, to: :broadcaster
|
20
|
+
|
36
21
|
# TODO remove xpath_controller and xpath_element for v4
|
37
|
-
delegate :id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :version, :npm_version, :suppress_logging, to: :
|
22
|
+
delegate :url, :element, :selectors, :method_name, :id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :version, :npm_version, :suppress_logging, to: :reflex_data
|
23
|
+
# END TODO: remove
|
38
24
|
|
39
|
-
|
25
|
+
alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name
|
26
|
+
alias_method :data, :reflex_data
|
27
|
+
|
28
|
+
def initialize(channel, reflex_data:)
|
40
29
|
@channel = channel
|
41
|
-
@
|
42
|
-
@element = element
|
43
|
-
@selectors = selectors
|
44
|
-
@method_name = method_name
|
45
|
-
@params = params
|
46
|
-
@client_attributes = ClientAttributes.new(client_attributes)
|
30
|
+
@reflex_data = reflex_data
|
47
31
|
@broadcaster = StimulusReflex::PageBroadcaster.new(self)
|
48
|
-
@logger = suppress_logging ? nil : StimulusReflex::Logger.new(self)
|
49
32
|
@payload = {}
|
50
33
|
@headers = {}
|
51
34
|
|
52
35
|
check_version!
|
53
|
-
|
54
|
-
self.params
|
55
36
|
end
|
56
37
|
|
57
38
|
# TODO: remove this for v4
|
@@ -61,6 +42,10 @@ class StimulusReflex::Reflex
|
|
61
42
|
end
|
62
43
|
# END TODO: remove
|
63
44
|
|
45
|
+
def logger
|
46
|
+
@logger ||= StimulusReflex::Logger.new(self) unless suppress_logging
|
47
|
+
end
|
48
|
+
|
64
49
|
def request
|
65
50
|
@request ||= begin
|
66
51
|
uri = URI.parse(url)
|
@@ -91,7 +76,7 @@ class StimulusReflex::Reflex
|
|
91
76
|
req = ActionDispatch::Request.new(env)
|
92
77
|
|
93
78
|
# fetch path params (controller, action, ...) and apply them
|
94
|
-
request_params = StimulusReflex::RequestParameters.new(params:
|
79
|
+
request_params = StimulusReflex::RequestParameters.new(params: reflex_data.params, req: req, url: url)
|
95
80
|
req = request_params.apply!
|
96
81
|
|
97
82
|
req
|
@@ -4,7 +4,7 @@ class StimulusReflex::ReflexData
|
|
4
4
|
attr_reader :data
|
5
5
|
|
6
6
|
def initialize(data)
|
7
|
-
@data = data
|
7
|
+
@data = data.deep_merge(data.deep_transform_keys { |k| k.to_s.underscore }).with_indifferent_access
|
8
8
|
end
|
9
9
|
|
10
10
|
def reflex_name
|
@@ -14,13 +14,13 @@ class StimulusReflex::ReflexData
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def selectors
|
17
|
-
selectors = (data[
|
18
|
-
selectors = data[
|
17
|
+
selectors = (data[:selectors] || []).select(&:present?)
|
18
|
+
selectors = data[:selectors] = ["body"] if selectors.blank?
|
19
19
|
selectors
|
20
20
|
end
|
21
21
|
|
22
22
|
def target
|
23
|
-
data[
|
23
|
+
data[:target].to_s
|
24
24
|
end
|
25
25
|
|
26
26
|
def method_name
|
@@ -28,11 +28,11 @@ class StimulusReflex::ReflexData
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def arguments
|
31
|
-
(data[
|
31
|
+
(data[:args] || []).map { |arg| object_with_indifferent_access arg } || []
|
32
32
|
end
|
33
33
|
|
34
34
|
def url
|
35
|
-
data[
|
35
|
+
data[:url].to_s
|
36
36
|
end
|
37
37
|
|
38
38
|
def element
|
@@ -40,15 +40,15 @@ class StimulusReflex::ReflexData
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def permanent_attribute_name
|
43
|
-
data[
|
43
|
+
data[:permanent_attribute_name]
|
44
44
|
end
|
45
45
|
|
46
46
|
def suppress_logging
|
47
|
-
data[
|
47
|
+
data[:suppress_logging]
|
48
48
|
end
|
49
49
|
|
50
50
|
def form_data
|
51
|
-
Rack::Utils.parse_nested_query(data[
|
51
|
+
Rack::Utils.parse_nested_query(data[:form_data])
|
52
52
|
end
|
53
53
|
|
54
54
|
def params
|
@@ -56,7 +56,7 @@ class StimulusReflex::ReflexData
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def form_params
|
59
|
-
form_data.deep_merge(data[
|
59
|
+
form_data.deep_merge(data[:params] || {})
|
60
60
|
end
|
61
61
|
|
62
62
|
def url_params
|
@@ -64,33 +64,33 @@ class StimulusReflex::ReflexData
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def id
|
67
|
-
data[
|
67
|
+
data[:id]
|
68
68
|
end
|
69
69
|
|
70
70
|
def tab_id
|
71
|
-
data[
|
71
|
+
data[:tab_id]
|
72
72
|
end
|
73
73
|
|
74
74
|
# TODO: remove this in v4
|
75
75
|
def xpath_controller
|
76
|
-
data[
|
76
|
+
data[:xpath_controller]
|
77
77
|
end
|
78
78
|
|
79
79
|
def xpath_element
|
80
|
-
data[
|
80
|
+
data[:xpath_element]
|
81
81
|
end
|
82
82
|
# END TODO remove
|
83
83
|
|
84
84
|
def reflex_controller
|
85
|
-
data[
|
85
|
+
data[:reflex_controller]
|
86
86
|
end
|
87
87
|
|
88
88
|
def npm_version
|
89
|
-
data[
|
89
|
+
data[:version].to_s
|
90
90
|
end
|
91
91
|
|
92
92
|
def version
|
93
|
-
|
93
|
+
npm_version.gsub("-pre", ".pre").gsub("-rc", ".rc")
|
94
94
|
end
|
95
95
|
|
96
96
|
private
|
@@ -1,36 +1,59 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class StimulusReflex::ReflexFactory
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
4
|
+
attr_reader :channel, :data
|
5
|
+
|
6
|
+
delegate :reflex_name, :method_name, to: :data
|
7
|
+
|
8
|
+
def initialize(channel, data)
|
9
|
+
@channel = channel
|
10
|
+
@data = StimulusReflex::ReflexData.new(data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
verify_method_name!
|
15
|
+
reflex_class.new(channel, reflex_data: data)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def verify_method_name!
|
21
|
+
return if default_reflex?
|
22
|
+
|
23
|
+
argument_error = ArgumentError.new("Reflex method '#{method_name}' is not defined on class '#{reflex_name}' or on any of its ancestors")
|
24
|
+
|
25
|
+
if reflex_method.nil?
|
26
|
+
raise argument_error
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
if !safe_ancestors.include?(reflex_method.owner)
|
30
|
+
raise argument_error
|
30
31
|
end
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
def reflex_class
|
35
|
+
@reflex_class ||= reflex_name.constantize.tap do |klass|
|
36
|
+
unless klass.ancestors.include?(StimulusReflex::Reflex)
|
37
|
+
raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex")
|
38
|
+
end
|
34
39
|
end
|
35
40
|
end
|
41
|
+
|
42
|
+
def reflex_method
|
43
|
+
if reflex_class.public_instance_methods.include?(method_name.to_sym)
|
44
|
+
reflex_class.public_instance_method(method_name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_reflex?
|
49
|
+
method_name == "default_reflex" && reflex_method.owner == ::StimulusReflex::Reflex
|
50
|
+
end
|
51
|
+
|
52
|
+
def safe_ancestors
|
53
|
+
# We want to include every class and module up to the `StimulusReflex::Reflex` class,
|
54
|
+
# but not the StimulusReflex::Reflex itself
|
55
|
+
reflex_class_index = reflex_class.ancestors.index(StimulusReflex::Reflex) - 1
|
56
|
+
|
57
|
+
reflex_class.ancestors.to(reflex_class_index)
|
58
|
+
end
|
36
59
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "stimulus_reflex/installer"
|
4
|
+
|
3
5
|
SR_STEPS = {
|
4
6
|
"action_cable" => "Action Cable",
|
5
7
|
"webpacker" => "Install StimulusReflex using Webpacker",
|
@@ -51,17 +53,18 @@ end
|
|
51
53
|
namespace :stimulus_reflex do
|
52
54
|
desc "✨ Install StimulusReflex and CableReady ✨"
|
53
55
|
task :install do
|
54
|
-
|
55
|
-
|
56
|
+
create_dir_if_not_exists(Rails.root.join("tmp/stimulus_reflex_installer/templates"))
|
57
|
+
create_dir_if_not_exists(Rails.root.join("tmp/stimulus_reflex_installer/working"))
|
58
|
+
|
56
59
|
install_complete = Rails.root.join("tmp/stimulus_reflex_installer/complete")
|
57
60
|
|
58
|
-
|
61
|
+
used_bundler = nil
|
59
62
|
options = {}
|
60
63
|
|
61
64
|
ARGV.each do |arg|
|
62
65
|
# make sure we have a valid build tool specified, or proceed to automatic detection
|
63
66
|
if ["webpacker", "esbuild", "vite", "shakapacker", "importmap"].include?(arg)
|
64
|
-
|
67
|
+
used_bundler = arg
|
65
68
|
else
|
66
69
|
kv = arg.split("=")
|
67
70
|
if kv.length == 2
|
@@ -90,9 +93,9 @@ namespace :stimulus_reflex do
|
|
90
93
|
end
|
91
94
|
|
92
95
|
# if there is an installation in progress, continue where we left off
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
+
if installer_entrypoint_path.exist?
|
97
|
+
entrypoint = installer_entrypoint_path.read
|
98
|
+
|
96
99
|
puts "✨ Resuming \e[38;5;220mStimulusReflex\e[0m and \e[38;5;220mCableReady\e[0m installation ✨"
|
97
100
|
puts
|
98
101
|
puts "If you have any setup issues, please consult \e[4;97mhttps://docs.stimulusreflex.com/hello-world/setup\e[0m"
|
@@ -106,69 +109,35 @@ namespace :stimulus_reflex do
|
|
106
109
|
puts
|
107
110
|
puts "If you have any setup issues, please consult \e[4;97mhttps://docs.stimulusreflex.com/hello-world/setup\e[0m"
|
108
111
|
puts "or get help on Discord: \e[4;97mhttps://discord.gg/stimulus-reflex\e[0m. \e[38;5;196mWe are here for you.\e[0m 💙"
|
112
|
+
|
109
113
|
if Rails.root.join(".git").exist?
|
110
114
|
puts
|
111
115
|
puts "We recommend running \e[1;94mgit commit\e[0m before proceeding. A diff will be generated at the end."
|
112
116
|
end
|
113
117
|
|
114
|
-
if options.key? "entrypoint"
|
115
|
-
|
118
|
+
entrypoint = if options.key? "entrypoint"
|
119
|
+
options["entrypoint"]
|
116
120
|
else
|
117
|
-
|
118
|
-
"app/javascript",
|
119
|
-
"app/frontend"
|
120
|
-
].find { |path| File.exist?(Rails.root.join(path)) } || "app/javascript"
|
121
|
-
|
122
|
-
puts
|
123
|
-
puts "Where do JavaScript files live in your app? Our best guess is: \e[1m#{entrypoint}\e[22m 🤔"
|
124
|
-
puts "Press enter to accept this, or type a different path."
|
125
|
-
print "> "
|
126
|
-
input = $stdin.gets.chomp
|
127
|
-
entrypoint = input unless input.blank?
|
121
|
+
auto_detect_entrypoint
|
128
122
|
end
|
129
|
-
|
123
|
+
|
124
|
+
installer_entrypoint_path.write(entrypoint)
|
130
125
|
end
|
131
126
|
|
132
127
|
# verify their bundler before starting, unless they explicitly specified on CLI
|
133
|
-
if !
|
134
|
-
|
135
|
-
if Rails.root.join("config/importmap.rb").exist?
|
136
|
-
bundler = "importmap"
|
137
|
-
elsif Rails.root.join("package.json").exist?
|
138
|
-
package_json = File.read(Rails.root.join("package.json"))
|
139
|
-
bundler = "webpacker" if package_json.include?('"@rails/webpacker":')
|
140
|
-
bundler = "esbuild" if package_json.include?('"esbuild":')
|
141
|
-
bundler = "vite" if package_json.include?('"vite":')
|
142
|
-
bundler = "shakapacker" if package_json.include?('"shakapacker":')
|
143
|
-
if !bundler
|
144
|
-
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."
|
145
|
-
exit
|
146
|
-
end
|
147
|
-
else
|
148
|
-
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."
|
149
|
-
exit
|
150
|
-
end
|
151
|
-
|
152
|
-
puts
|
153
|
-
puts "It looks like you're using \e[1m#{bundler}\e[22m as your bundler. Is that correct? (Y/n)"
|
154
|
-
print "> "
|
155
|
-
input = $stdin.gets.chomp
|
156
|
-
if input.downcase == "n"
|
157
|
-
puts
|
158
|
-
puts "StimulusReflex installation supports: esbuild, webpacker, vite, shakapacker and importmap."
|
159
|
-
puts "Please run \e[1;94mrails stimulus_reflex:install [bundler]\e[0m to install StimulusReflex and CableReady."
|
160
|
-
exit
|
161
|
-
end
|
128
|
+
if !used_bundler
|
129
|
+
used_bundler = bundler
|
162
130
|
end
|
163
131
|
|
164
|
-
|
132
|
+
installer_bundler_path.write(used_bundler)
|
133
|
+
|
165
134
|
FileUtils.touch("tmp/stimulus_reflex_installer/backups")
|
166
135
|
File.write("tmp/stimulus_reflex_installer/template_src", File.expand_path("../../generators/stimulus_reflex/templates/", __dir__))
|
167
136
|
|
168
137
|
`bin/spring stop` if defined?(Spring)
|
169
138
|
|
170
139
|
# do the things
|
171
|
-
SR_BUNDLERS[
|
140
|
+
SR_BUNDLERS[used_bundler].each do |template|
|
172
141
|
run_install_template(template, trace: !!options["trace"])
|
173
142
|
end
|
174
143
|
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "stimulus_reflex",
|
3
|
-
"version": "3.5.0-
|
3
|
+
"version": "3.5.0-rc4",
|
4
4
|
"description": "Build reactive applications with the Rails tooling you already know and love.",
|
5
5
|
"keywords": [
|
6
6
|
"ruby",
|
@@ -57,7 +57,7 @@
|
|
57
57
|
"dependencies": {
|
58
58
|
"@hotwired/stimulus": "^3",
|
59
59
|
"@rails/actioncable": "^6 || ^7",
|
60
|
-
"cable_ready": "5.0.0
|
60
|
+
"cable_ready": "^5.0.0"
|
61
61
|
},
|
62
62
|
"devDependencies": {
|
63
63
|
"@open-wc/testing": "^3.1.7",
|
@@ -70,6 +70,6 @@
|
|
70
70
|
"prettier-standard": "^16.4.1",
|
71
71
|
"rollup": "^3.19.1",
|
72
72
|
"toastify-js": "^1.12.0",
|
73
|
-
"vitepress": "^1.0.0-
|
73
|
+
"vitepress": "^1.0.0-beta.1"
|
74
74
|
}
|
75
75
|
}
|
data/stimulus_reflex.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |gem|
|
|
37
37
|
"[A-Z]*"
|
38
38
|
]
|
39
39
|
|
40
|
-
gem.required_ruby_version = ">=
|
40
|
+
gem.required_ruby_version = ">= 3.0.0"
|
41
41
|
|
42
42
|
rails_version = [">= 5.2", "< 8"]
|
43
43
|
gem.add_dependency "actioncable", *rails_version
|
@@ -46,7 +46,7 @@ Gem::Specification.new do |gem|
|
|
46
46
|
gem.add_dependency "activesupport", *rails_version
|
47
47
|
gem.add_dependency "railties", *rails_version
|
48
48
|
|
49
|
-
gem.add_dependency "cable_ready", "
|
49
|
+
gem.add_dependency "cable_ready", "~> 5.0"
|
50
50
|
gem.add_dependency "nokogiri", "~> 1.0"
|
51
51
|
gem.add_dependency "rack", ">= 2", "< 4"
|
52
52
|
gem.add_dependency "redis", ">= 4.0", "< 6.0"
|