Class: Pod::Command::Kz::Clean

Inherits:
Pod::Command::Kz show all
Defined in:
lib/cocoapods-kz/command/clean.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pod::Command::Kz

#validate!

Constructor Details

#initialize(argv) ⇒ Clean

Returns a new instance of Clean.



24
25
26
27
28
29
# File 'lib/cocoapods-kz/command/clean.rb', line 24

def initialize(argv)
  clean_xcode = argv.flag?('xcode')
  banner! unless clean_xcode

  super
end

Class Method Details

.optionsObject



18
19
20
21
22
# File 'lib/cocoapods-kz/command/clean.rb', line 18

def self.options
  [
    %w[--xcode 清除module缓存与头文件索引问题],
  ]
end

Instance Method Details

#runObject



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
# File 'lib/cocoapods-kz/command/clean.rb', line 31

def run
  xcodeproj_path = Pathname.new(Dir[Pod::Config.instance.installation_root + "*.xcodeproj"].first)
  return unless xcodeproj_path

  xcode_derived_data_path = Pathname.new(Dir.home + "/Library/Developer/Xcode/DerivedData")
  module_cache_noindex_path = xcode_derived_data_path + "ModuleCache.noindex"
  FileUtils.rm_rf(module_cache_noindex_path) if module_cache_noindex_path.exist?

  project_name = xcodeproj_path.basename.to_s.split(".").first
  Dir.foreach(xcode_derived_data_path) do |file_name|
    next if file_name == '.' || file_name == '..' || file_name == '.DS_Store'

    if file_name.start_with?(project_name)
      project_path = xcode_derived_data_path + file_name
      index_noindex_path = project_path + "Index.noindex"
      FileUtils.rm_rf(index_noindex_path) if index_noindex_path.exist?
    end
  end

  default_xcode_path = Pathname.new('/Applications/Xcode.app')
  if default_xcode_path.exist?
    system("osascript -e 'quit app \"Xcode\"'")
    sleep 1
    workspace_path = Dir[Pod::Config.instance.installation_root + "*.xcworkspace"].first
    system("open \"#{workspace_path}\"")
  end
end