Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
iOSプロジェクトの全ターゲットのバージョンを一気に上げる http://blog.hoppenichu.com/objective-c/219
#!/usr/bin/env ruby
require 'xcodeproj'
require 'plist'
class UpdateVersionManager
def initialize
path = File.expand_path("#{__dir__}/../") # absolute path to your project file
projects = Xcodeproj::Project.open(*Dir.glob("#{path}/*.xcodeproj"))
@base_path = path
@projects = projects
end
def update_plist_verion(version, number_version)
unless number_version
number_version = self.class.convert_version_to_number(version)
end
@projects.targets.each do |target|
next if target.product_type == 'com.apple.product-type.bundle.unit-test'
target.build_configurations.each do |configuration|
plist_path = configuration.build_settings['INFOPLIST_FILE']
plist_path = "#{@base_path}/#{plist_path}"
data = Plist.parse_xml(plist_path)
data['CFBundleVersion'] = number_version
data['CFBundleShortVersionString'] = version
Plist::Emit.save_plist(data, plist_path)
end
end
end
def self.convert_version_to_number(version)
# in case of Sumally
array = version.split('.')
(3 - array.length).times do
array.push('0')
end
array.join
end
end
unless ARGV[0]
print(<<'EOS')
Usage: update_versions.rb [CFBundleShortVersionString] ([CFBundleVersion])
Example: update_versions.rb 7.2.0 721
EOS
exit
end
if __FILE__ == $PROGRAM_NAME
manager = UpdateVersionManager.new
manager.update_plist_verion(ARGV[0], ARGV[1])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment