创建 BLHelp.rb 用.rb格式
#!/usr/bin/ruby
def reference_file(installer, folder)
path = Pathname(File.expand_path(folder, __dir__))
installer.pods_project.main_group.new_reference(path)
end
def find_and_replace(dir, findstr, replacestr, mark)
\# 判断文件是否存在
if File.exist?(dir) == false
return puts "不存在" + dir
end
\# 判断文件是否有写入权限
p=File.writable?( dir )
if p == false #没有则赋予权限
File.chmod(0644, dir)
end
Dir[dir].each do |name|
text = File.read(name)
\# 判断内容是否有标记 有标记则代表更换过
if text.include?mark
puts "包含"
else
replace = text.gsub(findstr,replacestr)
puts "replace"
puts replace
if text != replace #是否相等 不等在替换
File.open(name, "w+") { |file| file.puts replace }
puts "Fix: " + name
STDOUT.flush
else
puts "一样"
end
end
end
Dir[dir + '*/'].each(&method(:find_and_replace))
end
Podfile 文件中调用 (修改pod 三方库中指定文件内的代码)
reference_file(installer, 'BLHelp.rb') ##把 BLHelp.rb文件显示在Pod目录下和podfile 一样
## Fix for XCode 12.5 修改文件
find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",
"layoutCache[currentClass] = ivars;", "layoutCache[(id<NSCopying>)currentClass] = ivarss;//mark","//mark")
网友评论