Class: Xcodeprojfiler::Command
- Inherits:
-
Object
- Object
- Xcodeprojfiler::Command
- Defined in:
- lib/xcodeprojfiler/command.rb
Class Method Summary collapse
-
.dump_excluded_files_to_file(excluded_file_array) ⇒ Object
dump_excluded_files_to_file -> true.
-
.find_xclued_files(ignored_regex_array) ⇒ included_file_array, excluded_file_array
find_xclued_files -> xcluded_file_result_tuple.
- .show_common_tips_before_scan ⇒ Object
- .show_excluded_code_files(shouldDelete, ignored_regex_array) ⇒ Object
- .show_excluded_files(shouldDelete, ignored_regex_array) ⇒ Object
- .version ⇒ Object
Class Method Details
.dump_excluded_files_to_file(excluded_file_array) ⇒ Object
dump_excluded_files_to_file -> true
保存 excluded_file_array 到 excluded_files.yaml
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 |
# File 'lib/xcodeprojfiler/command.rb', line 120 def self.dump_excluded_files_to_file(excluded_file_array) root_dir = "#{Pathname::pwd}" yaml_file_path = "#{root_dir}/excluded_files.yaml" yaml_file = File.open(yaml_file_path, 'w') excluded_file_array.uniq! excluded_file_array.sort! yaml_content = { "excluded_files" => excluded_file_array }.to_yaml # remove three dashes (“---”). # # To get the details about three dashes (“---”) # see: https://yaml.org/spec/1.2/spec.html#id2760395 # document_separate_maker = "---\n" regx = /\A#{document_separate_maker}/ if yaml_content =~ regx yaml_content[document_separate_maker] = "" end yaml_file.write(yaml_content) yaml_file.close puts("") puts("to see the excluded files from: #{yaml_file_path}") return true end |
.find_xclued_files(ignored_regex_array) ⇒ included_file_array, excluded_file_array
find_xclued_files -> xcluded_file_result_tuple
扫描当前目录,返回包含和不包含在xcworkspace的文件数组 返回文件结果二元组 xcluded_file_result_tuple xcluded_file_result_tuple = [included_file_array, excluded_file_array]
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 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 |
# File 'lib/xcodeprojfiler/command.rb', line 45 def self.find_xclued_files(ignored_regex_array) included_file_array = [] excluded_file_array = [] # 获取当前目录的 xcworkspace 文件路径 root_dir = "#{Pathname::pwd}" xcworkspace_file = Dir.glob(["#{root_dir}/*.xcworkspace"]).first # xcworkspace_root_dir = "/Users/yorkfish/Workspace/Demo-Projects/TestGitFilter-OC" # xcworkspace_file = "/Users/yorkfish/Workspace/Demo-Projects/TestGitFilter-OC/TestGitFilter-OC.xcworkspace" if xcworkspace_file == nil puts("") puts("[!] No xcworkspace file found in the current working directory".red) return [included_file_array, excluded_file_array] end puts("") puts("scan the current working directory now ...") xcworkspace = Xcodeproj::Workspace.new_from_xcworkspace(xcworkspace_file) xcworkspace_file_references = xcworkspace.file_references xcworkspace_file_array = [] xcworkspace_file_references.each do |file_ref| if file_ref.path != "Pods/Pods.xcodeproj" proj_absolute_path = "#{root_dir}/#{file_ref.path}" # puts("xcworkspace_project: #{proj_absolute_path}") proj = Xcodeproj::Project::open(proj_absolute_path) proj.files.each do |pbx_file_ref| full_file_path = "#{proj.project_dir}/#{pbx_file_ref.full_path}" xcworkspace_file_array.push(full_file_path) end end end all_files = Dir.glob(["#{root_dir}/**/*.*"]) excluded_file_regex_array = [ "#{root_dir}/**/*.xcodeproj/**/*", "#{root_dir}/**/*.xcworkspace/**/*", "#{root_dir}/**/*.xcassets/**/*", "#{root_dir}/**/*.xctemplate/**/*", "#{root_dir}/**/*.framework/**/*", "#{root_dir}/**/*.bundle/**/*", "#{root_dir}/**/.git/**/*", "#{root_dir}/**/fastlane/**/*", "#{root_dir}/**/Pods/**/*", "#{root_dir}/**/Podfile", "#{root_dir}/**/Gemfile", "#{root_dir}/**/*{.git,.xcworkspace,.xcodeproj,.lproj,.xctemplate,.lock,.rb,.py,.sh,.log,.config,.properties}" ] all_files = all_files - Dir.glob(excluded_file_regex_array) if ignored_regex_array.empty? == false puts("") puts("Xcodeprojfiler will ignore the following files which you specify:") puts("") ignored_regex_array.each do |regex| puts(" - #{regex}") end all_files = all_files - Dir.glob(ignored_regex_array) end included_file_array = xcworkspace_file_array excluded_file_array = all_files - included_file_array puts("") puts("scan the current working directory done !!!") return [included_file_array, excluded_file_array] end |
.show_common_tips_before_scan ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/xcodeprojfiler/command.rb', line 13 def self.show_common_tips_before_scan puts("") puts("PS: If the xcode project is very large, Xcodeprojfiler needs more than 5min to scan") puts("") ignore_file_tips = <<-MESSAGE PS: Xcodeprojfiler do ignore the following files: - fastlane/* - Pods/* - Podfile - Gemfile - .git/* - *.xctemplate - *.lock - *.py - *.rb - *.sh - *.log - *.config - *.properties MESSAGE puts("#{ignore_file_tips}") end |
.show_excluded_code_files(shouldDelete, ignored_regex_array) ⇒ Object
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 |
# File 'lib/xcodeprojfiler/command.rb', line 165 def self.show_excluded_code_files(shouldDelete, ignored_regex_array) self.show_common_tips_before_scan code_file_types = [ ".h", ".c", ".cpp", ".m", ".mm", ".swift", ".a", ".framework", ".xib", ".storyboard", ] puts("") puts("PS: Xcodeprojfiler will show and delete(if you choose) the following code files:") puts("") code_file_types.each do |code_file_type| puts(" - *#{code_file_type}") end xcluded_file_result_tuple = self.find_xclued_files(ignored_regex_array) excluded_file_array = xcluded_file_result_tuple[1] excluded_code_file_array = excluded_file_array.select do |file| file_extname = File.extname(file) if code_file_types.include?(file_extname) next true end end if shouldDelete puts("") puts("delete the excluded files now ...") FileUtils.rm_rf(excluded_code_file_array) puts("") puts("delete the excluded files done !!!") end dump_excluded_files_to_file(excluded_code_file_array) end |
.show_excluded_files(shouldDelete, ignored_regex_array) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/xcodeprojfiler/command.rb', line 149 def self.show_excluded_files(shouldDelete, ignored_regex_array) self.show_common_tips_before_scan xcluded_file_result_tuple = self.find_xclued_files(ignored_regex_array) excluded_file_array = xcluded_file_result_tuple[1] if shouldDelete puts("") puts("delete the excluded files now ...") FileUtils.rm_rf(excluded_file_array) puts("") puts("delete the excluded files done !!!") end dump_excluded_files_to_file(excluded_file_array) end |
.version ⇒ Object
8 9 10 11 |
# File 'lib/xcodeprojfiler/command.rb', line 8 def self.version version_desc = "#{Xcodeprojfiler::VERSION}" puts(version_desc) end |