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
data/lib/install/esbuild.rb
CHANGED
@@ -2,46 +2,46 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
return if pack_path_missing?
|
5
|
+
return if StimulusReflex::Installer.pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines = package_json_path.readlines
|
8
|
+
lines = StimulusReflex::Installer.package_json_path.readlines
|
9
9
|
|
10
10
|
if !lines.index { |line| line =~ /^\s*["']esbuild-rails["']: ["']\^1.0.3["']/ }
|
11
|
-
add_package "esbuild-rails@^1.0.3"
|
11
|
+
StimulusReflex::Installer.add_package "esbuild-rails@^1.0.3"
|
12
12
|
else
|
13
13
|
say "⏩ esbuild-rails npm package is already present. Skipping."
|
14
14
|
end
|
15
15
|
|
16
16
|
# copy esbuild.config.mjs to app root
|
17
|
-
esbuild_src = fetch("/", "esbuild.config.mjs.tt")
|
17
|
+
esbuild_src = StimulusReflex::Installer.fetch("/", "esbuild.config.mjs.tt")
|
18
18
|
esbuild_path = Rails.root.join("esbuild.config.mjs")
|
19
19
|
|
20
20
|
if esbuild_path.exist?
|
21
21
|
if esbuild_path.read == esbuild_src.read
|
22
22
|
say "⏩ esbuild.config.mjs already present in app root. Skipping."
|
23
23
|
else
|
24
|
-
backup(esbuild_path) do
|
25
|
-
template(esbuild_src, esbuild_path, verbose: false, entrypoint: entrypoint)
|
24
|
+
StimulusReflex::Installer.backup(esbuild_path) do
|
25
|
+
template(esbuild_src, esbuild_path, verbose: false, entrypoint: StimulusReflex::Installer.entrypoint)
|
26
26
|
end
|
27
27
|
say "✅ updated esbuild.config.mjs in app root"
|
28
28
|
end
|
29
29
|
else
|
30
|
-
template(esbuild_src, esbuild_path, entrypoint: entrypoint)
|
30
|
+
template(esbuild_src, esbuild_path, entrypoint: StimulusReflex::Installer.entrypoint)
|
31
31
|
say "✅ Created esbuild.config.mjs in app root"
|
32
32
|
end
|
33
33
|
|
34
34
|
step_path = "/app/javascript/controllers/"
|
35
|
-
application_controller_src = fetch(step_path, "application_controller.js.tt")
|
36
|
-
application_controller_path = controllers_path / "application_controller.js"
|
37
|
-
application_js_src = fetch(step_path, "application.js.tt")
|
38
|
-
application_js_path = controllers_path / "application.js"
|
39
|
-
index_src = fetch(step_path, "index.js.esbuild.tt")
|
40
|
-
index_path = controllers_path / "index.js"
|
35
|
+
application_controller_src = StimulusReflex::Installer.fetch(step_path, "application_controller.js.tt")
|
36
|
+
application_controller_path = StimulusReflex::Installer.controllers_path / "application_controller.js"
|
37
|
+
application_js_src = StimulusReflex::Installer.fetch(step_path, "application.js.tt")
|
38
|
+
application_js_path = StimulusReflex::Installer.controllers_path / "application.js"
|
39
|
+
index_src = StimulusReflex::Installer.fetch(step_path, "index.js.esbuild.tt")
|
40
|
+
index_path = StimulusReflex::Installer.controllers_path / "index.js"
|
41
41
|
friendly_index_path = index_path.relative_path_from(Rails.root).to_s
|
42
42
|
|
43
43
|
# create entrypoint/controllers, if necessary
|
44
|
-
empty_directory controllers_path unless controllers_path.exist?
|
44
|
+
empty_directory StimulusReflex::Installer.controllers_path unless StimulusReflex::Installer.controllers_path.exist?
|
45
45
|
|
46
46
|
# copy application_controller.js, if necessary
|
47
47
|
copy_file(application_controller_src, application_controller_path) unless application_controller_path.exist?
|
@@ -50,7 +50,7 @@ copy_file(application_controller_src, application_controller_path) unless applic
|
|
50
50
|
friendly_application_js_path = application_js_path.relative_path_from(Rails.root).to_s
|
51
51
|
|
52
52
|
if application_js_path.exist?
|
53
|
-
backup(application_js_path) do
|
53
|
+
StimulusReflex::Installer.backup(application_js_path) do
|
54
54
|
if application_js_path.read.include?("import consumer")
|
55
55
|
say "⏩ #{friendly_application_js_path} is already present. Skipping."
|
56
56
|
else
|
@@ -68,7 +68,7 @@ if index_path.exist?
|
|
68
68
|
if index_path.read == index_src.read
|
69
69
|
say "⏩ #{friendly_index_path} already present. Skipping."
|
70
70
|
else
|
71
|
-
backup(index_path, delete: true) do
|
71
|
+
StimulusReflex::Installer.backup(index_path, delete: true) do
|
72
72
|
copy_file(index_src, index_path, verbose: false)
|
73
73
|
end
|
74
74
|
|
@@ -82,33 +82,33 @@ end
|
|
82
82
|
controllers_pattern = /import ['"].\/controllers['"]/
|
83
83
|
controllers_commented_pattern = /\s*\/\/\s*#{controllers_pattern}/
|
84
84
|
|
85
|
-
if pack.match?(controllers_pattern)
|
86
|
-
if pack.match?(controllers_commented_pattern)
|
87
|
-
proceed = if options.key? "uncomment"
|
88
|
-
options["uncomment"]
|
85
|
+
if StimulusReflex::Installer.pack.match?(controllers_pattern)
|
86
|
+
if StimulusReflex::Installer.pack.match?(controllers_commented_pattern)
|
87
|
+
proceed = if StimulusReflex::Installer.options.key? "uncomment"
|
88
|
+
StimulusReflex::Installer.options["uncomment"]
|
89
89
|
else
|
90
90
|
!no?("✨ Stimulus seems to be commented out in your application.js. Do you want to import your controllers? (Y/n)")
|
91
91
|
end
|
92
92
|
|
93
93
|
if proceed
|
94
94
|
# uncomment_lines only works with Ruby comments 🙄
|
95
|
-
lines = pack_path.readlines
|
95
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
96
96
|
matches = lines.select { |line| line =~ controllers_commented_pattern }
|
97
97
|
lines[lines.index(matches.last).to_i] = "import \".\/controllers\"\n" # standard:disable Style/RedundantStringEscape
|
98
|
-
pack_path.write lines.join
|
99
|
-
say "✅ Uncommented Stimulus controllers import in #{friendly_pack_path}"
|
98
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
99
|
+
say "✅ Uncommented Stimulus controllers import in #{StimulusReflex::Installer.friendly_pack_path}"
|
100
100
|
else
|
101
101
|
say "🤷 your Stimulus controllers are not being imported in your application.js. We trust that you have a reason for this."
|
102
102
|
end
|
103
103
|
else
|
104
|
-
say "⏩ Stimulus controllers are already being imported in #{friendly_pack_path}. Skipping."
|
104
|
+
say "⏩ Stimulus controllers are already being imported in #{StimulusReflex::Installer.friendly_pack_path}. Skipping."
|
105
105
|
end
|
106
106
|
else
|
107
|
-
lines = pack_path.readlines
|
107
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
108
108
|
matches = lines.select { |line| line =~ /^import / }
|
109
109
|
lines.insert lines.index(matches.last).to_i + 1, "import \".\/controllers\"\n" # standard:disable Style/RedundantStringEscape
|
110
|
-
pack_path.write lines.join
|
111
|
-
say "✅ Stimulus controllers imported in #{friendly_pack_path}"
|
110
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
111
|
+
say "✅ Stimulus controllers imported in #{StimulusReflex::Installer.friendly_pack_path}"
|
112
112
|
end
|
113
113
|
|
114
|
-
complete_step :esbuild
|
114
|
+
StimulusReflex::Installer.complete_step :esbuild
|
data/lib/install/example.rb
CHANGED
@@ -4,8 +4,8 @@ require "stimulus_reflex/installer"
|
|
4
4
|
|
5
5
|
proceed = false
|
6
6
|
if !Rails.root.join("app/reflexes/example_reflex.rb").exist?
|
7
|
-
proceed = if options.key? "example"
|
8
|
-
options["example"]
|
7
|
+
proceed = if StimulusReflex::Installer.options.key? "example"
|
8
|
+
StimulusReflex::Installer.options["example"]
|
9
9
|
else
|
10
10
|
!no?("✨ Generate an example Reflex with a quick demo? You can remove it later with a single command. (Y/n)")
|
11
11
|
end
|
@@ -19,4 +19,4 @@ else
|
|
19
19
|
say "⏩ Skipping."
|
20
20
|
end
|
21
21
|
|
22
|
-
complete_step :example
|
22
|
+
StimulusReflex::Installer.complete_step :example
|
data/lib/install/importmap.rb
CHANGED
@@ -2,37 +2,37 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
return if pack_path_missing?
|
5
|
+
return if StimulusReflex::Installer.pack_path_missing?
|
6
6
|
|
7
|
-
if !importmap_path.exist?
|
8
|
-
halt "#{
|
7
|
+
if !StimulusReflex::Installer.importmap_path.exist?
|
8
|
+
StimulusReflex::Installer.halt "#{friendly_StimulusReflex::Installer.importmap_path} is missing. You need a valid importmap config file to proceed."
|
9
9
|
return
|
10
10
|
end
|
11
11
|
|
12
|
-
importmap = importmap_path.read
|
12
|
+
importmap = StimulusReflex::Installer.importmap_path.read
|
13
13
|
|
14
|
-
backup(importmap_path) do
|
15
|
-
if !importmap.include?("pin_all_from \"#{entrypoint}/controllers\"")
|
16
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
17
|
-
pin_all_from "#{entrypoint}/controllers", under: "controllers"
|
14
|
+
StimulusReflex::Installer.backup(StimulusReflex::Installer.importmap_path) do
|
15
|
+
if !importmap.include?("pin_all_from \"#{StimulusReflex::Installer.entrypoint}/controllers\"")
|
16
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
17
|
+
pin_all_from "#{StimulusReflex::Installer.entrypoint}/controllers", under: "controllers"
|
18
18
|
RUBY
|
19
19
|
say "✅ pin_all_from controllers"
|
20
20
|
else
|
21
21
|
say "⏩ pin_all_from controllers already pinned. Skipping."
|
22
22
|
end
|
23
23
|
|
24
|
-
if !importmap.include?("pin_all_from \"#{entrypoint}/channels\"")
|
25
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
26
|
-
pin_all_from "#{entrypoint}/channels", under: "channels"
|
24
|
+
if !importmap.include?("pin_all_from \"#{StimulusReflex::Installer.entrypoint}/channels\"")
|
25
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
26
|
+
pin_all_from "#{StimulusReflex::Installer.entrypoint}/channels", under: "channels"
|
27
27
|
RUBY
|
28
28
|
say "✅ pin_all_from channels"
|
29
29
|
else
|
30
30
|
say "⏩ pin_all_from channels already pinned. Skipping."
|
31
31
|
end
|
32
32
|
|
33
|
-
if !importmap.include?("pin_all_from \"#{entrypoint}/config\"")
|
34
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
35
|
-
pin_all_from "#{entrypoint}/config", under: "config"
|
33
|
+
if !importmap.include?("pin_all_from \"#{StimulusReflex::Installer.entrypoint}/config\"")
|
34
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
35
|
+
pin_all_from "#{StimulusReflex::Installer.entrypoint}/config", under: "config"
|
36
36
|
RUBY
|
37
37
|
say "✅ pin_all_from config"
|
38
38
|
else
|
@@ -40,7 +40,7 @@ backup(importmap_path) do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
if !importmap.include?("pin \"@rails/actioncable\"")
|
43
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
43
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
44
44
|
pin "@rails/actioncable", to: "actioncable.esm.js", preload: true
|
45
45
|
RUBY
|
46
46
|
say "✅ pin @rails/actioncable"
|
@@ -49,7 +49,7 @@ backup(importmap_path) do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
if !importmap.include?("pin \"@hotwired/stimulus\"")
|
52
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
52
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
53
53
|
pin "@hotwired/stimulus", to: "stimulus.js", preload: true
|
54
54
|
RUBY
|
55
55
|
say "✅ pin @hotwired/stimulus"
|
@@ -58,7 +58,7 @@ backup(importmap_path) do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
if !importmap.include?("pin \"morphdom\"")
|
61
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
61
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
62
62
|
pin "morphdom", to: "https://ga.jspm.io/npm:morphdom@2.6.1/dist/morphdom.js", preload: true
|
63
63
|
RUBY
|
64
64
|
say "✅ pin morphdom"
|
@@ -67,7 +67,7 @@ backup(importmap_path) do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
if !importmap.include?("pin \"cable_ready\"")
|
70
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
70
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
71
71
|
pin "cable_ready", to: "cable_ready.js", preload: true
|
72
72
|
RUBY
|
73
73
|
say "✅ pin cable_ready"
|
@@ -76,7 +76,7 @@ backup(importmap_path) do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
if !importmap.include?("pin \"stimulus_reflex\"")
|
79
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
79
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
80
80
|
pin "stimulus_reflex", to: "stimulus_reflex.js", preload: true
|
81
81
|
RUBY
|
82
82
|
say "✅ pin stimulus_reflex"
|
@@ -85,20 +85,20 @@ backup(importmap_path) do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
application_controller_src = fetch("/", "app/javascript/controllers/application_controller.js.tt")
|
89
|
-
application_controller_path = controllers_path / "application_controller.js"
|
90
|
-
application_js_src = fetch("/", "app/javascript/controllers/application.js.tt")
|
91
|
-
application_js_path = controllers_path / "application.js"
|
92
|
-
index_src = fetch("/", "app/javascript/controllers/index.js.importmap.tt")
|
93
|
-
index_path = controllers_path / "index.js"
|
88
|
+
application_controller_src = StimulusReflex::Installer.fetch("/", "app/javascript/controllers/application_controller.js.tt")
|
89
|
+
application_controller_path = StimulusReflex::Installer.controllers_path / "application_controller.js"
|
90
|
+
application_js_src = StimulusReflex::Installer.fetch("/", "app/javascript/controllers/application.js.tt")
|
91
|
+
application_js_path = StimulusReflex::Installer.controllers_path / "application.js"
|
92
|
+
index_src = StimulusReflex::Installer.fetch("/", "app/javascript/controllers/index.js.importmap.tt")
|
93
|
+
index_path = StimulusReflex::Installer.controllers_path / "index.js"
|
94
94
|
|
95
95
|
# create entrypoint/controllers, as well as the index, application and application_controller
|
96
|
-
empty_directory controllers_path unless controllers_path.exist?
|
96
|
+
empty_directory StimulusReflex::Installer.controllers_path unless StimulusReflex::Installer.controllers_path.exist?
|
97
97
|
|
98
98
|
copy_file(application_controller_src, application_controller_path) unless application_controller_path.exist?
|
99
99
|
|
100
100
|
# configure Stimulus application superclass to import Action Cable consumer
|
101
|
-
backup(application_js_path) do
|
101
|
+
StimulusReflex::Installer.backup(application_js_path) do
|
102
102
|
if application_js_path.exist?
|
103
103
|
friendly_application_js_path = application_js_path.relative_path_from(Rails.root).to_s
|
104
104
|
if application_js_path.read.include?("import consumer")
|
@@ -120,7 +120,7 @@ if index_path.exist?
|
|
120
120
|
if index_path.read == index_src.read
|
121
121
|
say "⏩ #{friendly_index_path} is present. Skipping"
|
122
122
|
else
|
123
|
-
backup(index_path, delete: true) do
|
123
|
+
StimulusReflex::Installer.backup(index_path, delete: true) do
|
124
124
|
copy_file(index_src, index_path, verbose: false)
|
125
125
|
end
|
126
126
|
say "✅ #{friendly_index_path} has been updated"
|
@@ -130,4 +130,4 @@ else
|
|
130
130
|
say "✅ #{friendly_index_path} has been created."
|
131
131
|
end
|
132
132
|
|
133
|
-
complete_step :importmap
|
133
|
+
StimulusReflex::Installer.complete_step :importmap
|
data/lib/install/initializers.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
sr_initializer_src = fetch("/", "config/initializers/stimulus_reflex.rb")
|
5
|
+
sr_initializer_src = StimulusReflex::Installer.fetch("/", "config/initializers/stimulus_reflex.rb")
|
6
6
|
sr_initializer_path = Rails.root.join("config/initializers/stimulus_reflex.rb")
|
7
7
|
|
8
|
-
cr_initializer_src = fetch("/", "config/initializers/cable_ready.rb")
|
8
|
+
cr_initializer_src = StimulusReflex::Installer.fetch("/", "config/initializers/cable_ready.rb")
|
9
9
|
cr_initializer_path = Rails.root.join("config/initializers/cable_ready.rb")
|
10
10
|
|
11
11
|
if !sr_initializer_path.exist?
|
@@ -22,4 +22,4 @@ else
|
|
22
22
|
say "⏩ config/initializers/cable_ready.rb already exists. Skipping."
|
23
23
|
end
|
24
24
|
|
25
|
-
complete_step :initializers
|
25
|
+
StimulusReflex::Installer.complete_step :initializers
|
data/lib/install/mrujs.rb
CHANGED
@@ -2,34 +2,34 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
return if pack_path_missing?
|
5
|
+
return if StimulusReflex::Installer.pack_path_missing?
|
6
6
|
|
7
|
-
mrujs_path = config_path / "mrujs.js"
|
7
|
+
mrujs_path = StimulusReflex::Installer.config_path / "mrujs.js"
|
8
8
|
|
9
9
|
proceed = false
|
10
10
|
|
11
11
|
if !File.exist?(mrujs_path)
|
12
|
-
proceed = if options.key? "mrujs"
|
13
|
-
options["mrujs"]
|
12
|
+
proceed = if StimulusReflex::Installer.options.key? "mrujs"
|
13
|
+
StimulusReflex::Installer.options["mrujs"]
|
14
14
|
else
|
15
15
|
!no?("✨ Would you like to install and enable mrujs? It's a modern, drop-in replacement for rails-ujs (Y/n)")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
if proceed
|
20
|
-
if bundler.importmap?
|
20
|
+
if StimulusReflex::Installer.bundler.importmap?
|
21
21
|
|
22
|
-
if !importmap_path.exist?
|
23
|
-
halt "#{
|
22
|
+
if !StimulusReflex::Installer.importmap_path.exist?
|
23
|
+
StimulusReflex::Installer.halt "#{friendly_StimulusReflex::Installer.importmap_path} is missing. You need a valid importmap config file to proceed."
|
24
24
|
return
|
25
25
|
end
|
26
26
|
|
27
|
-
importmap = importmap_path.read
|
27
|
+
importmap = StimulusReflex::Installer.importmap_path.read
|
28
28
|
|
29
29
|
if importmap.include?("pin \"mrujs\"")
|
30
30
|
say "⏩ mrujs already pinned. Skipping."
|
31
31
|
else
|
32
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
32
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
33
33
|
pin "mrujs", to: "https://ga.jspm.io/npm:mrujs@0.10.1/dist/index.module.js"
|
34
34
|
RUBY
|
35
35
|
say "✅ pin mrujs"
|
@@ -38,40 +38,40 @@ if proceed
|
|
38
38
|
if importmap.include?("pin \"mrujs/plugins\"")
|
39
39
|
say "⏩ mrujs/plugins already pinned. Skipping."
|
40
40
|
else
|
41
|
-
append_file(importmap_path, <<~RUBY, verbose: false)
|
41
|
+
append_file(StimulusReflex::Installer.importmap_path, <<~RUBY, verbose: false)
|
42
42
|
pin "mrujs/plugins", to: "https://ga.jspm.io/npm:mrujs@0.10.1/plugins/dist/plugins.module.js"
|
43
43
|
RUBY
|
44
44
|
say "✅ pin mrujs/plugins"
|
45
45
|
end
|
46
46
|
else
|
47
47
|
# queue mrujs for installation
|
48
|
-
if package_json_path.read.include?('"mrujs":')
|
48
|
+
if StimulusReflex::Installer.package_json_path.read.include?('"mrujs":')
|
49
49
|
say "⏩ mrujs already present. Skipping."
|
50
50
|
else
|
51
|
-
add_package "mrujs@^0.10.1"
|
51
|
+
StimulusReflex::Installer.add_package "mrujs@^0.10.1"
|
52
52
|
end
|
53
53
|
|
54
54
|
# queue @rails/ujs for removal
|
55
|
-
if package_json_path.read.include?('"@rails/ujs":')
|
56
|
-
drop_package "@rails/ujs"
|
55
|
+
if StimulusReflex::Installer.package_json_path.read.include?('"@rails/ujs":')
|
56
|
+
StimulusReflex::Installer.drop_package "@rails/ujs"
|
57
57
|
else
|
58
58
|
say "⏩ @rails/ujs not present. Skipping."
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
step_path = "/app/javascript/config/"
|
63
|
-
mrujs_src = fetch(step_path, "mrujs.js.tt")
|
63
|
+
mrujs_src = StimulusReflex::Installer.fetch(step_path, "mrujs.js.tt")
|
64
64
|
|
65
65
|
# create entrypoint/config/mrujs.js if necessary
|
66
66
|
copy_file(mrujs_src, mrujs_path) unless mrujs_path.exist?
|
67
67
|
|
68
68
|
# import mrujs config in entrypoint/config/index.js
|
69
|
-
index_path = config_path / "index.js"
|
69
|
+
index_path = StimulusReflex::Installer.config_path / "index.js"
|
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?
|
74
|
+
mrujs_import = if StimulusReflex::Installer.bundler.importmap?
|
75
75
|
%(import "config/mrujs"\n)
|
76
76
|
else
|
77
77
|
%(import "./mrujs"\n)
|
@@ -87,12 +87,12 @@ if proceed
|
|
87
87
|
# remove @rails/ujs from application.js
|
88
88
|
rails_ujs_pattern = /import Rails from ['"]@rails\/ujs['"]/
|
89
89
|
|
90
|
-
lines = pack_path.readlines
|
90
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
91
91
|
if lines.index { |line| line =~ rails_ujs_pattern }
|
92
|
-
gsub_file pack_path, rails_ujs_pattern, "", verbose: false
|
93
|
-
say "✅ @rails/ujs removed from #{friendly_pack_path}"
|
92
|
+
gsub_file StimulusReflex::Installer.pack_path, rails_ujs_pattern, "", verbose: false
|
93
|
+
say "✅ @rails/ujs removed from #{StimulusReflex::Installer.friendly_pack_path}"
|
94
94
|
else
|
95
|
-
say "⏩ @rails/ujs not present in #{friendly_pack_path}. Skipping."
|
95
|
+
say "⏩ @rails/ujs not present in #{StimulusReflex::Installer.friendly_pack_path}. Skipping."
|
96
96
|
end
|
97
97
|
|
98
98
|
# set Action View to generate remote forms when using form_with
|
@@ -101,7 +101,7 @@ if proceed
|
|
101
101
|
defaults_pattern = /config\.load_defaults \d\.\d/
|
102
102
|
|
103
103
|
lines = application_path.readlines
|
104
|
-
backup(application_path) do
|
104
|
+
StimulusReflex::Installer.backup(application_path) do
|
105
105
|
if !lines.index { |line| line =~ application_pattern }
|
106
106
|
if (index = lines.index { |line| line =~ /^[^#]*#{defaults_pattern}/ })
|
107
107
|
gsub_file application_path, /\s*#{defaults_pattern}\n/, verbose: false do
|
@@ -127,12 +127,12 @@ if proceed
|
|
127
127
|
# remove turbolinks from Gemfile because it's incompatible with mrujs (and unnecessary)
|
128
128
|
turbolinks_pattern = /^[^#]*gem ["']turbolinks["']/
|
129
129
|
|
130
|
-
lines = gemfile_path.readlines
|
130
|
+
lines = StimulusReflex::Installer.gemfile_path.readlines
|
131
131
|
if lines.index { |line| line =~ turbolinks_pattern }
|
132
|
-
remove_gem :turbolinks
|
132
|
+
StimulusReflex::Installer.remove_gem :turbolinks
|
133
133
|
else
|
134
134
|
say "⏩ turbolinks is not present in Gemfile. Skipping."
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
complete_step :mrujs
|
138
|
+
StimulusReflex::Installer.complete_step :mrujs
|
data/lib/install/npm_packages.rb
CHANGED
@@ -2,24 +2,24 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
lines = package_json_path.readlines
|
5
|
+
lines = StimulusReflex::Installer.package_json_path.readlines
|
6
6
|
|
7
|
-
if !lines.index { |line| line =~ /^\s*["']cable_ready["']: ["'].*#{cr_npm_version}["']/ }
|
8
|
-
add_package "cable_ready@#{cr_npm_version}"
|
7
|
+
if !lines.index { |line| line =~ /^\s*["']cable_ready["']: ["'].*#{StimulusReflex::Installer.cr_npm_version}["']/ }
|
8
|
+
StimulusReflex::Installer.add_package "cable_ready@#{StimulusReflex::Installer.cr_npm_version}"
|
9
9
|
else
|
10
10
|
say "⏩ cable_ready npm package is already present. Skipping."
|
11
11
|
end
|
12
12
|
|
13
|
-
if !lines.index { |line| line =~ /^\s*["']stimulus_reflex["']: ["'].*#{sr_npm_version}["']/ }
|
14
|
-
add_package "stimulus_reflex@#{sr_npm_version}"
|
13
|
+
if !lines.index { |line| line =~ /^\s*["']stimulus_reflex["']: ["'].*#{StimulusReflex::Installer.sr_npm_version}["']/ }
|
14
|
+
StimulusReflex::Installer.add_package "stimulus_reflex@#{StimulusReflex::Installer.sr_npm_version}"
|
15
15
|
else
|
16
16
|
say "⏩ stimulus_reflex npm package is already present. Skipping."
|
17
17
|
end
|
18
18
|
|
19
19
|
if !lines.index { |line| line =~ /^\s*["']@hotwired\/stimulus["']:/ }
|
20
|
-
add_package "@hotwired/stimulus@^3.2"
|
20
|
+
StimulusReflex::Installer.add_package "@hotwired/stimulus@^3.2"
|
21
21
|
else
|
22
22
|
say "⏩ @hotwired/stimulus npm package is already present. Skipping."
|
23
23
|
end
|
24
24
|
|
25
|
-
complete_step :npm_packages
|
25
|
+
StimulusReflex::Installer.complete_step :npm_packages
|
data/lib/install/reflexes.rb
CHANGED
@@ -5,7 +5,7 @@ require "stimulus_reflex/installer"
|
|
5
5
|
reflexes_path = Rails.root.join("app/reflexes")
|
6
6
|
step_path = "/app/reflexes/"
|
7
7
|
application_reflex_path = reflexes_path / "application_reflex.rb"
|
8
|
-
application_reflex_src = fetch(step_path, "application_reflex.rb.tt")
|
8
|
+
application_reflex_src = StimulusReflex::Installer.fetch(step_path, "application_reflex.rb.tt")
|
9
9
|
|
10
10
|
# verify app/reflexes exists and create if necessary
|
11
11
|
if reflexes_path.exist?
|
@@ -22,4 +22,4 @@ else
|
|
22
22
|
say "✅ Created app/reflexes/application_reflex.rb"
|
23
23
|
end
|
24
24
|
|
25
|
-
complete_step :reflexes
|
25
|
+
StimulusReflex::Installer.complete_step :reflexes
|
data/lib/install/shakapacker.rb
CHANGED
@@ -2,28 +2,28 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
return if pack_path_missing?
|
5
|
+
return if StimulusReflex::Installer.pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines = package_json_path.readlines
|
8
|
+
lines = StimulusReflex::Installer.package_json_path.readlines
|
9
9
|
|
10
10
|
if !lines.index { |line| line =~ /^\s*["']@hotwired\/stimulus-webpack-helpers["']: ["']\^1.0.1["']/ }
|
11
|
-
add_package "@hotwired/stimulus-webpack-helpers@^1.0.1"
|
11
|
+
StimulusReflex::Installer.add_package "@hotwired/stimulus-webpack-helpers@^1.0.1"
|
12
12
|
else
|
13
13
|
say "⏩ @hotwired/stimulus-webpack-helpers npm package is already present. Skipping."
|
14
14
|
end
|
15
15
|
|
16
16
|
step_path = "/app/javascript/controllers/"
|
17
|
-
# controller_templates_path = File.expand_path(template_src + "/app/javascript/controllers", File.join(File.dirname(__FILE__)))
|
18
|
-
application_controller_src = fetch(step_path, "application_controller.js.tt")
|
19
|
-
application_controller_path = controllers_path / "application_controller.js"
|
20
|
-
application_js_src = fetch(step_path, "application.js.tt")
|
21
|
-
application_js_path = controllers_path / "application.js"
|
22
|
-
index_src = fetch(step_path, "index.js.shakapacker.tt")
|
23
|
-
index_path = controllers_path / "index.js"
|
17
|
+
# controller_templates_path = File.expand_path(StimulusReflex::Installer.template_src + "/app/javascript/controllers", File.join(File.dirname(__FILE__)))
|
18
|
+
application_controller_src = StimulusReflex::Installer.fetch(step_path, "application_controller.js.tt")
|
19
|
+
application_controller_path = StimulusReflex::Installer.controllers_path / "application_controller.js"
|
20
|
+
application_js_src = StimulusReflex::Installer.fetch(step_path, "application.js.tt")
|
21
|
+
application_js_path = StimulusReflex::Installer.controllers_path / "application.js"
|
22
|
+
index_src = StimulusReflex::Installer.fetch(step_path, "index.js.shakapacker.tt")
|
23
|
+
index_path = StimulusReflex::Installer.controllers_path / "index.js"
|
24
24
|
|
25
25
|
# create entrypoint/controllers, as well as the index, application and application_controller
|
26
|
-
empty_directory controllers_path unless controllers_path.exist?
|
26
|
+
empty_directory StimulusReflex::Installer.controllers_path unless StimulusReflex::Installer.controllers_path.exist?
|
27
27
|
|
28
28
|
copy_file(application_controller_src, application_controller_path) unless application_controller_path.exist?
|
29
29
|
copy_file(application_js_src, application_js_path) unless application_js_path.exist?
|
@@ -32,33 +32,33 @@ copy_file(index_src, index_path) unless index_path.exist?
|
|
32
32
|
controllers_pattern = /import ['"]controllers['"]/
|
33
33
|
controllers_commented_pattern = /\s*\/\/\s*#{controllers_pattern}/
|
34
34
|
|
35
|
-
if pack.match?(controllers_pattern)
|
36
|
-
if pack.match?(controllers_commented_pattern)
|
37
|
-
proceed = if options.key? "uncomment"
|
38
|
-
options["uncomment"]
|
35
|
+
if StimulusReflex::Installer.pack.match?(controllers_pattern)
|
36
|
+
if StimulusReflex::Installer.pack.match?(controllers_commented_pattern)
|
37
|
+
proceed = if StimulusReflex::Installer.options.key? "uncomment"
|
38
|
+
StimulusReflex::Installer.options["uncomment"]
|
39
39
|
else
|
40
40
|
!no?("✨ Do you want to import your Stimulus controllers in application.js? (Y/n)")
|
41
41
|
end
|
42
42
|
|
43
43
|
if proceed
|
44
44
|
# uncomment_lines only works with Ruby comments 🙄
|
45
|
-
lines = pack_path.readlines
|
45
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
46
46
|
matches = lines.select { |line| line =~ controllers_commented_pattern }
|
47
47
|
lines[lines.index(matches.last).to_i] = "import \"controllers\"\n"
|
48
|
-
pack_path.write lines.join
|
49
|
-
say "✅ Stimulus controllers imported in #{friendly_pack_path}"
|
48
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
49
|
+
say "✅ Stimulus controllers imported in #{StimulusReflex::Installer.friendly_pack_path}"
|
50
50
|
else
|
51
51
|
say "🤷 your Stimulus controllers are not being imported in your application.js. We trust that you have a reason for this."
|
52
52
|
end
|
53
53
|
else
|
54
|
-
say "✅ Stimulus controllers imported in #{friendly_pack_path}"
|
54
|
+
say "✅ Stimulus controllers imported in #{StimulusReflex::Installer.friendly_pack_path}"
|
55
55
|
end
|
56
56
|
else
|
57
|
-
lines = pack_path.readlines
|
57
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
58
58
|
matches = lines.select { |line| line =~ /^import / }
|
59
59
|
lines.insert lines.index(matches.last).to_i + 1, "import \"controllers\"\n"
|
60
|
-
pack_path.write lines.join
|
61
|
-
say "✅ Stimulus controllers imported in #{friendly_pack_path}"
|
60
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
61
|
+
say "✅ Stimulus controllers imported in #{StimulusReflex::Installer.friendly_pack_path}"
|
62
62
|
end
|
63
63
|
|
64
|
-
complete_step :shakapacker
|
64
|
+
StimulusReflex::Installer.complete_step :shakapacker
|
data/lib/install/spring.rb
CHANGED
@@ -5,11 +5,11 @@ require "stimulus_reflex/installer"
|
|
5
5
|
spring_pattern = /^[^#]*gem ["']spring["']/
|
6
6
|
|
7
7
|
proceed = false
|
8
|
-
lines = gemfile_path.readlines
|
8
|
+
lines = StimulusReflex::Installer.gemfile_path.readlines
|
9
9
|
|
10
10
|
if lines.index { |line| line =~ spring_pattern }
|
11
|
-
proceed = if options.key? "spring"
|
12
|
-
options["spring"]
|
11
|
+
proceed = if StimulusReflex::Installer.options.key? "spring"
|
12
|
+
StimulusReflex::Installer.options["spring"]
|
13
13
|
else
|
14
14
|
!no?("✨ Would you like to disable the spring gem? \nIt's been removed from Rails 7, and is the frequent culprit behind countless mystery bugs. (Y/n)")
|
15
15
|
end
|
@@ -22,7 +22,7 @@ if proceed
|
|
22
22
|
bin_rails_pattern = /^[^#]*load File.expand_path\("spring", __dir__\)/
|
23
23
|
|
24
24
|
if (index = lines.index { |line| line =~ spring_pattern })
|
25
|
-
remove_gem :spring
|
25
|
+
StimulusReflex::Installer.remove_gem :spring
|
26
26
|
|
27
27
|
bin_spring = Rails.root.join("bin/spring")
|
28
28
|
if bin_spring.exist?
|
@@ -33,7 +33,7 @@ if proceed
|
|
33
33
|
bin_rails = Rails.root.join("bin/rails")
|
34
34
|
bin_rails_content = bin_rails.readlines
|
35
35
|
if (index = bin_rails_content.index { |line| line =~ bin_rails_pattern })
|
36
|
-
backup(bin_rails) do
|
36
|
+
StimulusReflex::Installer.backup(bin_rails) do
|
37
37
|
bin_rails_content[index] = "# #{bin_rails_content[index]}"
|
38
38
|
bin_rails.write bin_rails_content.join
|
39
39
|
end
|
@@ -45,10 +45,10 @@ if proceed
|
|
45
45
|
end
|
46
46
|
|
47
47
|
if lines.index { |line| line =~ spring_watcher_pattern }
|
48
|
-
remove_gem "spring-watcher-listen"
|
48
|
+
StimulusReflex::Installer.remove_gem "spring-watcher-listen"
|
49
49
|
end
|
50
50
|
else
|
51
51
|
say "⏩ Skipping."
|
52
52
|
end
|
53
53
|
|
54
|
-
complete_step :spring
|
54
|
+
StimulusReflex::Installer.complete_step :spring
|
data/lib/install/updatable.rb
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
if application_record_path.exist?
|
6
|
-
lines = application_record_path.readlines
|
5
|
+
if StimulusReflex::Installer.application_record_path.exist?
|
6
|
+
lines = StimulusReflex::Installer.application_record_path.readlines
|
7
7
|
|
8
8
|
if !lines.index { |line| line =~ /^\s*include CableReady::Updatable/ }
|
9
|
-
proceed = if options.key? "updatable"
|
10
|
-
options["updatable"]
|
9
|
+
proceed = if StimulusReflex::Installer.options.key? "updatable"
|
10
|
+
StimulusReflex::Installer.options["updatable"]
|
11
11
|
else
|
12
12
|
!no?("✨ Include CableReady::Updatable in Active Record model classes? (Y/n)")
|
13
13
|
end
|
14
14
|
|
15
15
|
unless proceed
|
16
|
-
complete_step :updatable
|
16
|
+
StimulusReflex::Installer.complete_step :updatable
|
17
17
|
|
18
18
|
puts "⏩ Skipping."
|
19
19
|
return
|
@@ -21,7 +21,7 @@ if application_record_path.exist?
|
|
21
21
|
|
22
22
|
index = lines.index { |line| line.include?("class ApplicationRecord < ActiveRecord::Base") }
|
23
23
|
lines.insert index + 1, " include CableReady::Updatable\n"
|
24
|
-
application_record_path.write lines.join
|
24
|
+
StimulusReflex::Installer.application_record_path.write lines.join
|
25
25
|
|
26
26
|
say "✅ included CableReady::Updatable in ApplicationRecord"
|
27
27
|
else
|
@@ -31,4 +31,4 @@ else
|
|
31
31
|
say "⏩ ApplicationRecord doesn't exist. Skipping."
|
32
32
|
end
|
33
33
|
|
34
|
-
complete_step :updatable
|
34
|
+
StimulusReflex::Installer.complete_step :updatable
|