module PodUpdater

Constants

VERSION

Public Class Methods

git_tag_flow(path,msg,tag_version) click to toggle source

提供路径,然后将项目打包上git,标记tag

# File lib/podUpdater/git_tag_flow.rb, line 5
def git_tag_flow(path,msg,tag_version)

        cmd = []

        cmd << %(cd #{path})
        cmd << 'git add .'
        cmd << %(git commit -m  "#{msg}")
        cmd << 'git push'
        cmd << %(git tag -a #{tag_version} -m "#{msg}")
        cmd << 'git push --tags'

        # TODO: 尝试在每次即将执行该命令时,打印出这次的命令
        IO.popen(cmd.join(" && ")) do |io|
                io.each do |line|
                        puts line
                end
                io.close
        end

end
modifyPodspec(path:"",version:"0.0.0") click to toggle source

修改podspec的s.verison的值

# File lib/podUpdater/modify_podspec.rb, line 5
def modifyPodspec(path:"",version:"0.0.0")

        if version == "0.0.0"
                puts "请指定版本好的值,如 modifyPodspec version:#{version}"
                return
        end
        unless version =~ /^\d{1,}.\d.\d$|^\d{1,}.\d$|^\d{1,}$/
                puts "version:#{version}的格式不对"
                return 
        end

        # DEBUG:这里写死了路径是为了方便调试,正式用的话需去掉
        # path = "/Users/qwkj/Documents/WZ_GitHub/Ruby_Learning/day_7/QW_Http.podspec"
        # END

        unless File.exist?path
                puts "路径不存在"
                return
        end

        puts "***修改podspec文件***"
        File.open(path, "r+") do |f|
                s = ""
                f.each_line do |line|
                        # puts "#{line}"
                        if line.to_s =~ /s\.version\s*=\s*"(\d{1,}.\d.\d|\d{1,}.\d|\d{1,})"/
                                # puts "匹配到了"
                                temp = $1.to_s
                                line = line.sub(/\d{1,}.\d.\d|\d{1,}.\d|\d{1,}/) do |match| 
                                        version.to_s
                                end
                        end
                        s += line
                end
                puts "#{s}"
                File.open(path, "w+") do |f| f.write(s) end
        end   
        
end
pathWithPodspecSuffix(path) click to toggle source

找到指定路径下的podspec文件名

# File lib/podUpdater/modify_podspec.rb, line 46
def pathWithPodspecSuffix(path)

        # path = "/Users/qwkj/Desktop/IOS_Pod_Spec_Repo/千网PodRepo/QWCrashReporter/1.0.8/"
        path = File.expand_path(path)
        return nil unless File.exist?(path)

        unless path =~ /.podspec$/

                if File.directory?(path)
                        podfiles = Dir.glob("#{path}/*.podspec")
                        puts "#{podfiles}"
                        if podfiles.length == 0
                                puts %('#{path}'下无法找到'.podspec'文件)
                                return nil
                        elsif podfiles.length == 1
                                path = podfiles.first
                        else
                                puts "目录下找到多个podspec文件!"
                                podfiles.each_with_index do |elem, index|
                                        basename = File.basename(elem)
                                        puts %(#{index}.#{basename} )
                                end
                                puts "请指定您当前需要的操作的文件,输入它的序号:"
                                i = gets.to_i

                                case i
                                when 0 .. (podfiles.length-1)
                                        path = podfiles[i.to_i]   
                                else
                                        puts "输入错误❌"
                                        path = nil
                                end
                                
                        end
                end
        end

        path

end
pushPodToSevice(path,version) click to toggle source

给定pod库项目的路径,以及新版pod库的版本,将自己的pod提交到git,然后打上tag,再push trunk到pod服务器去

# File lib/podUpdater/pod_push.rb, line 14
def pushPodToSevice(path,version)
        # FOR_DEBUG:
        # path = "/Users/qwkj/Documents/WZ_GitHub/WZ_Framework"
        # END

        podFilePath = pathWithPodspecSuffix(path)

        unless podFilePath 
                puts "未找到相应的podspec文件"
                return
        end

        msg = "for pod version:#{version}"

        modifyPodspec(path:podFilePath,version:version)

        git_tag_flow(path,msg,version)

        cmd = []
        cmd << %(pod trunk push #{podFilePath} --allow-warnings)

        IO.popen(cmd.join('')) do |io|
                io.each do |line|
                        puts line
                end
        end
        
end
run(version) click to toggle source
# File lib/podUpdater.rb, line 11
def self.run(version)
        path = File.expand_path(Dir.pwd)              
        pushPodToSevice(path,version)
end
sayHi() click to toggle source
# File lib/podUpdater/pod_push.rb, line 9
def sayHi
        puts "heiehieheihehie"
        aPath = File.expand_path('./');puts "哈哈哈#{aPath}"
end

Private Instance Methods

git_tag_flow(path,msg,tag_version) click to toggle source

提供路径,然后将项目打包上git,标记tag

# File lib/podUpdater/git_tag_flow.rb, line 5
def git_tag_flow(path,msg,tag_version)

        cmd = []

        cmd << %(cd #{path})
        cmd << 'git add .'
        cmd << %(git commit -m  "#{msg}")
        cmd << 'git push'
        cmd << %(git tag -a #{tag_version} -m "#{msg}")
        cmd << 'git push --tags'

        # TODO: 尝试在每次即将执行该命令时,打印出这次的命令
        IO.popen(cmd.join(" && ")) do |io|
                io.each do |line|
                        puts line
                end
                io.close
        end

end
modifyPodspec(path:"",version:"0.0.0") click to toggle source

修改podspec的s.verison的值

# File lib/podUpdater/modify_podspec.rb, line 5
def modifyPodspec(path:"",version:"0.0.0")

        if version == "0.0.0"
                puts "请指定版本好的值,如 modifyPodspec version:#{version}"
                return
        end
        unless version =~ /^\d{1,}.\d.\d$|^\d{1,}.\d$|^\d{1,}$/
                puts "version:#{version}的格式不对"
                return 
        end

        # DEBUG:这里写死了路径是为了方便调试,正式用的话需去掉
        # path = "/Users/qwkj/Documents/WZ_GitHub/Ruby_Learning/day_7/QW_Http.podspec"
        # END

        unless File.exist?path
                puts "路径不存在"
                return
        end

        puts "***修改podspec文件***"
        File.open(path, "r+") do |f|
                s = ""
                f.each_line do |line|
                        # puts "#{line}"
                        if line.to_s =~ /s\.version\s*=\s*"(\d{1,}.\d.\d|\d{1,}.\d|\d{1,})"/
                                # puts "匹配到了"
                                temp = $1.to_s
                                line = line.sub(/\d{1,}.\d.\d|\d{1,}.\d|\d{1,}/) do |match| 
                                        version.to_s
                                end
                        end
                        s += line
                end
                puts "#{s}"
                File.open(path, "w+") do |f| f.write(s) end
        end   
        
end
pathWithPodspecSuffix(path) click to toggle source

找到指定路径下的podspec文件名

# File lib/podUpdater/modify_podspec.rb, line 46
def pathWithPodspecSuffix(path)

        # path = "/Users/qwkj/Desktop/IOS_Pod_Spec_Repo/千网PodRepo/QWCrashReporter/1.0.8/"
        path = File.expand_path(path)
        return nil unless File.exist?(path)

        unless path =~ /.podspec$/

                if File.directory?(path)
                        podfiles = Dir.glob("#{path}/*.podspec")
                        puts "#{podfiles}"
                        if podfiles.length == 0
                                puts %('#{path}'下无法找到'.podspec'文件)
                                return nil
                        elsif podfiles.length == 1
                                path = podfiles.first
                        else
                                puts "目录下找到多个podspec文件!"
                                podfiles.each_with_index do |elem, index|
                                        basename = File.basename(elem)
                                        puts %(#{index}.#{basename} )
                                end
                                puts "请指定您当前需要的操作的文件,输入它的序号:"
                                i = gets.to_i

                                case i
                                when 0 .. (podfiles.length-1)
                                        path = podfiles[i.to_i]   
                                else
                                        puts "输入错误❌"
                                        path = nil
                                end
                                
                        end
                end
        end

        path

end
pushPodToSevice(path,version) click to toggle source

给定pod库项目的路径,以及新版pod库的版本,将自己的pod提交到git,然后打上tag,再push trunk到pod服务器去

# File lib/podUpdater/pod_push.rb, line 14
def pushPodToSevice(path,version)
        # FOR_DEBUG:
        # path = "/Users/qwkj/Documents/WZ_GitHub/WZ_Framework"
        # END

        podFilePath = pathWithPodspecSuffix(path)

        unless podFilePath 
                puts "未找到相应的podspec文件"
                return
        end

        msg = "for pod version:#{version}"

        modifyPodspec(path:podFilePath,version:version)

        git_tag_flow(path,msg,version)

        cmd = []
        cmd << %(pod trunk push #{podFilePath} --allow-warnings)

        IO.popen(cmd.join('')) do |io|
                io.each do |line|
                        puts line
                end
        end
        
end
sayHi() click to toggle source
# File lib/podUpdater/pod_push.rb, line 9
def sayHi
        puts "heiehieheihehie"
        aPath = File.expand_path('./');puts "哈哈哈#{aPath}"
end