-
-
Save hmistry/29a79b5d9f3d5422618cb2a368016041 to your computer and use it in GitHub Desktop.
A script that collects and prints info about the age of all ruby gems in your project, see https://dev.to/borama/how-old-are-dependencies-in-your-ruby-project-3jia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
# | |
# Collects info about the age of all gems in the project | |
# | |
require "json" | |
require "date" | |
bundle = `bundle list` | |
yearly_stats = {} | |
bundle.split(/\n/).each do |line| | |
next unless line =~ /\s+\*\s+[^ ]+\s+\(.*\)/ | |
gem_name, gem_version = /\s+\*\s+([^ ]+)\s+\((.*)\)/.match(line).to_a[1..-1] | |
begin | |
gem_json = `curl -s https://rubygems.org/api/v2/rubygems/#{gem_name}/versions/#{gem_version}.json` | |
built_at = JSON.parse(gem_json)["built_at"] | |
release_date = Date.parse(built_at).to_date | |
puts "#{gem_name},#{gem_version},#{release_date.strftime("%Y-%m-%d")}" | |
release_year = release_date.strftime("%Y") | |
yearly_stats[release_year] ||= { count: 0, gems: [] } | |
yearly_stats[release_year][:count] += 1 | |
yearly_stats[release_year][:gems] << gem_name | |
rescue => e | |
puts "#{gem_name},#{gem_version},???" | |
end | |
end | |
puts | |
puts "Yearly summary:" | |
yearly_stats.sort.each do |year, data| | |
puts "#{year},#{data[:count]},#{data[:gems].join(' ')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment