Last active
October 25, 2023 21:03
-
-
Save borama/4d52c4f97c918a363a1fc7019593bf86 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
This script will find out the age (date of release) of all gems in your project and print this out together with yearly summary stats. The format of both output parts usually obeys the CSV format so that you can paste it in your spreadsheet and make a chart of it.
Typical output:
See the article for more details.