stimulus_reflex 3.5.0.rc4 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +19 -13
  3. data/app/assets/javascripts/stimulus_reflex.js +1 -1
  4. data/app/assets/javascripts/stimulus_reflex.umd.js +1 -1
  5. data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +2 -2
  6. data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +1 -1
  7. data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +1 -1
  8. data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +1 -1
  9. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +1 -1
  10. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +1 -1
  11. data/lib/install/action_cable.rb +30 -30
  12. data/lib/install/broadcaster.rb +11 -11
  13. data/lib/install/bundle.rb +9 -9
  14. data/lib/install/compression.rb +5 -5
  15. data/lib/install/config.rb +22 -22
  16. data/lib/install/development.rb +19 -19
  17. data/lib/install/esbuild.rb +28 -28
  18. data/lib/install/example.rb +3 -3
  19. data/lib/install/importmap.rb +29 -29
  20. data/lib/install/initializers.rb +3 -3
  21. data/lib/install/mrujs.rb +25 -25
  22. data/lib/install/npm_packages.rb +7 -7
  23. data/lib/install/reflexes.rb +2 -2
  24. data/lib/install/shakapacker.rb +23 -23
  25. data/lib/install/spring.rb +7 -7
  26. data/lib/install/updatable.rb +7 -7
  27. data/lib/install/vite.rb +22 -22
  28. data/lib/install/webpacker.rb +27 -27
  29. data/lib/install/yarn.rb +9 -9
  30. data/lib/stimulus_reflex/html/document_fragment.rb +5 -3
  31. data/lib/stimulus_reflex/installer.rb +303 -277
  32. data/lib/stimulus_reflex/version.rb +1 -1
  33. data/lib/stimulus_reflex.rb +2 -0
  34. data/lib/tasks/stimulus_reflex/stimulus_reflex.rake +8 -8
  35. data/package.json +1 -1
  36. data/stimulus_reflex.gemspec +2 -0
  37. data/yarn.lock +7 -7
  38. metadata +30 -2
@@ -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
@@ -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
@@ -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
@@ -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 "#{friendly_importmap_path} is missing. You need a valid importmap config file to proceed."
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
@@ -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 "#{friendly_importmap_path} is missing. You need a valid importmap config file to proceed."
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
@@ -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
@@ -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