module Xcodebump
Constants
- VERSION
Public Class Methods
add_new_version_to_git(version)
click to toggle source
# File lib/xcodebump/git.rb, line 6 def self.add_new_version_to_git version d = Dir.exist? "#{Dir.pwd}/.git" commit_changes(version) if d add_tag(version) if d push_changes if d end
add_tag(version)
click to toggle source
# File lib/xcodebump/git.rb, line 18 def self.add_tag version `git tag -a #{version} -m #{version}` `git push --tags` end
blue(text)
click to toggle source
# File lib/xcodebump/colors.rb, line 16 def self.blue(text) colorize(text, 36) end
colorize(text, color_code)
click to toggle source
Main Colorize Functions
# File lib/xcodebump/colors.rb, line 3 def self.colorize(text, color_code) puts "\e[#{color_code}m#{text}\e[0m" end
commit_changes(version)
click to toggle source
# File lib/xcodebump/git.rb, line 13 def self.commit_changes version `git add .` `git commit -m 'Bump: #{version}'` end
green(text)
click to toggle source
# File lib/xcodebump/colors.rb, line 12 def self.green(text) colorize(text, 32) end
new_version_string(v, release, minor, patch)
click to toggle source
# File lib/xcodebump/plist.rb, line 67 def self.new_version_string v, release, minor, patch v_components = v.split('.') while v_components.size < 3 v_components << '0' end if release v_components[0] = (v_components[0].to_i + 1).to_s v_components[1] = '0' v_components[2] = '0' elsif minor v_components[1] = (v_components[1].to_i + 1).to_s v_components[2] = '0' elsif patch v_components[2] = (v_components[2].to_i + 1).to_s if patch end return v_components.join('.') end
purple(text)
click to toggle source
# File lib/xcodebump/colors.rb, line 20 def self.purple(text) colorize(text, 35) end
push_changes()
click to toggle source
# File lib/xcodebump/git.rb, line 23 def self.push_changes `git push` end
red(text)
click to toggle source
Specific Colors
# File lib/xcodebump/colors.rb, line 8 def self.red(text) colorize(text, 31) end
update_version_number(release, minor, patch, git)
click to toggle source
# File lib/xcodebump/plist.rb, line 6 def self.update_version_number release, minor, patch, git # Find Plist Paths plist_paths = [] Dir.glob(Dir.pwd + '/**/*.plist').each do |d| plist_paths << d if d.include? '-Info.plist' end Xcodebump::red "\n No Plist files found.\n\n Please run this from a directory where an Xcode Project/Workspace lives.\n" unless plist_paths.size > 0 return unless plist_paths.size > 0 # Ask User which one to Bump Xcodebump::blue "\n Please choose one of the follwing to bump the version number:" plist_paths.each_with_index do |p, i| components = p.split('/') puts " [#{i.to_s}] #{components[components.size - 1]}" end puts index = ask(" Plist to Modify? ") path = nil if plist_paths.size > index.to_i path = plist_paths[index.to_i] end return unless path # Edit Version Number plist_text = File.read path # Find Keys, bump them keys = ['CFBundleVersion','CFBundleShortVersionString'] new_version = '' keys.each do |k| matches = plist_text.match /<key>#{k}<\/key>\s*<(.*?)>.*<\/(.*?)>/ if matches key_start = "<string>" key_end = "</string>" v = matches[0][/#{key_start}(.*?)#{key_end}/m, 1] v_new = new_version_string v, release, minor, patch new_version = v_new replace_string = matches[0].sub(/<string>.*<\/string>/, "<string>#{v_new}</string>") plist_text = plist_text.gsub(matches[0], replace_string) else v = '0.0.0' v = new_version_string v, release, minor, patch plist_text = plist_text.sub(/<\/dict>\s*<\/plist>/, "<key>#{k}</key>\n<string>#{v}</string>\n</dict></plist>") end # Save File File.open(path, 'w') do |f| f.write plist_text end end # Write to Console components = path.split('/') plist = components[components.size - 1] Xcodebump::green "\n #{plist} updated to #{new_version}\n" # Save to Git Xcodebump::add_new_version_to_git new_version if git end