Class: Xcodeprojfiler::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/xcodeprojfiler/command.rb

Class Method Summary collapse

Class Method Details

.dump_excluded_files_to_file(excluded_file_array) ⇒ Object

dump_excluded_files_to_file -> true

保存 excluded_file_array 到 excluded_files.yaml



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
# File 'lib/xcodeprojfiler/command.rb', line 112

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]

Returns:

  • (included_file_array, excluded_file_array)


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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/xcodeprojfiler/command.rb', line 19

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("Xcodeprojfiler Error: not exited xcworkspace file: #{xcworkspace_file}")
    return [included_file_array, excluded_file_array]
  end

  puts("scan the current directory now ...")
  puts("")
  puts("PS: if the xcode project is very larger, Xcodeprojfiler needs more than 10min to scan")

  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

  puts("")
  ignore_file_tips = "PS: Xcodeprojfiler will ignore the following files:\n\n  - fastlane/*\n  - Pods/*\n  - Podfile\n  - Gemfile\n  - .git/*\n  - *.xcassets\n  - *.xctemplate\n  - *.framework\n  - *.bundle\n  - *.lock\n  - *.py\n  - *.rb\n  - *.sh\n  - *.log\n  - *.config\n  - *.properties\n\n  MESSAGE\n  puts(\"\#{ignore_file_tips}\")\n\n  all_files = Dir.glob([\"\#{root_dir}/**/*.*\"])\n  excluded_file_regex_array = [\n    \"\#{root_dir}/**/*.xcodeproj/**/*\",\n    \"\#{root_dir}/**/*.xcworkspace/**/*\",\n    \"\#{root_dir}/**/*.xcassets/**/*\",\n    \"\#{root_dir}/**/*.xctemplate/**/*\",\n    \"\#{root_dir}/**/*.framework/**/*\",\n    \"\#{root_dir}/**/*.bundle/**/*\",\n    \"\#{root_dir}/**/.git/**/*\",\n    \"\#{root_dir}/**/fastlane/**/*\",\n    \"\#{root_dir}/**/Pods/**/*\",\n    \"\#{root_dir}/**/Podfile\",\n    \"\#{root_dir}/**/Gemfile\",\n    \"\#{root_dir}/**/*{.xcworkspace,.xcodeproj,.lproj,.xcassets,.xctemplate,.framework,.bundle,.lock,.rb,.py,.sh,.log,.config,.properties}\"\n  ]\n  all_files = all_files - Dir.glob(excluded_file_regex_array)\n  if ignored_regex_array.empty? == false\n    puts(\"ignored_regex_array: \#{ignored_regex_array}\")\n    all_files = all_files - Dir.glob(ignored_regex_array)\n  end\n\n  included_file_array = xcworkspace_file_array\n  excluded_file_array =  all_files - included_file_array\n\n  puts(\"\")\n  puts(\"scan the current directory done !!!\")\n\n  return [included_file_array, excluded_file_array]\nend\n"

.show_excluded_code_files(shouldDelete, ignored_regex_array) ⇒ Object



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
# File 'lib/xcodeprojfiler/command.rb', line 155

def self.show_excluded_code_files(shouldDelete, ignored_regex_array)
  xcluded_file_result_tuple = self.find_xclued_files(ignored_regex_array)
  excluded_file_array = xcluded_file_result_tuple[1]

  code_file_types = [
    ".h",
    ".c",
    ".cpp",
    ".m",
    ".mm",
    ".swift",
    ".xib",
    ".storyboard"
  ]

  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_f(excluded_code_file_array)
    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



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/xcodeprojfiler/command.rb', line 141

def self.show_excluded_files(shouldDelete, ignored_regex_array)
  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_f(excluded_file_array)
    puts("delete the excluded files done !!!")
  end

  dump_excluded_files_to_file(excluded_file_array)
end

.versionObject



7
8
9
10
# File 'lib/xcodeprojfiler/command.rb', line 7

def self.version
  version_desc = "#{Xcodeprojfiler::VERSION}"
  puts(version_desc)
end