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

def initialize(argv)
  @clean_xcode = argv.flag?('xcode')
  @clean_framework = argv.flag?('framework')
  banner! unless @clean_xcode || @clean_framework

  super
end

Class Method Details

.optionsObject



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

def self.options
  [
    ["--xcode", "清除module缓存与头文件索引问题"],
    ["--framework", "清除所有自生成本地缓存的framework"],
  ]
end

Instance Method Details

#runObject



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

def run
  if @clean_xcode
    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

  if @clean_framework
    FileUtils.rm_r(KZ::KZ_POD_CONFIG_ROOT) if File.exist?(KZ::KZ_POD_CONFIG_ROOT)
  end
end