class Object
Public Instance Methods
add(name, version)
click to toggle source
TODO:
# File lib/nver.rb, line 23 def add(name, version) end
android_platform?()
click to toggle source
# File lib/nver.rb, line 33 def android_platform? File.file?('./app/gradle.properties') end
bump_version_with_log(file_contents, reg_exp, dep_name, seperator, &gsub_proc)
click to toggle source
Version
# File lib/nver.rb, line 97 def bump_version_with_log(file_contents, reg_exp, dep_name, seperator, &gsub_proc) old_version = extract_version(file_contents, reg_exp, seperator) new_file_contents = gsub_proc.call new_version = extract_version(new_file_contents, reg_exp, seperator) if old_version != new_version puts "==> 升级【#{dep_name}】: #{old_version} => #{new_version}." end new_file_contents end
extract_version(text, reg_exp, seperator)
click to toggle source
# File lib/nver.rb, line 107 def extract_version(text, reg_exp, seperator) matches = text.match(reg_exp) arr = matches.to_s.split(seperator) version = arr[1] if !version raise "==> Failed to extract version for regExp #{reg_exp}." end version.strip; end
ios_platform?()
click to toggle source
Platform
# File lib/nver.rb, line 29 def ios_platform? File.file?('./Podfile') end
update(name, version)
click to toggle source
# File lib/nver.rb, line 13 def update(name, version) update_hash = update_platform_hash(name, version) if update_hash update_with_reg_exp(name, update_hash) else puts "目录错误,请选择正确工程目录执行命令" end end
update_file_with_proc(file_name, &update_proc)
click to toggle source
# File lib/nver.rb, line 89 def update_file_with_proc(file_name, &update_proc) contents = File.read(file_name) new_contents = update_proc.call(contents) File.open(file_name, 'w') { |file| file.puts new_contents } end
update_platform_hash(name, version)
click to toggle source
# File lib/nver.rb, line 56 def update_platform_hash(name, version) if ios_platform? { :file_name => './Podfile', :reg_exp => /'#{name}',\s?'\d+.\d+.\d+'/, :substitute => "'#{name}', '#{version}'", :seperator => ',', } elsif android_platform? { :file_name => './config/dependency/rndependencies.gradle', :reg_exp => /#{name}:\d+.\d+.\d+/, :substitute => "#{name}:#{version}", :seperator => ':', } else end end
update_with_reg_exp(module_name, hash)
click to toggle source
File
# File lib/nver.rb, line 77 def update_with_reg_exp(module_name, hash) file = hash[:file_name] reg_exp = hash[:reg_exp] substitute = hash[:substitute] seperator = hash[:seperator] update_file_with_proc(file) do |contents| bump_version_with_log(contents, reg_exp, module_name, seperator) do contents.gsub(reg_exp, substitute) end end end
version(version)
click to toggle source
Public
# File lib/nver.rb, line 4 def version(version) version_hash = version_platform_hash(version) if version_hash update_with_reg_exp('app', version_hash) else puts "目录错误,请选择正确工程目录执行命令" end end
version_platform_hash(version)
click to toggle source
# File lib/nver.rb, line 37 def version_platform_hash(version) if ios_platform? { :file_name => './dfc_v2/appconfig/BaseKeys.xcconfig', :reg_exp => /APP_VERSION\s=\s\d+.\d+.\d+/, :substitute => "APP_VERSION = #{version}", :seperator => '=', } elsif android_platform? { :file_name => './app/gradle.properties', :reg_exp => /VERSION_NAME=\d+.\d+.\d+/, :substitute => "VERSION_NAME=#{version}", :seperator => '=', } else end end