Class: DepUpgrade::Command
- Inherits:
-
Object
- Object
- DepUpgrade::Command
- Defined in:
- lib/dep_upgrade/command.rb
Instance Attribute Summary collapse
-
#bundler_audit_output ⇒ Object
Returns the value of attribute bundler_audit_output.
-
#bundler_outdated_output ⇒ Object
Returns the value of attribute bundler_outdated_output.
-
#yarn_outdated_output ⇒ Object
Returns the value of attribute yarn_outdated_output.
Instance Method Summary collapse
- #bundle_audit ⇒ Object
- #bundle_audit_update ⇒ Object
- #bundle_outdated ⇒ Object
- #bundle_update ⇒ Object
- #call ⇒ Object
- #detect_dependency_files ⇒ Object
- #has_gemfile? ⇒ Boolean
- #has_package_json? ⇒ Boolean
- #print_bundle_audit_summary ⇒ Object
- #print_bundle_update_summary ⇒ Object
- #print_summary ⇒ Object
- #print_yarn_upgrade_summary ⇒ Object
- #system!(*args) ⇒ Object
- #yarn_outdated ⇒ Object
- #yarn_upgrade ⇒ Object
Instance Attribute Details
#bundler_audit_output ⇒ Object
Returns the value of attribute bundler_audit_output.
8 9 10 |
# File 'lib/dep_upgrade/command.rb', line 8 def bundler_audit_output @bundler_audit_output end |
#bundler_outdated_output ⇒ Object
Returns the value of attribute bundler_outdated_output.
8 9 10 |
# File 'lib/dep_upgrade/command.rb', line 8 def bundler_outdated_output @bundler_outdated_output end |
#yarn_outdated_output ⇒ Object
Returns the value of attribute yarn_outdated_output.
8 9 10 |
# File 'lib/dep_upgrade/command.rb', line 8 def yarn_outdated_output @yarn_outdated_output end |
Instance Method Details
#bundle_audit ⇒ Object
77 78 79 80 81 82 83 |
# 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 ⇒ Object
70 71 72 73 74 75 |
# 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 ⇒ Object
46 47 48 49 50 51 52 |
# 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 ⇒ Object
63 64 65 66 67 68 |
# 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 ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
25 26 27 28 29 30 31 32 |
# 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? ⇒ Boolean
34 35 36 |
# File 'lib/dep_upgrade/command.rb', line 34 def has_gemfile? @_has_gemfile end |
#has_package_json? ⇒ Boolean
38 39 40 |
# File 'lib/dep_upgrade/command.rb', line 38 def has_package_json? @_has_package_json end |
#print_bundle_audit_summary ⇒ Object
137 138 139 140 141 142 |
# 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 ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# 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 ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# 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 ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# 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) ⇒ Object
42 43 44 |
# File 'lib/dep_upgrade/command.rb', line 42 def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end |
#yarn_outdated ⇒ Object
54 55 56 57 58 59 60 61 |
# 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 ⇒ Object
85 86 87 88 89 90 |
# 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 |