cable_ready 5.0.3 → 5.0.4

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.
@@ -2,14 +2,14 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- proceed = if options.key? "broadcaster"
6
- options["broadcaster"]
5
+ proceed = if CableReady::Installer.options.key? "broadcaster"
6
+ CableReady::Installer.options["broadcaster"]
7
7
  else
8
8
  !no?("✨ Make CableReady::Broadcaster available to channels, controllers, jobs and models? (Y/n)")
9
9
  end
10
10
 
11
11
  unless proceed
12
- complete_step :broadcaster
12
+ CableReady::Installer.complete_step :broadcaster
13
13
 
14
14
  puts "⏩ Skipping."
15
15
  return
@@ -20,7 +20,7 @@ channel_path = Rails.root.join("app/channels/application_cable/channel.rb")
20
20
  if channel_path.exist?
21
21
  lines = channel_path.readlines
22
22
  if !lines.index { |line| line =~ /^\s*include CableReady::Broadcaster/ }
23
- backup(channel_path) do
23
+ CableReady::Installer.backup(channel_path) do
24
24
  index = lines.index { |line| line.include?("class Channel < ActionCable::Channel::Base") }
25
25
  lines.insert index + 1, " include CableReady::Broadcaster\n"
26
26
  channel_path.write lines.join
@@ -37,7 +37,7 @@ controller_path = Rails.root.join("app/controllers/application_controller.rb")
37
37
  if controller_path.exist?
38
38
  lines = controller_path.readlines
39
39
  if !lines.index { |line| line =~ /^\s*include CableReady::Broadcaster/ }
40
- backup(controller_path) do
40
+ CableReady::Installer.backup(controller_path) do
41
41
  index = lines.index { |line| line.include?("class ApplicationController < ActionController::Base") }
42
42
  lines.insert index + 1, " include CableReady::Broadcaster\n"
43
43
  controller_path.write lines.join
@@ -55,7 +55,7 @@ if defined?(ActiveJob)
55
55
  if job_path.exist?
56
56
  lines = job_path.readlines
57
57
  if !lines.index { |line| line =~ /^\s*include CableReady::Broadcaster/ }
58
- backup(job_path) do
58
+ CableReady::Installer.backup(job_path) do
59
59
  index = lines.index { |line| line.include?("class ApplicationJob < ActiveJob::Base") }
60
60
  lines.insert index + 1, " include CableReady::Broadcaster\n"
61
61
  job_path.write lines.join
@@ -72,9 +72,9 @@ end
72
72
 
73
73
  # include CableReady::Broadcaster in StateMachines, if present
74
74
  if defined?(StateMachines)
75
- lines = action_cable_initializer_working_path.read
75
+ lines = CableReady::Installer.action_cable_initializer_working_path.read
76
76
  if !lines.include?("StateMachines::Machine.prepend(CableReady::Broadcaster)")
77
- inject_into_file action_cable_initializer_working_path, after: "CableReady.configure do |config|\n", verbose: false do
77
+ inject_into_file CableReady::Installer.action_cable_initializer_working_path, after: "CableReady.configure do |config|\n", verbose: false do
78
78
  <<-RUBY
79
79
 
80
80
  StateMachines::Machine.prepend(CableReady::Broadcaster)
@@ -91,13 +91,13 @@ else
91
91
  end
92
92
 
93
93
  # include CableReady::Broadcaster in Active Record model classes
94
- if Rails.root.join(application_record_path).exist?
95
- lines = application_record_path.readlines
94
+ if Rails.root.join(CableReady::Installer.application_record_path).exist?
95
+ lines = CableReady::Installer.application_record_path.readlines
96
96
  if !lines.index { |line| line =~ /^\s*include CableReady::Broadcaster/ }
97
- backup(application_record_path) do
97
+ CableReady::Installer.backup(CableReady::Installer.application_record_path) do
98
98
  index = lines.index { |line| line.include?("class ApplicationRecord < ActiveRecord::Base") }
99
99
  lines.insert index + 1, " include CableReady::Broadcaster\n"
100
- application_record_path.write lines.join
100
+ CableReady::Installer.application_record_path.write lines.join
101
101
  end
102
102
 
103
103
  puts "✅ include CableReady::Broadcaster in Active Record model classes"
@@ -106,4 +106,4 @@ if Rails.root.join(application_record_path).exist?
106
106
  end
107
107
  end
108
108
 
109
- complete_step :broadcaster
109
+ CableReady::Installer.complete_step :broadcaster
@@ -2,14 +2,14 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- hash = gemfile_hash
5
+ hash = CableReady::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 = CableReady::Installer.add_gem_list.exist? ? CableReady::Installer.add_gem_list.readlines.map(&:chomp) : []
9
+ remove = CableReady::Installer.remove_gem_list.exist? ? CableReady::Installer.remove_gem_list.readlines.map(&:chomp) : []
10
10
 
11
11
  if add.present? || remove.present?
12
- lines = gemfile_path.readlines
12
+ lines = CableReady::Installer.gemfile_path.readlines
13
13
 
14
14
  remove.each do |name|
15
15
  index = lines.index { |line| line =~ /gem ['"]#{name}['"]/ }
@@ -40,15 +40,15 @@ if add.present? || remove.present?
40
40
  end
41
41
  end
42
42
 
43
- gemfile_path.write lines.join
43
+ CableReady::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 != CableReady::Installer.gemfile_hash
46
46
  end
47
47
 
48
- FileUtils.cp(development_working_path, development_path)
48
+ FileUtils.cp(CableReady::Installer.development_working_path, CableReady::Installer.development_path)
49
49
  say "✅ development environment configuration installed"
50
50
 
51
- FileUtils.cp(action_cable_initializer_working_path, action_cable_initializer_path)
51
+ FileUtils.cp(CableReady::Installer.action_cable_initializer_working_path, CableReady::Installer.action_cable_initializer_path)
52
52
  say "✅ Action Cable initializer installed"
53
53
 
54
- complete_step :bundle
54
+ CableReady::Installer.complete_step :bundle
@@ -2,26 +2,26 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- initializer = action_cable_initializer_working_path.read
5
+ initializer = CableReady::Installer.action_cable_initializer_working_path.read
6
6
 
7
7
  proceed = false
8
8
 
9
9
  if initializer.exclude? "PermessageDeflate.configure"
10
- proceed = if options.key? "compression"
11
- options["compression"]
10
+ proceed = if CableReady::Installer.options.key? "compression"
11
+ CableReady::Installer.options["compression"]
12
12
  else
13
13
  !no?("✨ Configure Action Cable to compress your WebSocket traffic with gzip? (Y/n)")
14
14
  end
15
15
  end
16
16
 
17
17
  if proceed
18
- if !gemfile.match?(/gem ['"]permessage_deflate['"]/)
19
- add_gem "permessage_deflate@>= 0.1"
18
+ if !CableReady::Installer.gemfile.match?(/gem ['"]permessage_deflate['"]/)
19
+ CableReady::Installer.add_gem "permessage_deflate@>= 0.1"
20
20
  end
21
21
 
22
22
  # add permessage_deflate config to Action Cable initializer
23
23
  if initializer.exclude? "PermessageDeflate.configure"
24
- create_or_append(action_cable_initializer_working_path, verbose: false) do
24
+ CableReady::Installer.create_or_append(CableReady::Installer.action_cable_initializer_working_path, verbose: false) do
25
25
  <<~RUBY
26
26
  module ActionCable
27
27
  module Connection
@@ -48,4 +48,4 @@ if proceed
48
48
  end
49
49
  end
50
50
 
51
- complete_step :compression
51
+ CableReady::Installer.complete_step :compression
@@ -2,38 +2,38 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- return if pack_path_missing?
5
+ return if CableReady::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"
10
- cable_ready_src = fetch(step_path, "cable_ready.js.tt")
11
- cable_ready_path = config_path / "cable_ready.js"
8
+ index_src = CableReady::Installer.fetch(step_path, "index.js.tt")
9
+ index_path = CableReady::Installer.config_path / "index.js"
10
+ cable_ready_src = CableReady::Installer.fetch(step_path, "cable_ready.js.tt")
11
+ cable_ready_path = CableReady::Installer.config_path / "cable_ready.js"
12
12
 
13
- empty_directory config_path unless config_path.exist?
13
+ empty_directory CableReady::Installer.config_path unless CableReady::Installer.config_path.exist?
14
14
 
15
- copy_file(index_src, index_path) unless index_path.exist?
15
+ CableReady::Installer.copy_file(index_src, index_path) unless index_path.exist?
16
16
 
17
17
  index_pattern = /import ['"](\.\.\/|\.\/)?config['"]/
18
18
  index_commented_pattern = /\s*\/\/\s*#{index_pattern}/
19
- index_import = "import \"#{prefix}config\"\n"
19
+ index_import = "import \"#{CableReady::Installer.prefix}config\"\n"
20
20
 
21
- if pack.match?(index_pattern)
22
- if pack.match?(index_commented_pattern)
23
- lines = pack_path.readlines
21
+ if CableReady::Installer.pack.match?(index_pattern)
22
+ if CableReady::Installer.pack.match?(index_commented_pattern)
23
+ lines = CableReady::Installer.pack_path.readlines
24
24
  matches = lines.select { |line| line =~ index_commented_pattern }
25
25
  lines[lines.index(matches.last).to_i] = index_import
26
- pack_path.write lines.join
26
+ CableReady::Installer.pack_path.write lines.join
27
27
  end
28
28
  else
29
- lines = pack_path.readlines
29
+ lines = CableReady::Installer.pack_path.readlines
30
30
  matches = lines.select { |line| line =~ /^import / }
31
31
  lines.insert lines.index(matches.last).to_i + 1, index_import
32
- pack_path.write lines.join
32
+ CableReady::Installer.pack_path.write lines.join
33
33
  end
34
- say "✅ CableReady configs will be imported in #{friendly_pack_path}"
34
+ say "✅ CableReady configs will be imported in #{CableReady::Installer.friendly_pack_path}"
35
35
 
36
36
  # create entrypoint/config/cable_ready.js and make sure it's imported in application.js
37
- copy_file(cable_ready_src, cable_ready_path) unless cable_ready_path.exist?
37
+ CableReady::Installer.copy_file(cable_ready_src, cable_ready_path) unless cable_ready_path.exist?
38
38
 
39
- complete_step :config
39
+ CableReady::Installer.complete_step :config
@@ -3,32 +3,32 @@
3
3
  require "cable_ready/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(CableReady::Installer.development_path, CableReady::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 = CableReady::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
+ CableReady::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 = CableReady::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
+ CableReady::Installer.development_working_path.write lines.join
30
30
 
31
31
  say "✅ Action Controller default_url_options defined"
32
32
  end
33
33
 
34
- complete_step :development
34
+ CableReady::Installer.complete_step :development
@@ -2,47 +2,47 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- return if pack_path_missing?
5
+ return if CableReady::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.readlines
8
+ lines = CableReady::Installer.package_json.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
+ CableReady::Installer.add_package "esbuild-rails@^1.0.3"
12
12
  end
13
13
 
14
14
  if !lines.index { |line| line =~ /^\s*["']@hotwired\/stimulus["']:/ }
15
- add_package "@hotwired/stimulus@^3.2"
15
+ CableReady::Installer.add_package "@hotwired/stimulus@^3.2"
16
16
  end
17
17
  # copy esbuild.config.mjs to app root
18
- esbuild_src = fetch("/", "esbuild.config.mjs.tt")
18
+ esbuild_src = CableReady::Installer.fetch("/", "esbuild.config.mjs.tt")
19
19
  esbuild_path = Rails.root.join("esbuild.config.mjs")
20
20
  if esbuild_path.exist?
21
21
  if esbuild_path.read == esbuild_src.read
22
22
  say "✅ esbuild.config.mjs present in app root"
23
23
  else
24
- backup(esbuild_path) do
25
- template(esbuild_src, esbuild_path, verbose: false, entrypoint: entrypoint)
24
+ CableReady::Installer.backup(esbuild_path) do
25
+ template(esbuild_src, esbuild_path, verbose: false, entrypoint: CableReady::Installer.entrypoint)
26
26
  end
27
27
  end
28
28
  else
29
- template(esbuild_src, esbuild_path, entrypoint: entrypoint)
29
+ template(esbuild_src, esbuild_path, entrypoint: CableReady::Installer.entrypoint)
30
30
  end
31
31
 
32
32
  step_path = "/app/javascript/controllers/"
33
- application_js_src = fetch(step_path, "application.js.tt")
34
- application_js_path = controllers_path / "application.js"
35
- index_src = fetch(step_path, "index.js.esbuild.tt")
36
- index_path = controllers_path / "index.js"
33
+ application_js_src = CableReady::Installer.fetch(step_path, "application.js.tt")
34
+ application_js_path = CableReady::Installer.controllers_path / "application.js"
35
+ index_src = CableReady::Installer.fetch(step_path, "index.js.esbuild.tt")
36
+ index_path = CableReady::Installer.controllers_path / "index.js"
37
37
  friendly_index_path = index_path.relative_path_from(Rails.root).to_s
38
38
 
39
39
  # create entrypoint/controllers, if necessary
40
- empty_directory controllers_path unless controllers_path.exist?
40
+ empty_directory CableReady::Installer.controllers_path unless CableReady::Installer.controllers_path.exist?
41
41
 
42
42
  # configure Stimulus application superclass to import Action Cable consumer
43
43
  friendly_application_js_path = application_js_path.relative_path_from(Rails.root).to_s
44
44
  if application_js_path.exist?
45
- backup(application_js_path) do
45
+ CableReady::Installer.backup(application_js_path) do
46
46
  if application_js_path.read.include?("import consumer")
47
47
  say "✅ #{friendly_application_js_path} is present"
48
48
  else
@@ -52,12 +52,12 @@ if application_js_path.exist?
52
52
  end
53
53
  end
54
54
  else
55
- copy_file(application_js_src, application_js_path)
55
+ CableReady::Installer.copy_file(application_js_src, application_js_path)
56
56
  end
57
57
 
58
58
  if index_path.exist?
59
59
  if index_path.read != index_src.read
60
- backup(index_path, delete: true) do
60
+ CableReady::Installer.backup(index_path, delete: true) do
61
61
  copy_file(index_src, index_path, verbose: false)
62
62
  end
63
63
  end
@@ -69,33 +69,33 @@ say "✅ #{friendly_index_path} has been created"
69
69
  controllers_pattern = /import ['"].\/controllers['"]/
70
70
  controllers_commented_pattern = /\s*\/\/\s*#{controllers_pattern}/
71
71
 
72
- if pack.match?(controllers_pattern)
73
- if pack.match?(controllers_commented_pattern)
74
- proceed = if options.key? "uncomment"
75
- options["uncomment"]
72
+ if CableReady::Installer.pack.match?(controllers_pattern)
73
+ if CableReady::Installer.pack.match?(controllers_commented_pattern)
74
+ proceed = if CableReady::Installer.options.key? "uncomment"
75
+ CableReady::Installer.options["uncomment"]
76
76
  else
77
77
  !no?("✨ Stimulus seems to be commented out in your application.js. Do you want to import your controllers? (Y/n)")
78
78
  end
79
79
 
80
80
  if proceed
81
81
  # uncomment_lines only works with Ruby comments 🙄
82
- lines = pack_path.readlines
82
+ lines = CableReady::Installer.pack_path.readlines
83
83
  matches = lines.select { |line| line =~ controllers_commented_pattern }
84
84
  lines[lines.index(matches.last).to_i] = "import \".\/controllers\"\n" # standard:disable Style/RedundantStringEscape
85
- pack_path.write lines.join
86
- say "✅ Stimulus controllers imported in #{friendly_pack_path}"
85
+ CableReady::Installer.pack_path.write lines.join
86
+ say "✅ Stimulus controllers imported in #{CableReady::Installer.friendly_pack_path}"
87
87
  else
88
88
  say "🤷 your Stimulus controllers are not being imported in your application.js. We trust that you have a reason for this."
89
89
  end
90
90
  else
91
- say "✅ Stimulus controllers imported in #{friendly_pack_path}"
91
+ say "✅ Stimulus controllers imported in #{CableReady::Installer.friendly_pack_path}"
92
92
  end
93
93
  else
94
- lines = pack_path.readlines
94
+ lines = CableReady::Installer.pack_path.readlines
95
95
  matches = lines.select { |line| line =~ /^import / }
96
96
  lines.insert lines.index(matches.last).to_i + 1, "import \".\/controllers\"\n" # standard:disable Style/RedundantStringEscape
97
- pack_path.write lines.join
98
- say "✅ Stimulus controllers imported in #{friendly_pack_path}"
97
+ CableReady::Installer.pack_path.write lines.join
98
+ say "✅ Stimulus controllers imported in #{CableReady::Installer.friendly_pack_path}"
99
99
  end
100
100
 
101
- complete_step :esbuild
101
+ CableReady::Installer.complete_step :esbuild
@@ -2,69 +2,69 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- return if pack_path_missing?
5
+ return if CableReady::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 !CableReady::Installer.importmap_path.exist?
8
+ CableReady::Installer.halt "#{friendly_CableReady::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 = CableReady::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
+ CableReady::Installer.backup(CableReady::Installer.importmap_path) do
15
+ if !importmap.include?("pin_all_from \"#{CableReady::Installer.entrypoint}/controllers\"")
16
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
17
+ pin_all_from "#{CableReady::Installer.entrypoint}/controllers", under: "controllers"
18
18
  RUBY
19
19
  say "✅ pin controllers folder"
20
20
  end
21
21
 
22
- if !importmap.include?("pin_all_from \"#{entrypoint}/channels\"")
23
- append_file(importmap_path, <<~RUBY, verbose: false)
24
- pin_all_from "#{entrypoint}/channels", under: "channels"
22
+ if !importmap.include?("pin_all_from \"#{CableReady::Installer.entrypoint}/channels\"")
23
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
24
+ pin_all_from "#{CableReady::Installer.entrypoint}/channels", under: "channels"
25
25
  RUBY
26
26
  say "✅ pin channels folder"
27
27
  end
28
28
 
29
- if !importmap.include?("pin_all_from \"#{entrypoint}/config\"")
30
- append_file(importmap_path, <<~RUBY, verbose: false)
31
- pin_all_from "#{entrypoint}/config", under: "config"
29
+ if !importmap.include?("pin_all_from \"#{CableReady::Installer.entrypoint}/config\"")
30
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
31
+ pin_all_from "#{CableReady::Installer.entrypoint}/config", under: "config"
32
32
  RUBY
33
33
  say "✅ pin config folder"
34
34
  end
35
35
 
36
36
  if !importmap.include?("pin \"@rails/actioncable\"")
37
- append_file(importmap_path, <<~RUBY, verbose: false)
37
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
38
38
  pin "@rails/actioncable", to: "actioncable.esm.js", preload: true
39
39
  RUBY
40
40
  say "✅ pin Action Cable"
41
41
  end
42
42
 
43
43
  if !importmap.include?("pin \"cable_ready\"")
44
- append_file(importmap_path, <<~RUBY, verbose: false)
44
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
45
45
  pin "cable_ready", to: "cable_ready.js", preload: true
46
46
  RUBY
47
47
  say "✅ pin CableReady"
48
48
  end
49
49
 
50
50
  if !importmap.include?("pin \"morphdom\"")
51
- append_file(importmap_path, <<~RUBY, verbose: false)
51
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
52
52
  pin "morphdom", to: "https://ga.jspm.io/npm:morphdom@2.6.1/dist/morphdom.js", preload: true
53
53
  RUBY
54
54
  say "✅ pin morphdom"
55
55
  end
56
56
  end
57
57
 
58
- application_js_src = fetch("/", "app/javascript/controllers/application.js.tt")
59
- application_js_path = controllers_path / "application.js"
60
- index_src = fetch("/", "app/javascript/controllers/index.js.importmap.tt")
61
- index_path = controllers_path / "index.js"
58
+ application_js_src = CableReady::Installer.fetch("/", "app/javascript/controllers/application.js.tt")
59
+ application_js_path = CableReady::Installer.controllers_path / "application.js"
60
+ index_src = CableReady::Installer.fetch("/", "app/javascript/controllers/index.js.importmap.tt")
61
+ index_path = CableReady::Installer.controllers_path / "index.js"
62
62
 
63
63
  # create entrypoint/controllers, as well as the index, application and application_controller
64
- empty_directory controllers_path unless controllers_path.exist?
64
+ empty_directory CableReady::Installer.controllers_path unless CableReady::Installer.controllers_path.exist?
65
65
 
66
66
  # configure Stimulus application superclass to import Action Cable consumer
67
- backup(application_js_path) do
67
+ CableReady::Installer.backup(application_js_path) do
68
68
  if application_js_path.exist?
69
69
  friendly_application_js_path = application_js_path.relative_path_from(Rails.root).to_s
70
70
  if application_js_path.read.include?("import consumer")
@@ -84,7 +84,7 @@ if index_path.exist?
84
84
  if index_path.read == index_src.read
85
85
  say "✅ #{friendly_index_path} is present"
86
86
  else
87
- backup(index_path, delete: true) do
87
+ CableReady::Installer.backup(index_path, delete: true) do
88
88
  copy_file(index_src, index_path, verbose: false)
89
89
  end
90
90
  say "✅ #{friendly_index_path} has been created"
@@ -93,4 +93,4 @@ else
93
93
  copy_file(index_src, index_path)
94
94
  end
95
95
 
96
- complete_step :importmap
96
+ CableReady::Installer.complete_step :importmap
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- cr_initializer_src = fetch("/", "config/initializers/cable_ready.rb")
5
+ cr_initializer_src = CableReady::Installer.fetch("/", "config/initializers/cable_ready.rb")
6
6
  cr_initializer_path = Rails.root.join("config/initializers/cable_ready.rb")
7
7
 
8
8
  if !cr_initializer_path.exist?
@@ -12,4 +12,4 @@ else
12
12
  say "⏩ config/initializers/cable_ready.rb already exists. Skipping."
13
13
  end
14
14
 
15
- complete_step :initializers
15
+ CableReady::Installer.complete_step :initializers
data/lib/install/mrujs.rb CHANGED
@@ -2,63 +2,63 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- return if pack_path_missing?
5
+ return if CableReady::Installer.pack_path_missing?
6
6
 
7
- mrujs_path = config_path / "mrujs.js"
7
+ mrujs_path = CableReady::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 CableReady::Installer.options.key? "mrujs"
13
+ CableReady::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 CableReady::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 !CableReady::Installer.importmap_path.exist?
23
+ CableReady::Installer.halt "#{friendly_CableReady::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 = CableReady::Installer.importmap_path.read
28
28
 
29
29
  if !importmap.include?("pin \"mrujs\"")
30
- append_file(importmap_path, <<~RUBY, verbose: false)
30
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
31
31
  pin "mrujs", to: "https://ga.jspm.io/npm:mrujs@0.10.1/dist/index.module.js"
32
32
  RUBY
33
33
  say "✅ pin mrujs"
34
34
  end
35
35
 
36
36
  if !importmap.include?("pin \"mrujs/plugins\"")
37
- append_file(importmap_path, <<~RUBY, verbose: false)
37
+ append_file(CableReady::Installer.importmap_path, <<~RUBY, verbose: false)
38
38
  pin "mrujs/plugins", to: "https://ga.jspm.io/npm:mrujs@0.10.1/plugins/dist/plugins.module.js"
39
39
  RUBY
40
40
  say "✅ pin mrujs plugins"
41
41
  end
42
42
  else
43
43
  # queue mrujs for installation
44
- if !package_json.read.include?('"mrujs":')
45
- add_package "mrujs@^0.10.1"
44
+ if !CableReady::Installer.package_json.read.include?('"mrujs":')
45
+ CableReady::Installer.add_package "mrujs@^0.10.1"
46
46
  end
47
47
 
48
48
  # queue @rails/ujs for removal
49
- if package_json.read.include?('"@rails/ujs":')
50
- drop_package "@rails/ujs"
49
+ if CableReady::Installer.package_json.read.include?('"@rails/ujs":')
50
+ CableReady::Installer.drop_package "@rails/ujs"
51
51
  end
52
52
  end
53
53
 
54
54
  step_path = "/app/javascript/config/"
55
- mrujs_src = fetch(step_path, "mrujs.js.tt")
55
+ mrujs_src = CableReady::Installer.fetch(step_path, "mrujs.js.tt")
56
56
 
57
57
  # create entrypoint/config/mrujs.js if necessary
58
58
  copy_file(mrujs_src, mrujs_path) unless mrujs_path.exist?
59
59
 
60
60
  # import mrujs config in entrypoint/config/index.js
61
- index_path = config_path / "index.js"
61
+ index_path = CableReady::Installer.config_path / "index.js"
62
62
  index = index_path.read
63
63
  friendly_index_path = index_path.relative_path_from(Rails.root).to_s
64
64
  mrujs_pattern = /import ['"].\/mrujs['"]/
@@ -72,10 +72,10 @@ if proceed
72
72
  # remove @rails/ujs from application.js
73
73
  rails_ujs_pattern = /import Rails from ['"]@rails\/ujs['"]/
74
74
 
75
- lines = pack_path.readlines
75
+ lines = CableReady::Installer.pack_path.readlines
76
76
  if lines.index { |line| line =~ rails_ujs_pattern }
77
77
  gsub_file pack_path, rails_ujs_pattern, "", verbose: false
78
- say "✅ @rails/ujs removed from #{friendly_pack_path}"
78
+ say "✅ @rails/ujs removed from #{CableReady::Installer.friendly_pack_path}"
79
79
  end
80
80
 
81
81
  # set Action View to generate remote forms when using form_with
@@ -84,7 +84,7 @@ if proceed
84
84
  defaults_pattern = /config\.load_defaults \d\.\d/
85
85
 
86
86
  lines = application_path.readlines
87
- backup(application_path) do
87
+ CableReady::Installer.backup(application_path) do
88
88
  if !lines.index { |line| line =~ application_pattern }
89
89
  if (index = lines.index { |line| line =~ /^[^#]*#{defaults_pattern}/ })
90
90
  gsub_file application_path, /\s*#{defaults_pattern}\n/, verbose: false do
@@ -110,12 +110,12 @@ if proceed
110
110
  # remove turbolinks from Gemfile because it's incompatible with mrujs (and unnecessary)
111
111
  turbolinks_pattern = /^[^#]*gem ["']turbolinks["']/
112
112
 
113
- lines = gemfile_path.readlines
113
+ lines = CableReady::Installer.gemfile_path.readlines
114
114
  if lines.index { |line| line =~ turbolinks_pattern }
115
- remove_gem :turbolinks
115
+ CableReady::Installer.remove_gem :turbolinks
116
116
  else
117
117
  say "✅ turbolinks is not present in Gemfile"
118
118
  end
119
119
  end
120
120
 
121
- complete_step :mrujs
121
+ CableReady::Installer.complete_step :mrujs
@@ -2,12 +2,12 @@
2
2
 
3
3
  require "cable_ready/installer"
4
4
 
5
- lines = package_json.readlines
5
+ lines = CableReady::Installer.package_json.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["']: ["'].*#{CableReady::Installer.cr_npm_version}["']/ }
8
+ CableReady::Installer.add_package "cable_ready@#{CableReady::Installer.cr_npm_version}"
9
9
  else
10
10
  say "⏩ cable_ready npm package is already present"
11
11
  end
12
12
 
13
- complete_step :npm_packages
13
+ CableReady::Installer.complete_step :npm_packages