Module: Xcodebump
- Defined in:
- lib/xcodebump.rb,
lib/xcodebump/git.rb,
lib/xcodebump/plist.rb,
lib/xcodebump/colors.rb,
lib/xcodebump/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Class Method Summary collapse
- .add_new_version_to_git(version) ⇒ Object
- .add_tag(version) ⇒ Object
- .blue(text) ⇒ Object
-
.colorize(text, color_code) ⇒ Object
Main Colorize Functions.
- .commit_changes(version) ⇒ Object
- .green(text) ⇒ Object
- .new_version_string(v, release, minor, patch) ⇒ Object
- .purple(text) ⇒ Object
- .push_changes ⇒ Object
-
.red(text) ⇒ Object
Specific Colors.
- .update_version_number(release, minor, patch, git) ⇒ Object
Class Method Details
.add_new_version_to_git(version) ⇒ Object
6 7 8 9 10 11 |
# 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) ⇒ Object
18 19 20 21 |
# File 'lib/xcodebump/git.rb', line 18 def self.add_tag version `git tag -a #{version} -m #{version}` `git push --tags` end |
.blue(text) ⇒ Object
16 17 18 |
# File 'lib/xcodebump/colors.rb', line 16 def self.blue(text) colorize(text, 36) end |
.colorize(text, color_code) ⇒ Object
Main Colorize Functions
3 4 5 |
# 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) ⇒ Object
13 14 15 16 |
# File 'lib/xcodebump/git.rb', line 13 def self.commit_changes version `git add .` `git commit -m 'Bump: #{version}'` end |
.green(text) ⇒ Object
12 13 14 |
# File 'lib/xcodebump/colors.rb', line 12 def self.green(text) colorize(text, 32) end |
.new_version_string(v, release, minor, patch) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# 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 v_components[0] = (v_components[0].to_i + 1).to_s if release v_components[1] = (v_components[1].to_i + 1).to_s if minor v_components[2] = (v_components[2].to_i + 1).to_s if patch return v_components.join('.') end |
.purple(text) ⇒ Object
20 21 22 |
# File 'lib/xcodebump/colors.rb', line 20 def self.purple(text) colorize(text, 35) end |
.push_changes ⇒ Object
23 24 25 |
# File 'lib/xcodebump/git.rb', line 23 def self.push_changes `git push` end |
.red(text) ⇒ Object
Specific Colors
8 9 10 |
# File 'lib/xcodebump/colors.rb', line 8 def self.red(text) colorize(text, 31) end |
.update_version_number(release, minor, patch, git) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 |
# 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 |