Last active
June 3, 2016 15:40
-
-
Save mmrwoods/8537698 to your computer and use it in GitHub Desktop.
Hacky script to show bundled dependencies of rails app
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
#!/usr/bin/env ruby | |
require 'bundler' | |
require 'hirb' | |
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 | |
if $stdout.tty? | |
# dump a pretty table | |
extend Hirb::Console | |
table dependencies, :fields => [:name, :version, :source, :url] | |
else | |
# 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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment