Module: PodUpdater

Defined in:
lib/podUpdater.rb,
lib/podUpdater/version.rb,
lib/podUpdater/pod_push.rb,
lib/podUpdater/git_tag_flow.rb,
lib/podUpdater/modify_podspec.rb

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.modifyPodspec(path: "", version: "0.0.0") ⇒ Object

修改podspec的s.verison的值



5
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
# 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) ⇒ Object

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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) ⇒ Object

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



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
# 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) ⇒ Object



14
15
16
17
# File 'lib/podUpdater.rb', line 14

def self.run(version)
	path = File.expand_path(Dir.pwd)		
	pushPodToSevice(path,version)
end

.sayHiObject



9
10
11
12
# File 'lib/podUpdater/pod_push.rb', line 9

def sayHi
	puts "heiehieheihehie"
	aPath = File.expand_path('./');puts "哈哈哈#{aPath}"
end

Instance Method Details

#git_tag_flow(path, msg, tag_version) ⇒ Object

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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