26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/xcbump.rb', line 26
def bump_version(version_type)
file_path = File.join(Dir.pwd, project_name, "#{project_name}-Info.plist")
info_plist = Plist::parse_xml(file_path)
current_version_string = info_plist['CFBundleShortVersionString']
current_build_string = info_plist['CFBundleVersion']
puts "Current version: #{current_version_string} (#{current_build_string})"
case version_type
when :major
version_index = 0
when :minor
version_index = 1
when :patch
version_index = 2
else
version_index = 3
end
current_build = current_build_string.split('.').map(&:to_i)
new_build = []
current_build.each_index do |index|
current_number = current_build[index]
if index < version_index
new_number = current_number
elsif index > version_index
new_number = 0
else
new_number = current_number + 1
end
new_build[index] = new_number
end
new_version_string = new_build[0..-2].join('.')
new_build_string = new_build.join('.')
info_plist['CFBundleShortVersionString'] = new_version_string
info_plist['CFBundleVersion'] = new_build_string
puts "New version: #{new_version_string} (#{new_build_string})"
File.write(file_path, info_plist.to_plist)
end
|