Last active
March 1, 2020 07:13
-
-
Save neonichu/82849462714c5572eb2e to your computer and use it in GitHub Desktop.
A simple CocoaPods version manager.
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 'rubygems' | |
require 'yaml' | |
def install_gem(name, version) | |
require 'rubygems/commands/install_command' | |
cmd = Gem::Commands::InstallCommand.new | |
cmd.handle_options [name, '--version', version] | |
begin | |
cmd.execute | |
rescue Gem::SystemExitException => e | |
e.exit_code == 0 | |
end | |
end | |
if File.exist?('Podfile.lock') | |
lockfile = YAML.load(File.read('Podfile.lock')) | |
version = lockfile['COCOAPODS'] | |
begin | |
gem 'cocoapods', "=#{version}" | |
rescue Gem::LoadError | |
puts "Auto-installing CocoaPods #{version}" | |
exit(1) unless install_gem('cocoapods', version) | |
begin | |
gem 'cocoapods', "=#{version}" | |
rescue Gem::LoadError => message | |
STDERR.puts message | |
exit(1) | |
end | |
end | |
end | |
require 'cocoapods' | |
Pod::Command.run(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment