class DepUpgrade::Command
Attributes
bundler_audit_output[RW]
bundler_outdated_output[RW]
yarn_outdated_output[RW]
Public Instance Methods
bundle_audit()
click to toggle source
# File lib/dep_upgrade/command.rb, line 77 def bundle_audit return unless has_gemfile? puts "\n== Audit all gems ==" self.bundler_audit_output = `bundle exec bundle audit`.strip puts "Done." end
bundle_audit_update()
click to toggle source
# File lib/dep_upgrade/command.rb, line 70 def bundle_audit_update return unless has_gemfile? puts "\n== Update gems advisory database ==" system!("bundle exec bundle audit update") end
bundle_outdated()
click to toggle source
# File lib/dep_upgrade/command.rb, line 46 def bundle_outdated return unless has_gemfile? puts "\n== Analyze outdated gems ==" self.bundler_outdated_output = `bundle outdated --strict --parseable` puts "Done." end
bundle_update()
click to toggle source
# File lib/dep_upgrade/command.rb, line 63 def bundle_update return unless has_gemfile? puts "\n== Update all gems ==" system!("bundle update") end
call()
click to toggle source
# File lib/dep_upgrade/command.rb, line 11 def call detect_dependency_files bundle_outdated yarn_outdated bundle_update bundle_audit_update bundle_audit yarn_upgrade print_summary end
detect_dependency_files()
click to toggle source
# File lib/dep_upgrade/command.rb, line 25 def detect_dependency_files puts "\n== Detect dependency config files ==" @_has_gemfile = File.exist?("Gemfile") @_has_package_json = File.exist?("package.json") puts "Gemfile#{ " not" unless has_gemfile? } found." puts "package.json#{ " not" unless has_package_json? } found." end
has_gemfile?()
click to toggle source
# File lib/dep_upgrade/command.rb, line 34 def has_gemfile? @_has_gemfile end
has_package_json?()
click to toggle source
# File lib/dep_upgrade/command.rb, line 38 def has_package_json? @_has_package_json end
print_bundle_audit_summary()
click to toggle source
# File lib/dep_upgrade/command.rb, line 137 def print_bundle_audit_summary return unless has_gemfile? puts "\nbundle audit:" puts self.bundler_audit_output end
print_bundle_update_summary()
click to toggle source
# File lib/dep_upgrade/command.rb, line 104 def print_bundle_update_summary return unless has_gemfile? puts "\nbundle update:" self.bundler_outdated_output .split("\n") .reject { |line| line.empty? } .map do |line| line.match( /(?<name>[^ ]+) \(newest (?<to>[^,]+), installed (?<from>[^),]+)/ )&.named_captures end .compact .map do |gem| "#{gem['name']} [(#{gem['from']} -> #{gem['to']})]" \ "(https://rubygems.org/gems/#{gem['name']}/versions/#{gem['to']})" end .each { |line| puts "* #{line}" } end
print_summary()
click to toggle source
# File lib/dep_upgrade/command.rb, line 92 def print_summary puts "\nPaste this summary into your pull/merge request " \ "(chore-dep_upgrade_#{Date.today.strftime("%Y%m%d")}):" puts "-----" puts "\n## Dep Upgrade #{Date.today}" print_bundle_update_summary print_bundle_audit_summary print_yarn_upgrade_summary end
print_yarn_upgrade_summary()
click to toggle source
# File lib/dep_upgrade/command.rb, line 124 def print_yarn_upgrade_summary return unless has_package_json? puts "\nyarn upgrade:" self.yarn_outdated_output["data"]["body"] .select { |package| package[1] != package[2] } # Current != Wanted .map do |package| "#{package[0]} [(#{package[1]} -> #{package[2]})]" \ "(https://www.npmjs.com/package/#{package[0]}/v/#{package[2]})" end .each { |line| puts "* #{line}" } end
system!(*args)
click to toggle source
# File lib/dep_upgrade/command.rb, line 42 def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end
yarn_outdated()
click to toggle source
# File lib/dep_upgrade/command.rb, line 54 def yarn_outdated return unless has_package_json? puts "\n== Analyze outdated yarn packages ==" self.yarn_outdated_output = JSON .parse(`yarn outdated --json`.split("\n").last) puts "Done." end
yarn_upgrade()
click to toggle source
# File lib/dep_upgrade/command.rb, line 85 def yarn_upgrade return unless has_package_json? puts "\n== Update all yarn packages ==" system!("yarn upgrade") end