stimulus_reflex 3.5.0.rc2 → 3.5.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of stimulus_reflex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile.lock +21 -18
- data/app/assets/javascripts/stimulus_reflex.js +3 -3
- data/app/assets/javascripts/stimulus_reflex.umd.js +3 -3
- data/app/channels/stimulus_reflex/channel.rb +1 -1
- 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 +3 -3
- data/lib/stimulus_reflex/cable_readiness.rb +1 -7
- data/lib/stimulus_reflex/installer.rb +88 -7
- 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 +1 -1
- data/yarn.lock +500 -440
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cce31cfe35841f8e96b70fe52e22ee84cf6aa287562b3ab6d1d0ee318fa109ee
|
4
|
+
data.tar.gz: 33e86551718a90441a3110e7daf72c110ecf42fcd73105d788ec508d92a30ca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a56cd9fcedd2859b3d9b828dbc0fc91c59e9b773ddb983a22ce23709bc443ab4cbd25270bfda366a4594767f08f9964af4fd30475307889eb6ab10ad187828f3
|
7
|
+
data.tar.gz: a5f3a462fe156023852d2db3911040436034c3fe54e3716aeecad1fcf2aa0ef86484f04236f20fa75ae149a3530dad23d8935d71a8dd817da43084ce2d895c8a
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stimulus_reflex (3.5.0.
|
4
|
+
stimulus_reflex (3.5.0.rc3)
|
5
5
|
actioncable (>= 5.2, < 8)
|
6
6
|
actionpack (>= 5.2, < 8)
|
7
7
|
actionview (>= 5.2, < 8)
|
8
8
|
activesupport (>= 5.2, < 8)
|
9
|
-
cable_ready (
|
9
|
+
cable_ready (~> 5.0)
|
10
10
|
nokogiri (~> 1.0)
|
11
11
|
rack (>= 2, < 4)
|
12
12
|
railties (>= 5.2, < 8)
|
@@ -82,7 +82,7 @@ GEM
|
|
82
82
|
tzinfo (~> 2.0)
|
83
83
|
ast (2.4.2)
|
84
84
|
builder (3.2.4)
|
85
|
-
cable_ready (5.0.
|
85
|
+
cable_ready (5.0.1)
|
86
86
|
actionpack (>= 5.2)
|
87
87
|
actionview (>= 5.2)
|
88
88
|
activesupport (>= 5.2)
|
@@ -95,13 +95,13 @@ GEM
|
|
95
95
|
erubi (1.12.0)
|
96
96
|
globalid (1.1.0)
|
97
97
|
activesupport (>= 5.0)
|
98
|
-
i18n (1.
|
98
|
+
i18n (1.14.1)
|
99
99
|
concurrent-ruby (~> 1.0)
|
100
100
|
json (2.6.3)
|
101
101
|
language_server-protocol (3.17.0.3)
|
102
|
-
loofah (2.
|
102
|
+
loofah (2.21.3)
|
103
103
|
crass (~> 1.0.2)
|
104
|
-
nokogiri (>= 1.
|
104
|
+
nokogiri (>= 1.12.0)
|
105
105
|
magic_frozen_string_literal (1.2.0)
|
106
106
|
mail (2.8.1)
|
107
107
|
mini_mime (>= 0.1.1)
|
@@ -111,7 +111,7 @@ GEM
|
|
111
111
|
marcel (1.0.2)
|
112
112
|
method_source (1.0.0)
|
113
113
|
mini_mime (1.1.2)
|
114
|
-
minitest (5.18.
|
114
|
+
minitest (5.18.1)
|
115
115
|
mocha (1.13.0)
|
116
116
|
net-imap (0.3.4)
|
117
117
|
date
|
@@ -123,15 +123,15 @@ GEM
|
|
123
123
|
net-smtp (0.3.3)
|
124
124
|
net-protocol
|
125
125
|
nio4r (2.5.8)
|
126
|
-
nokogiri (1.
|
126
|
+
nokogiri (1.15.3-x86_64-darwin)
|
127
127
|
racc (~> 1.4)
|
128
|
-
nokogiri (1.
|
128
|
+
nokogiri (1.15.3-x86_64-linux)
|
129
129
|
racc (~> 1.4)
|
130
130
|
parallel (1.22.1)
|
131
131
|
parser (3.2.1.0)
|
132
132
|
ast (~> 2.4.1)
|
133
|
-
racc (1.
|
134
|
-
rack (2.2.
|
133
|
+
racc (1.7.1)
|
134
|
+
rack (2.2.7)
|
135
135
|
rack-test (2.1.0)
|
136
136
|
rack (>= 1.3)
|
137
137
|
rails (7.0.4.2)
|
@@ -148,11 +148,13 @@ GEM
|
|
148
148
|
activesupport (= 7.0.4.2)
|
149
149
|
bundler (>= 1.15.0)
|
150
150
|
railties (= 7.0.4.2)
|
151
|
-
rails-dom-testing (2.
|
152
|
-
activesupport (>=
|
151
|
+
rails-dom-testing (2.1.1)
|
152
|
+
activesupport (>= 5.0.0)
|
153
|
+
minitest
|
153
154
|
nokogiri (>= 1.6)
|
154
|
-
rails-html-sanitizer (1.
|
155
|
-
loofah (~> 2.
|
155
|
+
rails-html-sanitizer (1.6.0)
|
156
|
+
loofah (~> 2.21)
|
157
|
+
nokogiri (~> 1.14)
|
156
158
|
railties (7.0.4.2)
|
157
159
|
actionpack (= 7.0.4.2)
|
158
160
|
activesupport (= 7.0.4.2)
|
@@ -188,7 +190,7 @@ GEM
|
|
188
190
|
language_server-protocol (~> 3.17.0.2)
|
189
191
|
rubocop (= 1.44.1)
|
190
192
|
rubocop-performance (= 1.15.2)
|
191
|
-
thor (1.2.
|
193
|
+
thor (1.2.2)
|
192
194
|
thread-local (1.1.0)
|
193
195
|
timeout (0.3.2)
|
194
196
|
tzinfo (2.0.6)
|
@@ -197,10 +199,11 @@ GEM
|
|
197
199
|
websocket-driver (0.7.5)
|
198
200
|
websocket-extensions (>= 0.1.0)
|
199
201
|
websocket-extensions (0.1.5)
|
200
|
-
zeitwerk (2.6.
|
202
|
+
zeitwerk (2.6.8)
|
201
203
|
|
202
204
|
PLATFORMS
|
203
205
|
x86_64-darwin-19
|
206
|
+
x86_64-darwin-22
|
204
207
|
x86_64-linux
|
205
208
|
|
206
209
|
DEPENDENCIES
|
@@ -213,4 +216,4 @@ DEPENDENCIES
|
|
213
216
|
stimulus_reflex!
|
214
217
|
|
215
218
|
BUNDLED WITH
|
216
|
-
2.
|
219
|
+
2.4.14
|
@@ -945,7 +945,7 @@ const extractDataAttributes = element => {
|
|
945
945
|
|
946
946
|
var name = "stimulus_reflex";
|
947
947
|
|
948
|
-
var version = "3.5.0-
|
948
|
+
var version = "3.5.0-rc3";
|
949
949
|
|
950
950
|
var description = "Build reactive applications with the Rails tooling you already know and love.";
|
951
951
|
|
@@ -995,7 +995,7 @@ var peerDependencies = {
|
|
995
995
|
var dependencies = {
|
996
996
|
"@hotwired/stimulus": "^3",
|
997
997
|
"@rails/actioncable": "^6 || ^7",
|
998
|
-
cable_ready: "5.0.0
|
998
|
+
cable_ready: "^5.0.0"
|
999
999
|
};
|
1000
1000
|
|
1001
1001
|
var devDependencies = {
|
@@ -1009,7 +1009,7 @@ var devDependencies = {
|
|
1009
1009
|
"prettier-standard": "^16.4.1",
|
1010
1010
|
rollup: "^3.19.1",
|
1011
1011
|
"toastify-js": "^1.12.0",
|
1012
|
-
vitepress: "^1.0.0-
|
1012
|
+
vitepress: "^1.0.0-beta.1"
|
1013
1013
|
};
|
1014
1014
|
|
1015
1015
|
var packageInfo = {
|
@@ -869,7 +869,7 @@
|
|
869
869
|
return attrs;
|
870
870
|
};
|
871
871
|
var name = "stimulus_reflex";
|
872
|
-
var version = "3.5.0-
|
872
|
+
var version = "3.5.0-rc3";
|
873
873
|
var description = "Build reactive applications with the Rails tooling you already know and love.";
|
874
874
|
var keywords = [ "ruby", "rails", "websockets", "actioncable", "turbolinks", "reactive", "cable", "ujs", "ssr", "stimulus", "reflex", "stimulus_reflex", "dom", "morphdom" ];
|
875
875
|
var homepage = "https://docs.stimulusreflex.com";
|
@@ -902,7 +902,7 @@
|
|
902
902
|
var dependencies = {
|
903
903
|
"@hotwired/stimulus": "^3",
|
904
904
|
"@rails/actioncable": "^6 || ^7",
|
905
|
-
cable_ready: "5.0.0
|
905
|
+
cable_ready: "^5.0.0"
|
906
906
|
};
|
907
907
|
var devDependencies = {
|
908
908
|
"@open-wc/testing": "^3.1.7",
|
@@ -915,7 +915,7 @@
|
|
915
915
|
"prettier-standard": "^16.4.1",
|
916
916
|
rollup: "^3.19.1",
|
917
917
|
"toastify-js": "^1.12.0",
|
918
|
-
vitepress: "^1.0.0-
|
918
|
+
vitepress: "^1.0.0-beta.1"
|
919
919
|
};
|
920
920
|
var packageInfo = {
|
921
921
|
name: name,
|
@@ -27,7 +27,7 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
|
|
27
27
|
reflex.logger&.error error_message
|
28
28
|
reflex.broadcast_error data: data, error: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}"
|
29
29
|
else
|
30
|
-
unless exception.is_a?(StimulusReflex::
|
30
|
+
unless exception.is_a?(StimulusReflex::VersionMismatchError)
|
31
31
|
StimulusReflex.config.logger.error error_message
|
32
32
|
end
|
33
33
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "rails/generators"
|
4
4
|
require "stimulus_reflex/version"
|
5
|
+
require "stimulus_reflex/installer"
|
5
6
|
|
6
7
|
class StimulusReflexGenerator < Rails::Generators::NamedBase
|
7
8
|
source_root File.expand_path("templates", __dir__)
|
@@ -13,33 +14,20 @@ class StimulusReflexGenerator < Rails::Generators::NamedBase
|
|
13
14
|
def execute
|
14
15
|
actions.map!(&:underscore)
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Rails.root.join("app/javascript"),
|
22
|
-
Rails.root.join("app/frontend")
|
23
|
-
].find(&:exist?) || "app/javascript"
|
24
|
-
puts "Where do JavaScript files live in your app? Our best guess is: \e[1#{entrypoint}\e[22m 🤔"
|
25
|
-
puts "Press enter to accept this, or type a different path."
|
26
|
-
print "> "
|
27
|
-
input = Rails.env.test? ? "tmp/app/javascript" : $stdin.gets.chomp
|
28
|
-
entrypoint = input unless input.blank?
|
29
|
-
end
|
17
|
+
reflex_entrypoint = Rails.env.test? ? "tmp/app/reflexes" : "app/reflexes"
|
18
|
+
reflex_src = "app/reflexes/%file_name%_reflex.rb.tt"
|
19
|
+
reflex_path = Rails.root.join(reflex_entrypoint, "#{file_name}_reflex.rb")
|
20
|
+
|
21
|
+
template(reflex_src, reflex_path) unless options[:skip_reflex]
|
30
22
|
|
31
23
|
if !options[:skip_stimulus] && entrypoint.blank?
|
32
24
|
puts "❌ You must specify a valid JavaScript entrypoint."
|
33
25
|
exit
|
34
26
|
end
|
35
27
|
|
36
|
-
reflex_entrypoint = Rails.env.test? ? "tmp/app/reflexes" : "app/reflexes"
|
37
|
-
reflex_src = "app/reflexes/%file_name%_reflex.rb.tt"
|
38
|
-
reflex_path = Rails.root.join(reflex_entrypoint, "#{file_name}_reflex.rb")
|
39
28
|
stimulus_controller_src = "app/javascript/controllers/%file_name%_controller.js.tt"
|
40
29
|
stimulus_controller_path = Rails.root.join(entrypoint, "controllers/#{file_name}_controller.js")
|
41
30
|
|
42
|
-
template(reflex_src, reflex_path) unless options[:skip_reflex]
|
43
31
|
template(stimulus_controller_src, stimulus_controller_path) unless options[:skip_stimulus]
|
44
32
|
|
45
33
|
if file_name == "example"
|
@@ -1,4 +1,8 @@
|
|
1
|
-
|
2
|
-
import
|
1
|
+
<%- if bundler.importmap? -%>
|
2
|
+
import consumer from "channels/consumer"
|
3
|
+
<%- else -%>
|
4
|
+
import consumer from "../channels/consumer"
|
5
|
+
<%- end -%>
|
6
|
+
import CableReady from "cable_ready"
|
3
7
|
|
4
8
|
CableReady.initialize({ consumer })
|
@@ -1,5 +1,10 @@
|
|
1
|
+
<%- if bundler.importmap? -%>
|
2
|
+
import { application } from "controllers/application"
|
3
|
+
import controller from "controllers/application_controller"
|
4
|
+
<%- else -%>
|
1
5
|
import { application } from "../controllers/application"
|
2
6
|
import controller from "../controllers/application_controller"
|
7
|
+
<%- end -%>
|
3
8
|
import StimulusReflex from "stimulus_reflex"
|
4
9
|
|
5
10
|
StimulusReflex.initialize(application, { controller, isolate: true })
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
1
|
+
<%- if bundler.importmap? -%>
|
2
|
+
import ApplicationController from "controllers/application_controller"
|
3
|
+
<%- else -%>
|
4
|
+
import ApplicationController from "./application_controller"
|
5
|
+
<%- end -%>
|
2
6
|
|
3
7
|
<%- if class_name == "Example" -%>
|
4
|
-
//
|
8
|
+
//
|
5
9
|
// This is the Stimulus controller for the Example Reflex.
|
6
10
|
//
|
7
11
|
// It corresponds to the server-side Reflex class located at /app/reflexes/example.rb
|
@@ -1,11 +1,15 @@
|
|
1
1
|
import { Application } from "@hotwired/stimulus"
|
2
|
+
<%- if bundler.importmap? %>
|
3
|
+
import consumer from "channels/consumer"
|
4
|
+
<%- else %>
|
2
5
|
import consumer from "../channels/consumer"
|
6
|
+
<%- end %>
|
3
7
|
|
4
8
|
const application = Application.start()
|
5
9
|
|
6
10
|
// Configure Stimulus development experience
|
7
11
|
application.debug = false
|
8
12
|
application.consumer = consumer
|
9
|
-
window.Stimulus
|
13
|
+
window.Stimulus = application
|
10
14
|
|
11
15
|
export { application }
|
data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.importmap.tt
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
|
1
|
+
// Import and register all your controllers from the importmap under controllers/*
|
2
|
+
|
3
|
+
import { application } from "controllers/application"
|
2
4
|
|
3
5
|
// Eager load all controllers defined in the import map under controllers/**/*_controller
|
4
6
|
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
|
5
7
|
eagerLoadControllersFrom("controllers", application)
|
8
|
+
|
9
|
+
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
|
10
|
+
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
|
11
|
+
// lazyLoadControllersFrom("controllers", application)
|
data/lib/install/config.rb
CHANGED
@@ -20,7 +20,7 @@ if index_path.exist?
|
|
20
20
|
say "⏩ #{friendly_index_path} already exists. Skipping"
|
21
21
|
else
|
22
22
|
backup(index_path, delete: true) do
|
23
|
-
|
23
|
+
template(index_src, index_path)
|
24
24
|
end
|
25
25
|
say "✅ Created #{friendly_index_path}"
|
26
26
|
end
|
@@ -50,22 +50,22 @@ else
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# create entrypoint/config/cable_ready.js and make sure it's imported in application.js
|
53
|
-
|
53
|
+
template(cable_ready_src, cable_ready_path) unless cable_ready_path.exist?
|
54
54
|
|
55
55
|
# create entrypoint/config/stimulus_reflex.js and make sure it's imported in application.js
|
56
|
-
|
56
|
+
template(stimulus_reflex_src, stimulus_reflex_path) unless stimulus_reflex_path.exist?
|
57
57
|
|
58
58
|
if stimulus_reflex_path.read.include?("StimulusReflex.debug =")
|
59
59
|
say "⏩ Development environment options are already set in #{friendly_stimulus_reflex_path}. Skipping"
|
60
60
|
else
|
61
|
-
if
|
61
|
+
if bundler.webpacker? || bundler.shakapacker?
|
62
62
|
append_file(stimulus_reflex_path, <<~JS, verbose: false)
|
63
63
|
|
64
64
|
if (process.env.RAILS_ENV === 'development') {
|
65
65
|
StimulusReflex.debug = true
|
66
66
|
}
|
67
67
|
JS
|
68
|
-
elsif bundler
|
68
|
+
elsif bundler.vite?
|
69
69
|
append_file(stimulus_reflex_path, <<~JS, verbose: false) unless stimulus_reflex_path.read.include?("StimulusReflex.debug")
|
70
70
|
|
71
71
|
if (import.meta.env.MODE === "development") {
|
data/lib/install/esbuild.rb
CHANGED
@@ -5,7 +5,7 @@ require "stimulus_reflex/installer"
|
|
5
5
|
return if pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines =
|
8
|
+
lines = package_json_path.readlines
|
9
9
|
|
10
10
|
if !lines.index { |line| line =~ /^\s*["']esbuild-rails["']: ["']\^1.0.3["']/ }
|
11
11
|
add_package "esbuild-rails@^1.0.3"
|
data/lib/install/importmap.rb
CHANGED
@@ -104,12 +104,12 @@ backup(application_js_path) do
|
|
104
104
|
if application_js_path.read.include?("import consumer")
|
105
105
|
say "⏩ #{friendly_application_js_path} is present. Skipping."
|
106
106
|
else
|
107
|
-
inject_into_file application_js_path, "import consumer from \"
|
107
|
+
inject_into_file application_js_path, "import consumer from \"channels/consumer\"\n", after: "import { Application } from \"@hotwired/stimulus\"\n", verbose: false
|
108
108
|
inject_into_file application_js_path, "application.consumer = consumer\n", after: "application.debug = false\n", verbose: false
|
109
109
|
say "✅ #{friendly_application_js_path} has been updated to import the Action Cable consumer"
|
110
110
|
end
|
111
111
|
else
|
112
|
-
|
112
|
+
template(application_js_src, application_js_path)
|
113
113
|
say "✅ #{friendly_application_js_path} has been created"
|
114
114
|
end
|
115
115
|
end
|
data/lib/install/mrujs.rb
CHANGED
@@ -17,7 +17,7 @@ if !File.exist?(mrujs_path)
|
|
17
17
|
end
|
18
18
|
|
19
19
|
if proceed
|
20
|
-
if bundler
|
20
|
+
if bundler.importmap?
|
21
21
|
|
22
22
|
if !importmap_path.exist?
|
23
23
|
halt "#{friendly_importmap_path} is missing. You need a valid importmap config file to proceed."
|
@@ -45,14 +45,14 @@ if proceed
|
|
45
45
|
end
|
46
46
|
else
|
47
47
|
# queue mrujs for installation
|
48
|
-
if
|
48
|
+
if package_json_path.read.include?('"mrujs":')
|
49
49
|
say "⏩ mrujs already present. Skipping."
|
50
50
|
else
|
51
51
|
add_package "mrujs@^0.10.1"
|
52
52
|
end
|
53
53
|
|
54
54
|
# queue @rails/ujs for removal
|
55
|
-
if
|
55
|
+
if package_json_path.read.include?('"@rails/ujs":')
|
56
56
|
drop_package "@rails/ujs"
|
57
57
|
else
|
58
58
|
say "⏩ @rails/ujs not present. Skipping."
|
@@ -70,10 +70,15 @@ if proceed
|
|
70
70
|
index = index_path.read
|
71
71
|
friendly_index_path = index_path.relative_path_from(Rails.root).to_s
|
72
72
|
mrujs_pattern = /import ['"].\/mrujs['"]/
|
73
|
-
|
73
|
+
|
74
|
+
mrujs_import = if bundler.importmap?
|
75
|
+
%(import "config/mrujs"\n)
|
76
|
+
else
|
77
|
+
%(import "./mrujs"\n)
|
78
|
+
end
|
74
79
|
|
75
80
|
if index.match?(mrujs_pattern)
|
76
|
-
say "⏩ mrujs
|
81
|
+
say "⏩ mrujs already imported in #{friendly_index_path}. Skipping."
|
77
82
|
else
|
78
83
|
append_file(index_path, mrujs_import, verbose: false)
|
79
84
|
say "✅ mrujs imported in #{friendly_index_path}"
|
data/lib/install/npm_packages.rb
CHANGED
data/lib/install/shakapacker.rb
CHANGED
@@ -5,7 +5,7 @@ require "stimulus_reflex/installer"
|
|
5
5
|
return if pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines =
|
8
|
+
lines = package_json_path.readlines
|
9
9
|
|
10
10
|
if !lines.index { |line| line =~ /^\s*["']@hotwired\/stimulus-webpack-helpers["']: ["']\^1.0.1["']/ }
|
11
11
|
add_package "@hotwired/stimulus-webpack-helpers@^1.0.1"
|
data/lib/install/vite.rb
CHANGED
@@ -5,7 +5,7 @@ require "stimulus_reflex/installer"
|
|
5
5
|
return if pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines =
|
8
|
+
lines = package_json_path.readlines
|
9
9
|
|
10
10
|
if !lines.index { |line| line =~ /^\s*["']stimulus-vite-helpers["']: ["']\^3["']/ }
|
11
11
|
add_package "stimulus-vite-helpers@^3"
|
data/lib/install/webpacker.rb
CHANGED
@@ -5,7 +5,7 @@ require "stimulus_reflex/installer"
|
|
5
5
|
return if pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines =
|
8
|
+
lines = package_json_path.readlines
|
9
9
|
if !lines.index { |line| line =~ /^\s*["']webpack["']: ["']\^4.46.0["']/ }
|
10
10
|
add_package "webpack@^4.46.0"
|
11
11
|
else
|
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
|
@@ -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
|