-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpodlockDependencyParse.rb
89 lines (71 loc) · 2.68 KB
/
podlockDependencyParse.rb
1
2
3
4
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
44
45
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
86
87
88
89
#用法,ruby podlockDependencyParse.rb /xx/xx/Podfile.lock 生成分析图,需要用到三方工具 graphviz,自行安装,推荐brew安装,不需要额外添加环境变量
#author 张恒 2021.10.12
class TyPodLib
attr_accessor:pod_name
attr_accessor:pod_dependencies
end
def parsePodfilelock
podLockFilePath = ARGV[0]
podArray = Array.new
File.open(podLockFilePath) do |file|
file.each_line do |line|
#主pod
if line.start_with?(" -")
podlib = TyPodLib.new
podlib.pod_dependencies = Array.new
podName = line.split(" ")[1].gsub("\n","")
podlib.pod_name = podName.split("/")[0].gsub("-","_").gsub("\"","")
podArray.push(podlib)
elsif line.start_with?(" -") #子pod依赖 (" -")
podlib = podArray[-1]
puts(line)
subpodName = line.split(" ")[1].gsub("\n","")
subpodName = subpodName.split("/")[0]
if subpodName != podlib.pod_name
podlib.pod_dependencies.push(subpodName.gsub("-","_").gsub("\"",""))
end
elsif line.start_with?("DEPENDENCIES:")
#结束扫描,后面的不需要了
break
end
end
end
generateImageData(podArray)
end
def generateImageData(arrayData)
dotMainArray = Array.new
dotRelateArray = Array.new
for podlib in arrayData
dotMainArray.push(podlib.pod_name + ";\n")
for podDepenency in podlib.pod_dependencies
dotRelateArray.push(podlib.pod_name + "->" + podDepenency + ";\n")
end
end
#去重处理
dotMainArray = dotMainArray.uniq()
dotRelateArray = dotRelateArray.uniq()
dotFileContent = "digraph dependencyRelation{\n"
for mainContent in dotMainArray
dotFileContent = dotFileContent + mainContent
end
for relateContent in dotRelateArray
dotFileContent = dotFileContent + relateContent
end
dotFileContent = dotFileContent + "}"
dotFilePath = __dir__ + "/" + "dependencyRelation.dot"
if !Dir.exists?(dotFilePath)
File.new(dotFilePath,'w')
end
File.open(dotFilePath, "w") do |f|
f.write(dotFileContent)
end
#dot 默认布局方式,主要用于有向图
#neato 基于spring-model(又称force-based)算法
#twopi 径向布局
#circo 圆环布局
#fdp 用于无向图
#需要修改展示样式的话,只需要把此句最前面做一下修改即可
generateImageCmdString = "fdp -Tpng dependencyRelation.dot -o dependencyRelation.png"
system(generateImageCmdString)
end
parsePodfilelock