Class: PodBuilder::Command::Clean

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

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object



7
8
9
10
11
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
# File 'lib/pod_builder/command/clean.rb', line 7

def self.call(options)
  Configuration.check_inited
  PodBuilder::prepare_basepath

  install_update_repo = options.fetch(:update_repos, true)
  installer, analyzer = Analyze.installer_at(PodBuilder::basepath, install_update_repo)
  all_buildable_items = Analyze.podfile_items(installer, analyzer)

  podspec_names = all_buildable_items.map(&:podspec_name)
  rel_paths = all_buildable_items.map(&:prebuilt_rel_path)

  base_path = PodBuilder::basepath("Rome")
  framework_files = Dir.glob("#{base_path}/**/*.framework")
  puts "Looking for unused frameworks".yellow
  clean(framework_files, base_path, rel_paths)

  rel_paths.map! { |x| "#{x}.dSYM"}

  base_path = PodBuilder::basepath("dSYM/iphoneos")
  dSYM_files_iphone = Dir.glob("#{base_path}/**/*.dSYM")
  puts "Looking for iPhoneOS unused dSYMs".yellow    
  clean(dSYM_files_iphone, base_path, rel_paths)

  base_path = PodBuilder::basepath("dSYM/iphonesimulator")
  dSYM_files_sim = Dir.glob("#{base_path}/**/*.dSYM")
  puts "Looking for iPhone Simulator unused dSYMs".yellow
  clean(dSYM_files_sim, base_path, rel_paths)

  puts "Looking for unused sources".yellow
  clean_sources(podspec_names)

  puts "\n\nšŸŽ‰ done!\n".green
  return 0
end

.clean_sources(podspec_names) ⇒ Object



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/pod_builder/command/clean.rb', line 42

def self.clean_sources(podspec_names)        
  base_path = PodBuilder::basepath("Sources")

  repo_paths = Dir.glob("#{base_path}/*")

  paths_to_delete = []
  repo_paths.each do |path|
    podspec_name = File.basename(path)

    unless !podspec_names.include?(podspec_name)
      next
    end

    paths_to_delete.push(path)
  end

  paths_to_delete.flatten.each do |path|
    confirm = ask("#{path} unused.\nDelete it? [Y/N] ") { |yn| yn.limit = 1, yn.validate = /[yn]/i }
    if confirm.downcase == 'y'
      PodBuilder::safe_rm_rf(path)
    end
  end
end