Class: Pod::Command::Bin::Clean

Inherits:
Pod::Command::Bin show all
Defined in:
lib/cocoapods-imy-bin/command/bin/clean.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pod::Command::Bin

#validate!

Methods included from CBin::SpecFilesHelper

#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files

Methods included from CBin::SourcesHelper

#binary_source, #code_source, #sources_manager, #sources_option, #valid_sources

Constructor Details

#initialize(argv) ⇒ Clean

Returns a new instance of Clean.



24
25
26
27
28
29
30
31
32
# File 'lib/cocoapods-imy-bin/command/bin/clean.rb', line 24

def initialize(argv)
  @env =  argv.option('env') || nil
  @list = argv.flag?('list', [] )
  @all_clean = argv.flag?('all', false )

  @config = Pod::Config.instance

  super
end

Class Method Details

.optionsObject



15
16
17
18
19
20
21
# File 'lib/cocoapods-imy-bin/command/bin/clean.rb', line 15

def self.options
  [
      ['--env=configuration_env', '清除哪个环境,在.cocoapods下的 bin_dev.yml的配置项,dev'],
      ['--list=[module,module,...]', '清除某个仓库下的模块 TODO'],
      ['--all', '清除所有 TODO'],
  ].concat(Pod::Command::Gen.options).concat(super).uniq
end

Instance Method Details

#delete_build_binaryObject

三、删除二进制私有源存储二进制文件,



98
99
100
101
# File 'lib/cocoapods-imy-bin/command/bin/clean.rb', line 98

def delete_build_binary
  `curl #{@config.delete_binary_url}`
  UI.puts "完成删除服务器二进制包"
end

#deleteDirectory(dirPath) ⇒ Object

遍历文件夹



111
112
113
114
115
116
117
118
119
120
# File 'lib/cocoapods-imy-bin/command/bin/clean.rb', line 111

def deleteDirectory(dirPath)
  if File.directory?(dirPath)
    puts "是文件夹";
    Dir.foreach(dirPath) do |subFile|
      if subFile != '.' and subFile != '..' and subFile != ".git"
        FileUtils.remove_entry(File.join(dirPath, subFile))
      end
    end
  end
end

#reset_binary_repoObject

一、清除git上的仓库 1、拿到仓库地址 CBin.config.binary_repo_url 2、clone仓库 3、删除仓库下所有可见目录,除了.git 4、提交删除记录



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cocoapods-imy-bin/command/bin/clean.rb', line 70

def reset_binary_repo
  work_dir = Dir.tmpdir + '/cocoapods-imy-bin-' + Array.new(8) { rand(36).to_s(36) }.join
  UI.puts "临时目录 work_dir = #{work_dir}"
  Pathname.new(work_dir).mkdir

  `git clone #{@config.binary_repo_url} #{work_dir}`

  deleteDirectory(work_dir)
  UI.puts "binary_repo_url = #{@config.binary_repo_url}"

  #在当前目录下 做git操作,才能提交成功
  Dir.chdir(work_dir) do
    UI.puts "当前目录 = #{Dir.pwd}"
    `git add .`
    `git commit -m "cocopods-imy-bin auto del"`
    `/usr/bin/git push`
  end

end

#runObject



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

def run
  #清除所有仓库缓存
  if @all_clean

  elsif @env  #是否存在spec仓库
    #获取对应环境地址
     CBin.config.set_configuration_env(@env)
     @config = CBin.config
    unless @config
      raise "请检查 env = #{@env} 私有源仓库是否设置正常"
    end

    # #1、清除git
    reset_binary_repo
    # #2、更新本地仓库源
    update_cocoapods_repo
    #3、删除二进制私有源存储二进制文件
    update_cocoapods_repo

     delete_build_binary
    #4、清除cocoapods pods cache
    update_cocopods_pods_cache

    # @config.clean_binary_url
  else #不存在spec仓库、就抛异常
    raise "未设置 spec 私有源仓库"
  end

end

#update_cocoapods_repoObject

二、更新本地仓库源, pod repo update xxx



92
93
94
95
# File 'lib/cocoapods-imy-bin/command/bin/clean.rb', line 92

def update_cocoapods_repo
  `pod repo update`
  UI.puts "完成pod repo update"
end

#update_cocopods_pods_cacheObject

四、清除cocoapods pods cache



104
105
106
107
# File 'lib/cocoapods-imy-bin/command/bin/clean.rb', line 104

def update_cocopods_pods_cache
  `pod cache clean --all --verbose`
  UI.puts "完成清除本地pod cache"
end