Top Level Namespace
Defined Under Namespace
Classes: YPHelp, YPInstall, YPTools
Instance Method Summary collapse
- #yp_log_doing(log) ⇒ Object
- #yp_log_fail(log) ⇒ Object
- #yp_log_success(log) ⇒ Object
-
#yp_method_ceateGarbageCodeByObjC_m(path, outPath, suffix) ⇒ Object
根据.m文件创建垃圾代码.
-
#yp_method_fileList(path, script, ignoringFiles) ⇒ Object
正则查询文件列表,path:传路径 script:正则表达式 ignoringFiles:忽略的文件或者文件夹 retun [文件名:文件路径,文件名2:文件路径2].
-
#yp_method_ignoringFiles ⇒ Object
需要忽略的文件或者文件夹.
-
#yp_method_makeGarbage(path, outPath, suffix) ⇒ Object
生成垃圾数据.
-
#yp_method_mkdir(path) ⇒ Object
创建文件夹.
-
#yp_method_rmdir(path) ⇒ Object
删除文件夹(包括文件夹下面的文件).
-
#yp_tools_method_makeGarbage(suffix) ⇒ Object
生成垃圾数据.
Instance Method Details
#yp_log_doing(log) ⇒ Object
9 10 11 |
# File 'lib/yptools/log/yp_log.rb', line 9 def yp_log_doing (log) puts log.yellow end |
#yp_log_fail(log) ⇒ Object
5 6 7 |
# File 'lib/yptools/log/yp_log.rb', line 5 def yp_log_fail (log) puts log.red end |
#yp_log_success(log) ⇒ Object
1 2 3 |
# File 'lib/yptools/log/yp_log.rb', line 1 def yp_log_success (log) puts log.green end |
#yp_method_ceateGarbageCodeByObjC_m(path, outPath, suffix) ⇒ Object
根据.m文件创建垃圾代码
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/yptools/mgc/yp_makegarbagecode.rb', line 68 def yp_method_ceateGarbageCodeByObjC_m(path,outPath,suffix) pathFile = File.open(path, "r") maxLineThreshold = 10000 fileLine = 0 fileName = File.basename(path,".*") mainStringH = "@interface " + fileName + " (#{suffix})" mainStringM = "@implementation " + fileName + " (#{suffix})" importStringsH = Array.new importStringsM = Array.new methodStringsH = Array.new methodStringsM = Array.new pathFileStrings = Array.new isClass = 0 while textLine = pathFile.gets fileLine += 1 if pathFileStrings.include?(textLine) next end if textLine.include?("@implementation #{fileName}") isClass = 1 end pathFileStrings.push(textLine) if textLine.include?("#import") importStringsH.push(textLine) elsif textLine.start_with?("-(") | textLine.start_with?("- (") if textLine.include?("API_AVAILABLE") next end textLine = textLine.sub(" \{","\{") textLine = textLine.sub("\n","") unless textLine.include?("{") textLine = textLine + "{" end returnStringM = "" if textLine.include?("-(void") | textLine.include?("- (void") returnStringM = " return;" elsif textLine.include?("- (IBAction") | textLine.include?("-(IBAction") returnStringM = " return;" elsif textLine.include?("- (CGFloat") | textLine.include?("-(CGFloat") returnStringM = " return 0.f;" elsif textLine.include?("- (CGRect") | textLine.include?("-(CGRect") returnStringM = " return CGRectZero;" elsif textLine.include?("- (CGSize") | textLine.include?("-(CGSize") returnStringM = " return CGSizeZero;" elsif textLine.include?("- (UIEdgeInsets") | textLine.include?("-(UIEdgeInsets") returnStringM = " return UIEdgeInsetsZero;" else next end # .h 文件生成 replaceStringH = "" if textLine.include?(":") replaceStringH = " " + suffix + ":(NSString *)" + suffix + ";" else replaceStringH = suffix + ":(NSString *)" + suffix + ";" end tempTextLineH = textLine.sub("\{",replaceStringH) methodStringsH.push("/// " + suffix) methodStringsH.push("\n") methodStringsH.push(tempTextLineH) methodStringsH.push("\n") methodStringsH.push("\n") # .m 文件生成 replaceStringM = "" if textLine.include?(":") replaceStringM = " " + suffix + ":(NSString *)" + suffix + "\ {" else replaceStringM = suffix + ":(NSString *)" + suffix + "\ {" end tempTextLineM = textLine.sub("\{",replaceStringM) methodStringsM.push("/// " + suffix) methodStringsM.push("\n") methodStringsM.push(tempTextLineM) methodStringsM.push("\n") methodStringsM.push(" NSLog(@\"%@\",#{suffix});") methodStringsM.push("\n") methodStringsM.push(returnStringM) methodStringsM.push("\n") methodStringsM.push("}") methodStringsM.push("\n") methodStringsM.push("\n") end end if isClass != 1 return end importStringsH.push("\n") importStringsH.push(mainStringH) importStringsH.push("\n") importStringsH.push("\n") methodStringsH.push("@end") file_h = importStringsH + methodStringsH importStringsM.push("#import \"#{fileName}+#{suffix}.h\"") importStringsM.push("\n") importStringsM.push("\n") importStringsM.push(mainStringM) importStringsM.push("\n") importStringsM.push("\n") methodStringsM.push("@end") file_m = importStringsM + methodStringsM unless outPath =~ /(\/$)/ outPath = outPath + "/" end filePathH = outPath + fileName + "+#{suffix}.h" filePathM = outPath + fileName + "+#{suffix}.m" createFileH = File.new(filePathH,"w+") file_h.each {|lineTest| createFileH.syswrite(lineTest) } createFileM = File.new(filePathM,"w+") file_m.each {|lineTest| createFileM.syswrite(lineTest) } pathFile.close end |
#yp_method_fileList(path, script, ignoringFiles) ⇒ Object
正则查询文件列表,path:传路径 script:正则表达式 ignoringFiles:忽略的文件或者文件夹 retun [文件名:文件路径,文件名2:文件路径2]
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 |
# File 'lib/yptools/mgc/yp_makegarbagecode.rb', line 12 def yp_method_fileList (path,script,ignoringFiles) unless File.directory?(path) return end unless path =~ /(\/$)/ path = path + "/" end fileList = Array.new Dir.entries(path).each do |sub| unless ignoringFiles.include?(sub) subPath = path + sub; if File.directory?(subPath) subFileList = yp_method_fileList subPath, script, ignoringFiles fileList = fileList + subFileList; else if subPath =~ script obj = Hash.new obj[sub] = subPath fileList.push(obj) end end end end return fileList end |
#yp_method_ignoringFiles ⇒ Object
需要忽略的文件或者文件夹
7 8 9 |
# File 'lib/yptools/mgc/yp_makegarbagecode.rb', line 7 def yp_method_ignoringFiles return ".", "..", ".DS_Store", "Pods", "LocalPods", "main.m", "doc" end |
#yp_method_makeGarbage(path, outPath, suffix) ⇒ Object
生成垃圾数据
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/yptools/mgc/yp_makegarbagecode.rb', line 218 def yp_method_makeGarbage (path, outPath, suffix) # 筛选文件的正则 script = /^(?!.*(\+)).*.(\.m)$/ # 配置忽略文件 ignoringFiles = yp_method_ignoringFiles # 获取符合条件的文件列表 fileList = yp_method_fileList path, script, ignoringFiles fileList.each { |fileDic| fileDic.each { |key, value| createTime = Time.new fileName = File.basename(value,".*") filePathH = fileName + "+#{suffix}.h" filePathM = fileName + "+#{suffix}.m" yp_log_success createTime.inspect + " 生成 " + filePathH + "、" + filePathM + " 完成" yp_method_ceateGarbageCodeByObjC_m(value,outPath,suffix) } } end |
#yp_method_mkdir(path) ⇒ Object
创建文件夹
61 62 63 |
# File 'lib/yptools/mgc/yp_makegarbagecode.rb', line 61 def yp_method_mkdir (path) Dir.mkdir(path) end |
#yp_method_rmdir(path) ⇒ Object
删除文件夹(包括文件夹下面的文件)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yptools/mgc/yp_makegarbagecode.rb', line 44 def yp_method_rmdir (path) if File.exists?(path) if File.directory?(path) Dir.foreach(path) do |subPath| if subPath != '.' and subPath != '..' tempSubPath = File.join(path, subPath) yp_method_rmdir(tempSubPath) end end Dir.rmdir(path) else File.delete(path) end end end |
#yp_tools_method_makeGarbage(suffix) ⇒ Object
生成垃圾数据
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/yptools/mgc/yp_makegarbagecode.rb', line 241 def yp_tools_method_makeGarbage (suffix) yp_log_doing "🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀"; yp_path = `pwd` yp_path = yp_path.sub("\n","") yp_outPath = "#{yp_path}/" + suffix yp_log_doing "当前目录 #{yp_path}" yp_log_doing "垃圾代码生成目录 #{yp_outPath}" yp_log_doing "后缀 #{suffix}" if suffix.length == 0 yp_log_fail "后缀不能为空" return end yp_isTruePath = 0 Dir.entries(yp_path).each do |subFile| if subFile.include?(".xcodeproj") | subFile.include?(".xcworkspace") yp_isTruePath = 1 break end end if yp_isTruePath == 0 yp_log_fail "#{yp_path} " + "此目录没有工程,请切换到项目目录下再执行 'yptools mgc ..' 命令" return end yp_method_rmdir yp_outPath yp_method_mkdir yp_outPath yp_method_makeGarbage yp_path, yp_outPath, suffix yp_log_doing "🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀"; end |