-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfindXibUse.rb
54 lines (41 loc) · 1.5 KB
/
findXibUse.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
def findXibs
projectName = File.basename(Dir.getwd)
projectDir = Dir.getwd + "/" + projectName
xibResults = Array.new()
Dir.glob(projectDir + "/**/**/**/**.{xib}").each do |name|
next if Dir.exists? name
filePaths = name.split("/")
xibFile = filePaths[filePaths.count - 1]
xibName = xibFile.gsub(".xib","")
xibResults.push(xibName)
end
# puts(xibResults)
return xibResults
end
def findCoponentXibUsageInMainPrj(xibFileClassName)
#修改路径为自己需检测的主工程目录
mainProjectDir = "主工程目录"
xibUsedArray = Array.new()
#使用xib必须会用到xib的名字,可能有以下三种方式使用,搜索出来以后就行
xibUsePattern = /\"#{xibFileClassName}\"/
xibOtherUsePattern = /NSStringFromClass(#{xibFileClassName}.class)/
xibThirdUsePattern = /NSStringFromClass(\[#{xibFileClassName} class\])/
Dir.glob(mainProjectDir + "/**/**/**.{m}").each do |ocmFile|
next if Dir.exists? ocmFile
text = File.read(ocmFile)
xibresults = text.scan(xibUsePattern)
xibresults += text.scan(xibOtherUsePattern)
xibresults += text.scan(xibThirdUsePattern)
if(xibresults.count > 0)
puts("xib used in file" + ocmFile)
puts(xibresults)
end
end
end
def startFind
xibFiles = findXibs
for xibFile in xibFiles do
findCoponentXibUsageInMainPrj(xibFile)
end
end
startFind