Created
October 12, 2020 12:10
-
-
Save skatkov/e32f3f491665d2d4d570f9576abd1f0e to your computer and use it in GitHub Desktop.
extract Ruby dependencies
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'bundler' | |
require 'csv' | |
lock_file = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock")) | |
def url_for(spec) | |
case spec.source | |
when Bundler::Source::Rubygems | |
"http://rubygems.org/gems/#{spec.name}" | |
when Bundler::Source::Git | |
if spec.source.uri.include? "github.com" | |
"https:" + spec.source.uri.sub(/^\w+:/,'').sub(/\.git$/,'') | |
else | |
spec.source.uri | |
end | |
end | |
end | |
dependencies = lock_file.specs.sort_by{|spec| spec.name}.map do |spec| | |
{ | |
name: spec.name, | |
version: spec.version.to_s, | |
source: spec.source.class.to_s.split("::").last, | |
url: url_for(spec) | |
} | |
end | |
# dump tp csv | |
puts CSV.generate_line %w{ Name Version Source Url } | |
dependencies.each do |d| | |
puts CSV.generate_line [ d[:name], d[:version], d[:source], d[:url] ] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment