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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +144 -101
  3. data/README.md +2 -2
  4. data/app/assets/javascripts/stimulus_reflex.js +15 -13
  5. data/app/assets/javascripts/stimulus_reflex.umd.js +15 -12
  6. data/app/channels/stimulus_reflex/channel.rb +49 -53
  7. data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +2 -2
  8. data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +1 -1
  9. data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +1 -1
  10. data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +1 -1
  11. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +1 -1
  12. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +1 -1
  13. data/lib/install/action_cable.rb +30 -30
  14. data/lib/install/broadcaster.rb +11 -11
  15. data/lib/install/bundle.rb +9 -9
  16. data/lib/install/compression.rb +5 -5
  17. data/lib/install/config.rb +22 -22
  18. data/lib/install/development.rb +19 -19
  19. data/lib/install/esbuild.rb +28 -28
  20. data/lib/install/example.rb +3 -3
  21. data/lib/install/importmap.rb +29 -29
  22. data/lib/install/initializers.rb +3 -3
  23. data/lib/install/mrujs.rb +25 -25
  24. data/lib/install/npm_packages.rb +7 -7
  25. data/lib/install/reflexes.rb +2 -2
  26. data/lib/install/shakapacker.rb +23 -23
  27. data/lib/install/spring.rb +7 -7
  28. data/lib/install/updatable.rb +7 -7
  29. data/lib/install/vite.rb +22 -22
  30. data/lib/install/webpacker.rb +27 -27
  31. data/lib/install/yarn.rb +9 -9
  32. data/lib/stimulus_reflex/html/document_fragment.rb +5 -3
  33. data/lib/stimulus_reflex/installer.rb +305 -277
  34. data/lib/stimulus_reflex/reflex.rb +14 -29
  35. data/lib/stimulus_reflex/reflex_data.rb +17 -17
  36. data/lib/stimulus_reflex/reflex_factory.rb +49 -26
  37. data/lib/stimulus_reflex/version.rb +1 -1
  38. data/lib/stimulus_reflex.rb +2 -0
  39. data/lib/tasks/stimulus_reflex/stimulus_reflex.rake +8 -8
  40. data/package.json +10 -10
  41. data/stimulus_reflex.gemspec +10 -8
  42. data/web-test-runner.config.mjs +14 -0
  43. data/yarn.lock +1278 -830
  44. metadata +34 -42
@@ -20,13 +20,13 @@ class StimulusReflexGenerator < Rails::Generators::NamedBase
20
20
 
21
21
  template(reflex_src, reflex_path) unless options[:skip_reflex]
22
22
 
23
- if !options[:skip_stimulus] && entrypoint.blank?
23
+ if !options[:skip_stimulus] && StimulusReflex::Installer.entrypoint.blank?
24
24
  puts "❌ You must specify a valid JavaScript entrypoint."
25
25
  exit
26
26
  end
27
27
 
28
28
  stimulus_controller_src = "app/javascript/controllers/%file_name%_controller.js.tt"
29
- stimulus_controller_path = Rails.root.join(entrypoint, "controllers/#{file_name}_controller.js")
29
+ stimulus_controller_path = Rails.root.join(StimulusReflex::Installer.entrypoint, "controllers/#{file_name}_controller.js")
30
30
 
31
31
  template(stimulus_controller_src, stimulus_controller_path) unless options[:skip_stimulus]
32
32
 
@@ -1,4 +1,4 @@
1
- <%- if bundler.importmap? -%>
1
+ <%- if StimulusReflex::Installer.bundler.importmap? -%>
2
2
  import consumer from "channels/consumer"
3
3
  <%- else -%>
4
4
  import consumer from "../channels/consumer"
@@ -1,4 +1,4 @@
1
- <%- if bundler.importmap? -%>
1
+ <%- if StimulusReflex::Installer.bundler.importmap? -%>
2
2
  import "config/cable_ready"
3
3
  import "config/stimulus_reflex"
4
4
  <%- else -%>
@@ -1,4 +1,4 @@
1
- <%- if bundler.importmap? -%>
1
+ <%- if StimulusReflex::Installer.bundler.importmap? -%>
2
2
  import { application } from "controllers/application"
3
3
  import controller from "controllers/application_controller"
4
4
  <%- else -%>
@@ -1,4 +1,4 @@
1
- <%- if bundler.importmap? -%>
1
+ <%- if StimulusReflex::Installer.bundler.importmap? -%>
2
2
  import ApplicationController from "controllers/application_controller"
3
3
  <%- else -%>
4
4
  import ApplicationController from "./application_controller"
@@ -1,5 +1,5 @@
1
1
  import { Application } from "@hotwired/stimulus"
2
- <%- if bundler.importmap? %>
2
+ <%- if StimulusReflex::Installer.bundler.importmap? %>
3
3
  import consumer from "channels/consumer"
4
4
  <%- else %>
5
5
  import consumer from "../channels/consumer"
@@ -6,11 +6,11 @@ require "stimulus_reflex/installer"
6
6
  if defined?(ActionCable::Engine)
7
7
  say "⏩ ActionCable::Engine is already loaded and in scope. Skipping"
8
8
  else
9
- halt "ActionCable::Engine is not loaded, please add or uncomment `require \"action_cable/engine\"` to your `config/application.rb`"
9
+ StimulusReflex::Installer.halt "ActionCable::Engine is not loaded, please add or uncomment `require \"action_cable/engine\"` to your `config/application.rb`"
10
10
  return
11
11
  end
12
12
 
13
- return if pack_path_missing?
13
+ return if StimulusReflex::Installer.pack_path_missing?
14
14
 
15
15
  # verify that the Action Cable pubsub config is created
16
16
  cable_config = Rails.root.join("config/cable.yml")
@@ -37,7 +37,7 @@ elsif yaml["development"]["adapter"] == "async"
37
37
  "url" => "<%= ENV.fetch(\"REDIS_URL\") { \"redis://localhost:6379/1\" } %>",
38
38
  "channel_prefix" => "#{app_name}_development"
39
39
  }
40
- backup(cable_config) do
40
+ StimulusReflex::Installer.backup(cable_config) do
41
41
  cable_config.write(yaml.to_yaml)
42
42
  end
43
43
  say "✅ config/cable.yml was updated to use the redis adapter in development"
@@ -45,29 +45,29 @@ else
45
45
  say "🤷 config/cable.yml should use the redis adapter - or something like it - in development. You have something else specified, and we trust that you know what you're doing."
46
46
  end
47
47
 
48
- if gemfile.match?(/gem ['"]redis['"]/)
48
+ if StimulusReflex::Installer.gemfile.match?(/gem ['"]redis['"]/)
49
49
  say "⏩ redis gem is already present in Gemfile. Skipping."
50
50
  elsif Rails::VERSION::MAJOR >= 7
51
- add_gem "redis@~> 5"
51
+ StimulusReflex::Installer.add_gem "redis@~> 5"
52
52
  else
53
- add_gem "redis@~> 4"
53
+ StimulusReflex::Installer.add_gem "redis@~> 4"
54
54
  end
55
55
 
56
56
  # install action-cable-redis-backport gem if using Action Cable < 7.1
57
57
  unless ActionCable::VERSION::MAJOR >= 7 && ActionCable::VERSION::MINOR >= 1
58
- if gemfile.match?(/gem ['"]action-cable-redis-backport['"]/)
58
+ if StimulusReflex::Installer.gemfile.match?(/gem ['"]action-cable-redis-backport['"]/)
59
59
  say "⏩ action-cable-redis-backport gem is already present in Gemfile. Skipping."
60
60
  else
61
- add_gem "action-cable-redis-backport@~> 1"
61
+ StimulusReflex::Installer.add_gem "action-cable-redis-backport@~> 1"
62
62
  end
63
63
  end
64
64
 
65
65
  # verify that the Action Cable channels folder and consumer class is available
66
66
  step_path = "/app/javascript/channels/"
67
- channels_path = Rails.root.join(entrypoint, "channels")
68
- consumer_src = fetch(step_path, "consumer.js.tt")
67
+ channels_path = Rails.root.join(StimulusReflex::Installer.entrypoint, "channels")
68
+ consumer_src = StimulusReflex::Installer.fetch(step_path, "consumer.js.tt")
69
69
  consumer_path = channels_path / "consumer.js"
70
- index_src = fetch(step_path, "index.js.#{bundler}.tt")
70
+ index_src = StimulusReflex::Installer.fetch(step_path, "index.js.#{StimulusReflex::Installer.bundler}.tt")
71
71
  index_path = channels_path / "index.js"
72
72
  friendly_index_path = index_path.relative_path_from(Rails.root).to_s
73
73
 
@@ -79,7 +79,7 @@ if index_path.exist?
79
79
  if index_path.read == index_src.read
80
80
  say "⏩ #{friendly_index_path} is already present. Skipping."
81
81
  else
82
- backup(index_path) do
82
+ StimulusReflex::Installer.backup(index_path) do
83
83
  copy_file(index_src, index_path, verbose: false)
84
84
  end
85
85
  say "✅ #{friendly_index_path} has been updated"
@@ -92,45 +92,45 @@ end
92
92
  # import Action Cable channels into application pack
93
93
  channels_pattern = /import ['"](\.\.\/|\.\/)?channels['"]/
94
94
  channels_commented_pattern = /\s*\/\/\s*#{channels_pattern}/
95
- channel_import = "import \"#{prefix}channels\"\n"
95
+ channel_import = "import \"#{StimulusReflex::Installer.prefix}channels\"\n"
96
96
 
97
- if pack.match?(channels_pattern)
98
- if pack.match?(channels_commented_pattern)
99
- proceed = if options.key? "uncomment"
100
- options["uncomment"]
97
+ if StimulusReflex::Installer.pack.match?(channels_pattern)
98
+ if StimulusReflex::Installer.pack.match?(channels_commented_pattern)
99
+ proceed = if StimulusReflex::Installer.options.key? "uncomment"
100
+ StimulusReflex::Installer.options["uncomment"]
101
101
  else
102
102
  !no?("✨ Action Cable seems to be commented out in your application.js. Do you want to uncomment it? (Y/n)")
103
103
  end
104
104
 
105
105
  if proceed
106
106
  # uncomment_lines only works with Ruby comments 🙄
107
- lines = pack_path.readlines
107
+ lines = StimulusReflex::Installer.pack_path.readlines
108
108
  matches = lines.select { |line| line =~ channels_commented_pattern }
109
109
  lines[lines.index(matches.last).to_i] = channel_import
110
- pack_path.write lines.join
111
- say "✅ Uncommented channels import in #{friendly_pack_path}"
110
+ StimulusReflex::Installer.pack_path.write lines.join
111
+ say "✅ Uncommented channels import in #{StimulusReflex::Installer.friendly_pack_path}"
112
112
  else
113
113
  say "🤷 your Action Cable channels are not being imported in your application.js. We trust that you have a reason for this."
114
114
  end
115
115
  else
116
- say "⏩ channels are already being imported in #{friendly_pack_path}. Skipping."
116
+ say "⏩ channels are already being imported in #{StimulusReflex::Installer.friendly_pack_path}. Skipping."
117
117
  end
118
118
  else
119
- lines = pack_path.readlines
119
+ lines = StimulusReflex::Installer.pack_path.readlines
120
120
  matches = lines.select { |line| line =~ /^import / }
121
121
  lines.insert lines.index(matches.last).to_i + 1, channel_import
122
- pack_path.write lines.join
123
- say "✅ channels imported in #{friendly_pack_path}"
122
+ StimulusReflex::Installer.pack_path.write lines.join
123
+ say "✅ channels imported in #{StimulusReflex::Installer.friendly_pack_path}"
124
124
  end
125
125
 
126
126
  # create working copy of Action Cable initializer in tmp
127
- if action_cable_initializer_path.exist?
128
- FileUtils.cp(action_cable_initializer_path, action_cable_initializer_working_path)
127
+ if StimulusReflex::Installer.action_cable_initializer_path.exist?
128
+ FileUtils.cp(StimulusReflex::Installer.action_cable_initializer_path, StimulusReflex::Installer.action_cable_initializer_working_path)
129
129
 
130
130
  say "⏩ Action Cable initializer already exists. Skipping"
131
131
  else
132
132
  # create Action Cable initializer if it doesn't already exist
133
- create_file(action_cable_initializer_working_path, verbose: false) do
133
+ create_file(StimulusReflex::Installer.action_cable_initializer_working_path, verbose: false) do
134
134
  <<~RUBY
135
135
  # frozen_string_literal: true
136
136
 
@@ -140,10 +140,10 @@ else
140
140
  end
141
141
 
142
142
  # silence notoriously chatty Action Cable logs
143
- if action_cable_initializer_working_path.read.match?(/^[^#]*ActionCable.server.config.logger/)
143
+ if StimulusReflex::Installer.action_cable_initializer_working_path.read.match?(/^[^#]*ActionCable.server.config.logger/)
144
144
  say "⏩ Action Cable logger is already being silenced. Skipping"
145
145
  else
146
- append_file(action_cable_initializer_working_path, verbose: false) do
146
+ append_file(StimulusReflex::Installer.action_cable_initializer_working_path, verbose: false) do
147
147
  <<~RUBY
148
148
  ActionCable.server.config.logger = Logger.new(nil)
149
149
 
@@ -152,4 +152,4 @@ else
152
152
  say "✅ Action Cable logger silenced for performance and legibility"
153
153
  end
154
154
 
155
- complete_step :action_cable
155
+ StimulusReflex::Installer.complete_step :action_cable
@@ -11,7 +11,7 @@ end
11
11
  channel_path = Rails.root.join("app/channels/application_cable/channel.rb")
12
12
  controller_path = Rails.root.join("app/controllers/application_controller.rb")
13
13
  job_path = Rails.root.join("app/jobs/application_job.rb")
14
- model_path = Rails.root.join(application_record_path)
14
+ model_path = Rails.root.join(StimulusReflex::Installer.application_record_path)
15
15
 
16
16
  include_in_channel = needs_broadcaster?(channel_path)
17
17
  include_in_controller = needs_broadcaster?(controller_path)
@@ -21,20 +21,20 @@ include_in_model = needs_broadcaster?(model_path)
21
21
  proceed = [include_in_channel, include_in_controller, include_in_job, include_in_model].reduce(:|)
22
22
 
23
23
  unless proceed
24
- complete_step :broadcaster
24
+ StimulusReflex::Installer.complete_step :broadcaster
25
25
 
26
26
  puts "⏩ CableReady::Broadcaster already included in all files. Skipping."
27
27
  return
28
28
  end
29
29
 
30
- proceed = if options.key? "broadcaster"
31
- options["broadcaster"]
30
+ proceed = if StimulusReflex::Installer.options.key? "broadcaster"
31
+ StimulusReflex::Installer.options["broadcaster"]
32
32
  else
33
33
  !no?("✨ Make CableReady::Broadcaster available to channels, controllers, jobs and models? (Y/n)")
34
34
  end
35
35
 
36
36
  unless proceed
37
- complete_step :broadcaster
37
+ StimulusReflex::Installer.complete_step :broadcaster
38
38
 
39
39
  puts "⏩ Skipping."
40
40
  return
@@ -44,7 +44,7 @@ broadcaster_include = "\n include CableReady::Broadcaster\n"
44
44
 
45
45
  # include CableReady::Broadcaster in Action Cable Channel classes
46
46
  if include_in_channel
47
- backup(channel_path) do
47
+ StimulusReflex::Installer.backup(channel_path) do
48
48
  inject_into_file channel_path, broadcaster_include, after: /class (ApplicationCable::)?Channel < ActionCable::Channel::Base/, verbose: false
49
49
  end
50
50
 
@@ -55,7 +55,7 @@ end
55
55
 
56
56
  # include CableReady::Broadcaster in Action Controller classes
57
57
  if include_in_controller
58
- backup(controller_path) do
58
+ StimulusReflex::Installer.backup(controller_path) do
59
59
  inject_into_class controller_path, "ApplicationController", broadcaster_include, verbose: false
60
60
  end
61
61
 
@@ -67,7 +67,7 @@ end
67
67
  # include CableReady::Broadcaster in Active Job classes, if present
68
68
 
69
69
  if include_in_job
70
- backup(job_path) do
70
+ StimulusReflex::Installer.backup(job_path) do
71
71
  inject_into_class job_path, "ApplicationJob", broadcaster_include, verbose: false
72
72
  end
73
73
 
@@ -78,8 +78,8 @@ end
78
78
 
79
79
  # include CableReady::Broadcaster in Active Record model classes
80
80
  if include_in_model
81
- backup(application_record_path) do
82
- inject_into_class application_record_path, "ApplicationRecord", broadcaster_include, verbose: false
81
+ StimulusReflex::Installer.backup(StimulusReflex::Installer.application_record_path) do
82
+ inject_into_class StimulusReflex::Installer.application_record_path, "ApplicationRecord", broadcaster_include, verbose: false
83
83
  end
84
84
 
85
85
  puts "✅ include CableReady::Broadcaster in ApplicationRecord"
@@ -87,4 +87,4 @@ else
87
87
  puts "⏩ Not including CableReady::Broadcaster in ApplicationRecord. Skipping"
88
88
  end
89
89
 
90
- complete_step :broadcaster
90
+ StimulusReflex::Installer.complete_step :broadcaster
@@ -2,14 +2,14 @@
2
2
 
3
3
  require "stimulus_reflex/installer"
4
4
 
5
- hash = gemfile_hash
5
+ hash = StimulusReflex::Installer.gemfile_hash
6
6
 
7
7
  # run bundle only when gems are waiting to be added or removed
8
- add = add_gem_list.exist? ? add_gem_list.readlines.map(&:chomp) : []
9
- remove = remove_gem_list.exist? ? remove_gem_list.readlines.map(&:chomp) : []
8
+ add = StimulusReflex::Installer.add_gem_list.exist? ? StimulusReflex::Installer.add_gem_list.readlines.map(&:chomp) : []
9
+ remove = StimulusReflex::Installer.remove_gem_list.exist? ? StimulusReflex::Installer.remove_gem_list.readlines.map(&:chomp) : []
10
10
 
11
11
  if add.present? || remove.present?
12
- lines = gemfile_path.readlines
12
+ lines = StimulusReflex::Installer.gemfile_path.readlines
13
13
 
14
14
  remove.each do |name|
15
15
  index = lines.index { |line| line =~ /gem ['"]#{name}['"]/ }
@@ -40,17 +40,17 @@ if add.present? || remove.present?
40
40
  end
41
41
  end
42
42
 
43
- gemfile_path.write lines.join
43
+ StimulusReflex::Installer.gemfile_path.write lines.join
44
44
 
45
- bundle_command("install --quiet", "BUNDLE_IGNORE_MESSAGES" => "1") if hash != gemfile_hash
45
+ bundle_command("install --quiet", "BUNDLE_IGNORE_MESSAGES" => "1") if hash != StimulusReflex::Installer.gemfile_hash
46
46
  else
47
47
  say "⏩ No rubygems depedencies to install. Skipping."
48
48
  end
49
49
 
50
- FileUtils.cp(development_working_path, development_path)
50
+ FileUtils.cp(StimulusReflex::Installer.development_working_path, StimulusReflex::Installer.development_path)
51
51
  say "✅ development environment configuration installed"
52
52
 
53
- FileUtils.cp(action_cable_initializer_working_path, action_cable_initializer_path)
53
+ FileUtils.cp(StimulusReflex::Installer.action_cable_initializer_working_path, StimulusReflex::Installer.action_cable_initializer_path)
54
54
  say "✅ Action Cable initializer installed"
55
55
 
56
- complete_step :bundle
56
+ StimulusReflex::Installer.complete_step :bundle
@@ -2,17 +2,17 @@
2
2
 
3
3
  require "stimulus_reflex/installer"
4
4
 
5
- initializer = action_cable_initializer_working_path.read
5
+ initializer = StimulusReflex::Installer.action_cable_initializer_working_path.read
6
6
 
7
- if gemfile.match?(/gem ['"]permessage_deflate['"]/)
7
+ if StimulusReflex::Installer.gemfile.match?(/gem ['"]permessage_deflate['"]/)
8
8
  say "⏩ permessage_deflate already present in Gemfile. Skipping."
9
9
  else
10
- add_gem "permessage_deflate@>= 0.1"
10
+ StimulusReflex::Installer.add_gem "permessage_deflate@>= 0.1"
11
11
  end
12
12
 
13
13
  # add permessage_deflate config to Action Cable initializer
14
14
  if initializer.exclude? "PermessageDeflate.configure"
15
- create_or_append(action_cable_initializer_working_path, verbose: false) do
15
+ StimulusReflex::Installer.create_or_append(StimulusReflex::Installer.action_cable_initializer_working_path, verbose: false) do
16
16
  <<~RUBY
17
17
  module ActionCable
18
18
  module Connection
@@ -38,4 +38,4 @@ else
38
38
  say "⏩ Action Cable initializer is already patched to deflate websocket traffic. Skipping."
39
39
  end
40
40
 
41
- complete_step :compression
41
+ StimulusReflex::Installer.complete_step :compression
@@ -2,24 +2,24 @@
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
  step_path = "/app/javascript/config/"
8
- index_src = fetch(step_path, "index.js.tt")
9
- index_path = config_path / "index.js"
8
+ index_src = StimulusReflex::Installer.fetch(step_path, "index.js.tt")
9
+ index_path = StimulusReflex::Installer.config_path / "index.js"
10
10
  friendly_index_path = index_path.relative_path_from(Rails.root).to_s
11
- stimulus_reflex_src = fetch(step_path, "stimulus_reflex.js.tt")
12
- stimulus_reflex_path = config_path / "stimulus_reflex.js"
11
+ stimulus_reflex_src = StimulusReflex::Installer.fetch(step_path, "stimulus_reflex.js.tt")
12
+ stimulus_reflex_path = StimulusReflex::Installer.config_path / "stimulus_reflex.js"
13
13
  friendly_stimulus_reflex_path = stimulus_reflex_path.relative_path_from(Rails.root).to_s
14
- cable_ready_src = fetch(step_path, "cable_ready.js.tt")
15
- cable_ready_path = config_path / "cable_ready.js"
14
+ cable_ready_src = StimulusReflex::Installer.fetch(step_path, "cable_ready.js.tt")
15
+ cable_ready_path = StimulusReflex::Installer.config_path / "cable_ready.js"
16
16
 
17
- empty_directory config_path unless config_path.exist?
17
+ empty_directory StimulusReflex::Installer.config_path unless StimulusReflex::Installer.config_path.exist?
18
18
 
19
19
  if index_path.exist?
20
20
  say "⏩ #{friendly_index_path} already exists. Skipping"
21
21
  else
22
- backup(index_path, delete: true) do
22
+ StimulusReflex::Installer.backup(index_path, delete: true) do
23
23
  template(index_src, index_path)
24
24
  end
25
25
  say "✅ Created #{friendly_index_path}"
@@ -27,26 +27,26 @@ end
27
27
 
28
28
  index_pattern = /import ['"](\.\.\/|\.\/)?config['"]/
29
29
  index_commented_pattern = /\s*\/\/\s*#{index_pattern}/
30
- index_import = "import \"#{prefix}config\"\n"
30
+ index_import = "import \"#{StimulusReflex::Installer.prefix}config\"\n"
31
31
 
32
- if pack.match?(index_pattern)
33
- if pack.match?(index_commented_pattern)
34
- lines = pack_path.readlines
32
+ if StimulusReflex::Installer.pack.match?(index_pattern)
33
+ if StimulusReflex::Installer.pack.match?(index_commented_pattern)
34
+ lines = StimulusReflex::Installer.pack_path.readlines
35
35
  matches = lines.select { |line| line =~ index_commented_pattern }
36
36
  lines[lines.index(matches.last).to_i] = index_import
37
- pack_path.write lines.join
37
+ StimulusReflex::Installer.pack_path.write lines.join
38
38
 
39
- say "✅ Uncommented StimulusReflex and CableReady configs imports in #{friendly_pack_path}"
39
+ say "✅ Uncommented StimulusReflex and CableReady configs imports in #{StimulusReflex::Installer.friendly_pack_path}"
40
40
  else
41
- say "⏩ StimulusReflex and CableReady configs are already being imported in #{friendly_pack_path}. Skipping"
41
+ say "⏩ StimulusReflex and CableReady configs are already being imported in #{StimulusReflex::Installer.friendly_pack_path}. Skipping"
42
42
  end
43
43
  else
44
- lines = pack_path.readlines
44
+ lines = StimulusReflex::Installer.pack_path.readlines
45
45
  matches = lines.select { |line| line =~ /^import / }
46
46
  lines.insert lines.index(matches.last).to_i + 1, index_import
47
- pack_path.write lines.join
47
+ StimulusReflex::Installer.pack_path.write lines.join
48
48
 
49
- say "✅ StimulusReflex and CableReady configs will be imported in #{friendly_pack_path}"
49
+ say "✅ StimulusReflex and CableReady configs will be imported in #{StimulusReflex::Installer.friendly_pack_path}"
50
50
  end
51
51
 
52
52
  # create entrypoint/config/cable_ready.js and make sure it's imported in application.js
@@ -58,14 +58,14 @@ template(stimulus_reflex_src, stimulus_reflex_path) unless stimulus_reflex_path.
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 bundler.webpacker? || bundler.shakapacker?
61
+ if StimulusReflex::Installer.bundler.webpacker? || StimulusReflex::Installer.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.vite?
68
+ elsif StimulusReflex::Installer.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") {
@@ -84,4 +84,4 @@ else
84
84
  say "✅ Set useful development environment options in #{friendly_stimulus_reflex_path}"
85
85
  end
86
86
 
87
- complete_step :config
87
+ StimulusReflex::Installer.complete_step :config
@@ -3,56 +3,56 @@
3
3
  require "stimulus_reflex/installer"
4
4
 
5
5
  # mutate working copy of development.rb to avoid bundle alerts
6
- FileUtils.cp(development_path, development_working_path)
6
+ FileUtils.cp(StimulusReflex::Installer.development_path, StimulusReflex::Installer.development_working_path)
7
7
 
8
8
  # add default_url_options to development.rb for Action Mailer
9
9
  if defined?(ActionMailer)
10
- lines = development_working_path.readlines
10
+ lines = StimulusReflex::Installer.development_working_path.readlines
11
11
  if lines.find { |line| line.include?("config.action_mailer.default_url_options") }
12
12
  say "⏩ Action Mailer default_url_options already defined. Skipping."
13
13
  else
14
14
  index = lines.index { |line| line =~ /^Rails.application.configure do/ }
15
15
  lines.insert index + 1, " config.action_mailer.default_url_options = {host: \"localhost\", port: 3000}\n\n"
16
- development_working_path.write lines.join
16
+ StimulusReflex::Installer.development_working_path.write lines.join
17
17
 
18
18
  say "✅ Action Mailer default_url_options defined"
19
19
  end
20
20
  end
21
21
 
22
22
  # add default_url_options to development.rb for Action Controller
23
- lines = development_working_path.readlines
23
+ lines = StimulusReflex::Installer.development_working_path.readlines
24
24
  if lines.find { |line| line.include?("config.action_controller.default_url_options") }
25
25
  say "⏩ Action Controller default_url_options already defined. Skipping."
26
26
  else
27
27
  index = lines.index { |line| line =~ /^Rails.application.configure do/ }
28
28
  lines.insert index + 1, " config.action_controller.default_url_options = {host: \"localhost\", port: 3000}\n"
29
- development_working_path.write lines.join
29
+ StimulusReflex::Installer.development_working_path.write lines.join
30
30
 
31
31
  say "✅ Action Controller default_url_options defined"
32
32
  end
33
33
 
34
- # halt with instructions if using cookie store, otherwise, nudge towards Redis
35
- lines = development_working_path.readlines
34
+ # StimulusReflex::Installer.halt with instructions if using cookie store, otherwise, nudge towards Redis
35
+ lines = StimulusReflex::Installer.development_working_path.readlines
36
36
 
37
37
  if (index = lines.index { |line| line =~ /^[^#]*config.session_store/ })
38
38
  if /^[^#]*cookie_store/.match?(lines[index])
39
- write_redis_recommendation(development_working_path, lines, index, gemfile)
40
- halt "StimulusReflex does not support session cookies. See https://docs.stimulusreflex.com/hello-world/setup#session-storage"
39
+ StimulusReflex::Installer.write_redis_recommendation(StimulusReflex::Installer.development_working_path, lines, index, StimulusReflex::Installer.gemfile)
40
+ StimulusReflex::Installer.halt "StimulusReflex does not support session cookies. See https://docs.stimulusreflex.com/hello-world/setup#session-storage"
41
41
  return
42
42
  elsif /^[^#]*redis_session_store/.match?(lines[index])
43
43
  say "⏩ Already using redis-session-store for session storage. Skipping."
44
44
  else
45
- write_redis_recommendation(development_working_path, lines, index, gemfile)
45
+ StimulusReflex::Installer.write_redis_recommendation(StimulusReflex::Installer.development_working_path, lines, index, StimulusReflex::Installer.gemfile)
46
46
  say "🤷 We recommend using redis-session-store for session storage. See https://docs.stimulusreflex.com/hello-world/setup#session-storage"
47
47
  end
48
48
  # no session store defined, so let's opt-in to redis-session-store
49
49
  else
50
50
  # add redis-session-store to Gemfile
51
- if !gemfile.match?(/gem ['"]redis-session-store['"]/)
51
+ if !StimulusReflex::Installer.gemfile.match?(/gem ['"]redis-session-store['"]/)
52
52
  if ActionCable::VERSION::MAJOR >= 7
53
- add_gem "redis-session-store@~> 0.11.5"
53
+ StimulusReflex::Installer.add_gem "redis-session-store@~> 0.11.5"
54
54
  else
55
- add_gem "redis-session-store@0.11.4"
55
+ StimulusReflex::Installer.add_gem "redis-session-store@0.11.4"
56
56
  end
57
57
  end
58
58
 
@@ -68,12 +68,12 @@ else
68
68
  url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }
69
69
  }
70
70
  RUBY
71
- development_working_path.write lines.join
71
+ StimulusReflex::Installer.development_working_path.write lines.join
72
72
  say "✅ Using redis-session-store for session storage"
73
73
  end
74
74
 
75
75
  # switch to redis for caching if using memory store, otherwise nudge with a comment
76
- lines = development_working_path.readlines
76
+ lines = StimulusReflex::Installer.development_working_path.readlines
77
77
 
78
78
  if (index = lines.index { |line| line =~ /^[^#]*config.cache_store = :memory_store/ })
79
79
  lines[index] = <<~RUBY
@@ -81,13 +81,13 @@ if (index = lines.index { |line| line =~ /^[^#]*config.cache_store = :memory_sto
81
81
  url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }
82
82
  }
83
83
  RUBY
84
- development_working_path.write lines.join
84
+ StimulusReflex::Installer.development_working_path.write lines.join
85
85
  say "✅ Using Redis for caching"
86
86
  elsif lines.index { |line| line =~ /^[^#]*config.cache_store = :redis_cache_store/ }
87
87
  say "⏩ Already using Redis for caching. Skipping."
88
88
  else
89
89
  if !lines.index { |line| line.include?("We couldn't identify your cache store") }
90
- lines.insert find_index(lines), <<~RUBY
90
+ lines.insert StimulusReflex::Installer.find_index(lines), <<~RUBY
91
91
 
92
92
  # We couldn't identify your cache store, but recommend using Redis:
93
93
 
@@ -95,7 +95,7 @@ else
95
95
  # url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }
96
96
  # }
97
97
  RUBY
98
- development_working_path.write lines.join
98
+ StimulusReflex::Installer.development_working_path.write lines.join
99
99
  end
100
100
  say "🤷 We couldn't identify your cache store, but recommend using Redis. See https://docs.stimulusreflex.com/appendices/deployment#use-redis-as-your-cache-store"
101
101
  end
@@ -107,4 +107,4 @@ else
107
107
  say "✅ Enabled caching in development"
108
108
  end
109
109
 
110
- complete_step :development
110
+ StimulusReflex::Installer.complete_step :development