Class: Jets::Commands::Upgrade::Version1
- Inherits:
-
Object
- Object
- Jets::Commands::Upgrade::Version1
- Defined in:
- lib/jets/commands/upgrade/version1.rb
Instance Method Summary collapse
- #add_dynomite_to_gemfile ⇒ Object
- #environment_configs ⇒ Object
- #remove_ruby_lazy_load ⇒ Object
- #remove_ruby_lazy_load_for(path) ⇒ Object
- #run ⇒ Object
- #update_config_ru ⇒ Object
- #update_mode_setting ⇒ Object
- #update_routes ⇒ Object
- #update_webpack_binstubs ⇒ Object
Instance Method Details
#add_dynomite_to_gemfile ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/jets/commands/upgrade/version1.rb', line 113 def add_dynomite_to_gemfile return unless File.exist?("app/models/application_item.rb") lines = IO.readlines("Gemfile") dynomite_found = lines.detect { |l| l =~ /dynomite/ } return if dynomite_found File.open('Gemfile', 'a') do |f| f.puts 'gem "dynomite"' end puts "Updated Gemfile: add dynomite gem" end |
#environment_configs ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jets/commands/upgrade/version1.rb', line 13 def environment_configs path = File.("templates/skeleton/config/environments", File.dirname(__FILE__)) Dir.glob("#{path}/*").each do |src| config_file = "config/environments/#{File.basename(src)}" dest = "#{Jets.root}/#{config_file}" puts "src #{src}" puts "dest #{dest}" unless File.exist?(dest) puts "Create: #{config_file}" FileUtils.mkdir_p(File.dirname(dest)) FileUtils.cp(src, dest) end end end |
#remove_ruby_lazy_load ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/jets/commands/upgrade/version1.rb', line 82 def remove_ruby_lazy_load app_config = "#{Jets.root}/config/application.rb" remove_ruby_lazy_load_for(app_config) Dir.glob("#{Jets.root}/config/environments/*.rb").each do |env_config| remove_ruby_lazy_load_for(env_config) end end |
#remove_ruby_lazy_load_for(path) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jets/commands/upgrade/version1.rb', line 90 def remove_ruby_lazy_load_for(path) lines = IO.readlines(path) new_lines = lines.reject do |l| l =~ %r{config.ruby.lazy_load} end return unless lines != new_lines content = new_lines.join("") IO.write(path, content) puts "Update: #{path}" end |
#run ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/jets/commands/upgrade/version1.rb', line 3 def run environment_configs update_routes update_mode_setting update_config_ru remove_ruby_lazy_load update_webpack_binstubs add_dynomite_to_gemfile end |
#update_config_ru ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jets/commands/upgrade/version1.rb', line 70 def update_config_ru src = "#{Jets.root}/config.ru" return unless File.exist?(src) config_ru = File.read(src) return if config_ru.include?("Jets.boot") src = File.("templates/skeleton/config.ru", File.dirname(__FILE__)) dest = src puts "Update: config.ru" FileUtils.cp(src, dest) end |
#update_mode_setting ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/jets/commands/upgrade/version1.rb', line 50 def update_mode_setting application_file = "#{Jets.root}/config/application.rb" lines = IO.readlines(application_file) deprecated_code = 'config.api_generator' return unless lines.detect { |l| l.include?(deprecated_code) } puts "Update: config/application.rb" lines.map! do |line| if line.include?(deprecated_code) mode = Jets.config.api_generator ? 'api' : 'html' %Q| config.mode = "#{mode}"\n| # assume 2 spaces for simplicity else line end end content = lines.join IO.write(application_file, content) end |
#update_routes ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jets/commands/upgrade/version1.rb', line 29 def update_routes routes_file = "#{Jets.root}/config/routes.rb" return unless File.exist?(routes_file) lines = IO.readlines(routes_file) deprecated_code = 'root "jets/welcome#index"' return unless lines.detect { |l| l.include?(deprecated_code) } puts "Update: config/routes.rb" lines.map! do |line| if line.include?(deprecated_code) %Q| root "jets/public#show"\n| # assume 2 spaces for simplicity else line end end content = lines.join IO.write(routes_file, content) end |
#update_webpack_binstubs ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/jets/commands/upgrade/version1.rb', line 102 def update_webpack_binstubs return unless File.exist?("bin/webpack") lines = IO.readlines("bin/webpack") already_upgraded = lines.detect { |l| l =~ /WebpackRunner/ } return if already_upgraded update_project_file("bin/webpack") update_project_file("bin/webpack-dev-server") puts "Updated webpack binstubs." end |