Skip to content

Commit

Permalink
Automate installation of Git submodules.
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Oct 11, 2009
1 parent c5372d8 commit d3df9ba
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions Rakefile
Expand Up @@ -18,6 +18,24 @@ module PrototypeHelper
%w[sprockets pdoc unittest_js caja_builder sizzle].each do |name|
$:.unshift File.join(PrototypeHelper::ROOT_DIR, 'vendor', name, 'lib')
end

def self.has_git?
begin
`git --version`
return true
rescue Error => e
return false
end
end

def self.require_git
return if has_git?
puts "\nPrototype requires Git in order to load its dependencies."
puts "\nMake sure you've got Git installed and in your path."
puts "\nFor more information, visit:\n\n"
puts " http://book.git-scm.com/2_installing_git.html"
exit
end

def self.sprocketize(path, source, destination = nil, strip_comments = true)
require_sprockets
Expand Down Expand Up @@ -66,25 +84,37 @@ module PrototypeHelper

def self.require_sizzle
if !File.exists?(File.join(SIZZLE_DIR, 'sizzle.js'))
puts "\nIt looks like you're missing Sizzle. Just run:\n\n"
puts " $ git submodule init"
puts " $ git submodule update"
puts "\nand you should be all set.\n\n"
exit
exit unless get_submodule("Sizzle", "sizzle")
end
end

def self.get_submodule(name, path)
require_git
puts "\nYou seem to be missing #{name}. Obtaining it via git...\n\n"

Kernel.system("git submodule init")
return true if Kernel.system("git submodule update vendor/#{path}")

# If we got this far, something went wrong.
puts "\nLooks like it didn't work. Try it manually:\n\n"
puts " $ git submodule init"
puts " $ git submodule update vendor/#{path}"
false
end

def self.require_submodule(name, path)
begin
require path
rescue LoadError => e
# Wait until we notice that a submodule is missing before we bother the
# user about installing git. (Maybe they brought all the files over
# from a different machine.)
missing_file = e.message.sub('no such file to load -- ', '')
if missing_file == path
puts "\nIt looks like you're missing #{name}. Just run:\n\n"
puts " $ git submodule init"
puts " $ git submodule update"
puts "\nand you should be all set.\n\n"
# Missing a git submodule.
retry if get_submodule(name, path)
else
# Missing a gem.
puts "\nIt looks like #{name} is missing the '#{missing_file}' gem. Just run:\n\n"
puts " $ gem install #{missing_file}"
puts "\nand you should be all set.\n\n"
Expand All @@ -94,8 +124,6 @@ module PrototypeHelper
end
end



task :default => [:dist, :dist_helper, :package, :clean_package_source]

desc "Builds the distribution."
Expand Down

1 comment on commit d3df9ba

@tobie
Copy link
Collaborator

@tobie tobie commented on d3df9ba Oct 11, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

Please sign in to comment.