Skip to content

Instantly share code, notes, and snippets.

@radiospiel
Created March 9, 2012 22:39
Show Gist options
  • Save radiospiel/2009088 to your computer and use it in GitHub Desktop.
Save radiospiel/2009088 to your computer and use it in GitHub Desktop.
File to update local CocoaPod
#!/usr/bin/env ruby
require "fileutils"
SCRIPT = File.basename(__FILE__)
DIR = File.expand_path File.dirname(__FILE__)
LOCAL_PODS = File.expand_path "~/CocoaPods/Local"
HEAD = `git log -1 --pretty=%H`.chomp
def git(*args)
Dir.chdir(LOCAL_PODS) do |path|
STDERR.puts "git #{args.join(" ")}"
system("git", *args)
end
end
Dir.glob("#{DIR}/*.podspec").each do |file|
spec = File.read(file)
# get version string
if spec =~ /\n[^#]*\.version\s*=\s*(\S+)/
version = eval($1) # Note: version is a ruby string
else
raise "Missing version number"
end
# adjust specs to point to local repository
spec = spec.gsub(/\n([^#]*)\.source\s*=.*\n/) do |source|
"#{$1}.source = { :git => '#{DIR}', :commit => '#{HEAD}' }\n"
end
# write adjusted spec file
basename = File.basename(file)
basename_wo_ext = basename.gsub(/\..*/, "")
target_dir = "#{LOCAL_PODS}/#{basename_wo_ext}/#{version}"
FileUtils.mkdir_p(target_dir)
File.open("#{target_dir}/#{basename}", "w") do |file|
file.write spec
end
git "add", "#{target_dir}/#{basename}"
end
git "commit", "-m", "autocommit by #{SCRIPT}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment