Class: Pod::Command::Tag
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::Tag
- Defined in:
- lib/cocoapods-hd/command/tag.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_tag ⇒ Object
- #cocoapods_repos_dir ⇒ Object
-
#create_tag ⇒ Object
创建tag.
-
#delete_tag(tag) ⇒ Object
移除tag.
-
#get_source_specs_dir ⇒ Object
获取 HDSourceSpecs 路径.
-
#get_tag ⇒ Object
获取tag名称.
-
#initialize(argv) ⇒ Tag
constructor
A new instance of Tag.
- #remove_git_source_repo ⇒ Object
-
#remove_pod_repo_source(tag_name) ⇒ Object
移除远程仓库podspec.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Tag
Returns a new instance of Tag.
21 22 23 24 25 26 27 28 29 |
# File 'lib/cocoapods-hd/command/tag.rb', line 21 def initialize(argv) @beta = argv.flag?('beta', false) @create = argv.flag?('create', false) @delete = argv.flag?('delete', false) @tag_version = argv.shift_argument # @tag_version = argv.option('tag_version') || nil # @tag_version = argv.arguments! unless argv.arguments.empty? super end |
Class Method Details
.options ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/cocoapods-hd/command/tag.rb', line 13 def self. [ ['--beta', 'beta tag'], ['--create', 'create tag'], ['--delete', 'delete tag and remove pod repo source'], ] end |
Instance Method Details
#build_tag ⇒ Object
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 |
# File 'lib/cocoapods-hd/command/tag.rb', line 31 def build_tag UI.puts "🍉 开始创建tag: #{get_tag}" if TagUtil.exist_tag(get_tag) TagUtil.git_delete_tag(get_tag) end `git tag #{get_tag}` `git push origin #{get_tag}` latest_tag = %x(git describe --abbrev=0 --tags 2>/dev/null) UI.puts("--------- latest tag ----------") UI.puts(latest_tag) unless get_tag.eql?(latest_tag.to_s.strip) TagUtil.git_delete_tag(get_tag) UI.warn("⚠️ commit没有改变,请先提交内容") return end module_dir = Dir.pwd Dir['*.podspec'].each do |rip| podspec_name = rip.to_s if podspec_name.empty? UI.warn("#{module_dir}目录下,不包含.podspec文件") return end podspec_json_name = "#{podspec_name}.json" pod_name = podspec_name.gsub(".podspec", "") `pod ipc spec #{pod_name}.podspec >>#{podspec_json_name}` podspec_json_dir = File.join(Dir.pwd, podspec_json_name) UI.puts("HDSourceSpecs目录: #{get_source_specs_dir}") Dir.chdir(get_source_specs_dir) `git pull` dest_dir = File.join(get_source_specs_dir, pod_name, get_tag) UI.section("创建目录: #{dest_dir}") do FileUtils.mkdir_p(dest_dir) unless File.directory?(dest_dir) end UI.section("move #{podspec_json_dir} to #{dest_dir}") do FileUtils.mv(podspec_json_dir, dest_dir) end UI.section("✅ #{podspec_json_name} 上传成功") do TagUtil.upload_origin_sources("添加 #{pod_name}/#{get_tag}") end Dir.chdir(module_dir) end unless File.directory?(cocoapods_repos_dir) remove_git_source_repo end unless @beta beta_tag = "#{@tag_version}-beta" if TagUtil.exist_tag(beta_tag) UI.section("正式tag #{@tag_version} 创建成功,删除#{@tag_version}-beta") do delete_tag(beta_tag) end end end end |
#cocoapods_repos_dir ⇒ Object
177 178 179 |
# File 'lib/cocoapods-hd/command/tag.rb', line 177 def cocoapods_repos_dir File.join(Dir.home, ".cocoapods/repos/HDSourceSpecs") end |
#create_tag ⇒ Object
创建tag
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cocoapods-hd/command/tag.rb', line 99 def create_tag unless TagUtil.check_release_branch UI.warn("❌ 当前分支仅支持打 beta tag") unless @beta build_tag if @beta return end unless TagUtil.check_branch_include_tag(@tag_version) UI.warn("❌ 分支后缀版本号,必须跟tag保持一致") return end build_tag end |
#delete_tag(tag) ⇒ Object
移除tag
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/cocoapods-hd/command/tag.rb', line 136 def delete_tag(tag) UI.puts "🍉 开始删除tag: #{tag}" if TagUtil.exist_tag(tag) TagUtil.git_delete_tag(tag) remove_pod_repo_source(tag) else UI.warn "❌ 不存在tag: #{tag}" end end |
#get_source_specs_dir ⇒ Object
获取 HDSourceSpecs 路径
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/cocoapods-hd/command/tag.rb', line 117 def get_source_specs_dir if File.directory?(cocoapods_repos_dir) cocoapods_repos_dir else module_parent_dir = File.("..", Dir.pwd) # module目录的上一级 source_repo_path = File.join(module_parent_dir, "HDSourceSpecs") if File.exist?(source_repo_path) source_repo_path else Dir.chdir(module_parent_dir) `git clone http://gitlab.dushuclub.io/cocoapods/HDSourceSpecs.git` source_repo_path end end end |
#get_tag ⇒ Object
获取tag名称
148 149 150 |
# File 'lib/cocoapods-hd/command/tag.rb', line 148 def get_tag @beta ? "#{@tag_version}-beta" : @tag_version end |
#remove_git_source_repo ⇒ Object
181 182 183 184 |
# File 'lib/cocoapods-hd/command/tag.rb', line 181 def remove_git_source_repo source_repo_path = File.join(File.dirname(Dir.pwd), "HDSourceSpecs") FileUtils.rm_r(source_repo_path) end |
#remove_pod_repo_source(tag_name) ⇒ Object
移除远程仓库podspec
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/cocoapods-hd/command/tag.rb', line 153 def remove_pod_repo_source(tag_name) Dir['*.podspec'].each do |rip| pod_name = rip.to_s.gsub(".podspec", "") UI.puts "pod_name: #{pod_name}" source_specs_dir = get_source_specs_dir pod_tag_path = File.join(source_specs_dir, pod_name, tag_name) unless File.exist?(pod_tag_path) UI.warn "❌ 本地HDSourceSpecs不包含#{pod_name}的#{tag_name}标签, 请先执行 pod repo update" remove_git_source_repo break end FileUtils.remove_dir(pod_tag_path) Dir.chdir(source_specs_dir) UI.section("✅ #{pod_name} #{tag_name} 标签删除成功 !!!") do TagUtil.upload_origin_sources("删除 #{pod_name}/#{tag_name}") end end end |
#run ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/cocoapods-hd/command/tag.rb', line 186 def run if @delete delete_tag(get_tag) else create_tag end end |