Skip to content

Instantly share code, notes, and snippets.

@levicook
Forked from practicingruby/mooch.rb
Created February 14, 2010 15:21
Show Gist options
  • Save levicook/304090 to your computer and use it in GitHub Desktop.
Save levicook/304090 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "pathname"
LOADER = '''
require "pathname"
vendor_path = Pathname.new(__FILE__).parent.parent + "vendor"
Pathname.glob("#{vendor_path}/**/**/lib") do |lib|
next if $LOAD_PATH.include?(lib.realpath.to_s)
$LOAD_PATH.insert(0, lib.realpath.to_s) if lib.directory?
end
'''
if ARGV[0] == "init"
lib = Pathname.new(ARGV[1])
lib.mkpath
(lib + 'dependencies.rb').open("w") do |file|
file.write LOADER
end
else
vendor = Pathname.new("vendor")
vendor.mkpath
if File.exist?('.git') ## already using git?
system("git add vendor")
system("git submodule add git://github.com/#{ARGV[0]}.git vendor/#{ARGV[0]}")
else
Dir.chdir(vendor.realpath)
system("git clone git://github.com/#{ARGV[0]}.git #{ARGV[0]}")
if ARGV[1]
Dir.chdir(ARGV[0])
system("git checkout #{ARGV[1]}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment