Class: CableReady::Installer
- Inherits:
-
Object
- Object
- CableReady::Installer
- Includes:
- Thor::Actions, Thor::Base
- Defined in:
- lib/cable_ready/installer.rb
Class Method Summary collapse
- .action_cable_initializer_path ⇒ Object
- .action_cable_initializer_working_path ⇒ Object
- .add_dev_package(name) ⇒ Object
- .add_gem(name) ⇒ Object
- .add_gem_list ⇒ Object
- .add_package(name) ⇒ Object
- .append_file ⇒ Object
- .application_record_path ⇒ Object
- .backup(path, delete: false) ⇒ Object
- .backups_path ⇒ Object
- .bundler ⇒ Object
- .complete_step(step) ⇒ Object
- .config_path ⇒ Object
- .controllers_path ⇒ Object
- .copy_file ⇒ Object
-
.cr_npm_version ⇒ Object
memoized values.
-
.create_file ⇒ Object
Thor wrapper.
- .create_or_append(path, *args, &block) ⇒ Object
- .current_template ⇒ Object
- .dev_package_list ⇒ Object
- .development_path ⇒ Object
- .development_working_path ⇒ Object
- .drop_package(name) ⇒ Object
- .drop_package_list ⇒ Object
- .entrypoint ⇒ Object
-
.fetch(step_path, file) ⇒ Object
general utilities.
- .friendly_importmap_path ⇒ Object
- .friendly_pack_path ⇒ Object
- .gemfile ⇒ Object
- .gemfile_hash ⇒ Object
- .gemfile_path ⇒ Object
- .halt(message) ⇒ Object
- .importmap_path ⇒ Object
- .options ⇒ Object
- .options_path ⇒ Object
- .pack ⇒ Object
- .pack_path ⇒ Object
- .pack_path_missing? ⇒ Boolean
- .package_json ⇒ Object
- .package_list ⇒ Object
- .prefix ⇒ Object
- .remove_gem(name) ⇒ Object
- .remove_gem_list ⇒ Object
- .say ⇒ Object
- .template_src ⇒ Object
- .working ⇒ Object
Class Method Details
.action_cable_initializer_path ⇒ Object
211 212 213 |
# File 'lib/cable_ready/installer.rb', line 211 def self.action_cable_initializer_path @action_cable_initializer_path ||= Rails.root.join("config/initializers/action_cable.rb") end |
.action_cable_initializer_working_path ⇒ Object
215 216 217 |
# File 'lib/cable_ready/installer.rb', line 215 def self.action_cable_initializer_working_path @action_cable_initializer_working_path ||= Rails.root.join(working, "action_cable.rb") end |
.add_dev_package(name) ⇒ Object
107 108 109 110 |
# File 'lib/cable_ready/installer.rb', line 107 def self.add_dev_package(name) create_or_append(dev_package_list, "#{name}\n", verbose: false) say "☑️ Enqueued #{name} to be added to dev dependencies" end |
.add_gem(name) ⇒ Object
92 93 94 95 |
# File 'lib/cable_ready/installer.rb', line 92 def self.add_gem(name) create_or_append(add_gem_list, "#{name}\n", verbose: false) say "☑️ Added #{name} to the Gemfile" end |
.add_gem_list ⇒ Object
231 232 233 |
# File 'lib/cable_ready/installer.rb', line 231 def self.add_gem_list @add_gem_list ||= Rails.root.join("tmp/cable_ready_installer/add_gem_list") end |
.add_package(name) ⇒ Object
102 103 104 105 |
# File 'lib/cable_ready/installer.rb', line 102 def self.add_package(name) create_or_append(package_list, "#{name}\n", verbose: false) say "☑️ Enqueued #{name} to be added to dependencies" end |
.append_file ⇒ Object
18 19 20 |
# File 'lib/cable_ready/installer.rb', line 18 def self.append_file(...) new.append_file(...) end |
.application_record_path ⇒ Object
207 208 209 |
# File 'lib/cable_ready/installer.rb', line 207 def self.application_record_path @application_record_path ||= Rails.root.join("app/models/application_record.rb") end |
.backup(path, delete: false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cable_ready/installer.rb', line 62 def self.backup(path, delete: false) if !path.exist? yield return end backup_path = Pathname.new("#{path}.bak") old_path = path.relative_path_from(Rails.root).to_s filename = path.to_path.split("/").last if backup_path.exist? if backup_path.read == path.read path.delete if delete yield return end backup_path.delete end copy_file(path, backup_path, verbose: false) path.delete if delete yield if path.read != backup_path.read create_or_append(backups_path, "#{old_path}\n", verbose: false) end say "📦 #{old_path} backed up as #{filename}.bak" end |
.backups_path ⇒ Object
227 228 229 |
# File 'lib/cable_ready/installer.rb', line 227 def self.backups_path @backups_path ||= Rails.root.join("tmp/cable_ready_installer/backups") end |
.bundler ⇒ Object
135 136 137 |
# File 'lib/cable_ready/installer.rb', line 135 def self.bundler @bundler ||= File.read("tmp/cable_ready_installer/bundler") end |
.complete_step(step) ⇒ Object
39 40 41 |
# File 'lib/cable_ready/installer.rb', line 39 def self.complete_step(step) create_file "tmp/cable_ready_installer/#{step}", verbose: false end |
.config_path ⇒ Object
139 140 141 |
# File 'lib/cable_ready/installer.rb', line 139 def self.config_path @config_path ||= Rails.root.join(entrypoint, "config") end |
.controllers_path ⇒ Object
183 184 185 |
# File 'lib/cable_ready/installer.rb', line 183 def self.controllers_path @controllers_path ||= Rails.root.join(entrypoint, "controllers") end |
.copy_file ⇒ Object
22 23 24 |
# File 'lib/cable_ready/installer.rb', line 22 def self.copy_file(...) new.copy_file(...) end |
.cr_npm_version ⇒ Object
memoized values
123 124 125 |
# File 'lib/cable_ready/installer.rb', line 123 def self.cr_npm_version @cr_npm_version ||= CableReady::VERSION.gsub(".pre", "-pre") end |
.create_file ⇒ Object
Thor wrapper
14 15 16 |
# File 'lib/cable_ready/installer.rb', line 14 def self.create_file(...) new.create_file(...) end |
.create_or_append(path, *args, &block) ⇒ Object
43 44 45 46 |
# File 'lib/cable_ready/installer.rb', line 43 def self.create_or_append(path, *args, &block) FileUtils.touch(path) append_file(path, *args, &block) end |
.current_template ⇒ Object
48 49 50 |
# File 'lib/cable_ready/installer.rb', line 48 def self.current_template ENV["LOCATION"].split("/").last.gsub(".rb", "") end |
.dev_package_list ⇒ Object
171 172 173 |
# File 'lib/cable_ready/installer.rb', line 171 def self.dev_package_list @dev_package_list ||= Rails.root.join("tmp/cable_ready_installer/npm_dev_package_list") end |
.development_path ⇒ Object
219 220 221 |
# File 'lib/cable_ready/installer.rb', line 219 def self.development_path @development_path ||= Rails.root.join("config/environments/development.rb") end |
.development_working_path ⇒ Object
223 224 225 |
# File 'lib/cable_ready/installer.rb', line 223 def self.development_working_path @development_working_path ||= Rails.root.join(working, "development.rb") end |
.drop_package(name) ⇒ Object
112 113 114 115 |
# File 'lib/cable_ready/installer.rb', line 112 def self.drop_package(name) create_or_append(drop_package_list, "#{name}\n", verbose: false) say "❎ Enqueued #{name} to be removed from dependencies" end |
.drop_package_list ⇒ Object
175 176 177 |
# File 'lib/cable_ready/installer.rb', line 175 def self.drop_package_list @drop_package_list ||= Rails.root.join("tmp/cable_ready_installer/drop_npm_package_list") end |
.entrypoint ⇒ Object
131 132 133 |
# File 'lib/cable_ready/installer.rb', line 131 def self.entrypoint @entrypoint ||= File.read("tmp/cable_ready_installer/entrypoint") end |
.fetch(step_path, file) ⇒ Object
general utilities
32 33 34 35 36 37 |
# File 'lib/cable_ready/installer.rb', line 32 def self.fetch(step_path, file) relative_path = step_path + file location = template_src + relative_path Pathname.new(location) end |
.friendly_importmap_path ⇒ Object
147 148 149 |
# File 'lib/cable_ready/installer.rb', line 147 def self.friendly_importmap_path @friendly_importmap_path ||= importmap_path.relative_path_from(Rails.root).to_s end |
.friendly_pack_path ⇒ Object
155 156 157 |
# File 'lib/cable_ready/installer.rb', line 155 def self.friendly_pack_path @friendly_pack_path ||= pack_path.relative_path_from(Rails.root).to_s end |
.gemfile ⇒ Object
191 192 193 |
# File 'lib/cable_ready/installer.rb', line 191 def self.gemfile @gemfile ||= gemfile_path.read end |
.gemfile_hash ⇒ Object
117 118 119 |
# File 'lib/cable_ready/installer.rb', line 117 def self.gemfile_hash Digest::MD5.hexdigest(gemfile_path.read) end |
.gemfile_path ⇒ Object
187 188 189 |
# File 'lib/cable_ready/installer.rb', line 187 def self.gemfile_path @gemfile_path ||= Rails.root.join("Gemfile") end |
.halt(message) ⇒ Object
57 58 59 60 |
# File 'lib/cable_ready/installer.rb', line 57 def self.halt() say "❌ #{}", :red create_file "tmp/cable_ready_installer/halt", verbose: false end |
.importmap_path ⇒ Object
143 144 145 |
# File 'lib/cable_ready/installer.rb', line 143 def self.importmap_path @importmap_path ||= Rails.root.join("config/importmap.rb") end |
.options ⇒ Object
243 244 245 |
# File 'lib/cable_ready/installer.rb', line 243 def self. @options ||= YAML.safe_load(File.read()) end |
.options_path ⇒ Object
239 240 241 |
# File 'lib/cable_ready/installer.rb', line 239 def self. @options_path ||= Rails.root.join("tmp/cable_ready_installer/options") end |
.pack ⇒ Object
151 152 153 |
# File 'lib/cable_ready/installer.rb', line 151 def self.pack @pack ||= pack_path.read end |
.pack_path ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/cable_ready/installer.rb', line 159 def self.pack_path @pack_path ||= [ Rails.root.join(entrypoint, "application.js"), Rails.root.join(entrypoint, "packs/application.js"), Rails.root.join(entrypoint, "entrypoints/application.js") ].find(&:exist?) end |
.pack_path_missing? ⇒ Boolean
52 53 54 55 |
# File 'lib/cable_ready/installer.rb', line 52 def self.pack_path_missing? return false unless pack_path.nil? halt "#{friendly_pack_path} is missing. You need a valid application pack file to proceed." end |
.package_json ⇒ Object
127 128 129 |
# File 'lib/cable_ready/installer.rb', line 127 def self.package_json @package_json ||= Rails.root.join("package.json") end |
.package_list ⇒ Object
167 168 169 |
# File 'lib/cable_ready/installer.rb', line 167 def self.package_list @package_list ||= Rails.root.join("tmp/cable_ready_installer/npm_package_list") end |
.prefix ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/cable_ready/installer.rb', line 195 def self.prefix # standard:disable Style/RedundantStringEscape @prefix ||= { "vite" => "..\/", "webpacker" => "", "shakapacker" => "", "importmap" => "", "esbuild" => ".\/" }[bundler] # standard:enable Style/RedundantStringEscape end |
.remove_gem(name) ⇒ Object
97 98 99 100 |
# File 'lib/cable_ready/installer.rb', line 97 def self.remove_gem(name) create_or_append(remove_gem_list, "#{name}\n", verbose: false) say "❎ Removed #{name} from Gemfile" end |
.remove_gem_list ⇒ Object
235 236 237 |
# File 'lib/cable_ready/installer.rb', line 235 def self.remove_gem_list @remove_gem_list ||= Rails.root.join("tmp/cable_ready_installer/remove_gem_list") end |
.say ⇒ Object
26 27 28 |
# File 'lib/cable_ready/installer.rb', line 26 def self.say(...) new.say(...) end |
.template_src ⇒ Object
179 180 181 |
# File 'lib/cable_ready/installer.rb', line 179 def self.template_src @template_src ||= File.read("tmp/cable_ready_installer/template_src") end |
.working ⇒ Object
247 248 249 |
# File 'lib/cable_ready/installer.rb', line 247 def self.working @working ||= Rails.root.join("tmp/cable_ready_installer/working") end |