require 'cocoapods' require_relative '../source/util/http_util' module OrmDev class Command class Publish < Command self.summary = '发布插件' self.description = <<-DESC 发布插件. 指定'插件名.podspec'的路径`PATH`。 DESC self.arguments = [ CLAide::Argument.new('PATH', false) ] def self.options [ ['--account=XXX', '发布第三方插件的账户名'], ['--password=XXX', '发布第三方插件的密码'], ['--changelog=xxxx', '更新说明'], ['--zip=xxx', '插件SDK本地地址,当push-type = 0,是必传'], ['--push-type=[0,1,2]', '发布类型:0、替换+push+录入;1、push+录入;2、直接录入'], ].concat(super) end def initialize(argv) @podspec_file = argv.shift_argument @podspec_files = Pathname.pwd.children.select { |pn| pn.extname == '.podspec' } @account = argv.option('account') @password = argv.option('password') @changelog = argv.option('changelog', '') @push_type = argv.option('push-type').to_i @zip = argv.option('zip') super end def validate! super # raise Pod::Informative, "No `Cimfile' found in the project directory." unless @cipfile_path.exist? if @podspec_file help! "podspec file at #{@podspec_file} does not exist" unless File.exist? @podspec_file @podspec_path = @podspec_file else raise Pod::Informative, 'No podspec file found, please specify one' unless @podspec_files.length > 0 raise Pod::Informative, 'Multiple podspec file found, please specify one' unless @podspec_files.length == 1 @podspec_path = @podspec_files.first end help! '发布类型传值错误' if @push_type < 0 || @push_type > 2 if @push_type == 0 then help! '插件zip包地址不能为空' if @zip.nil? help! "插件zip包地址( #{@zip} )不存在" unless File.exist? @zip end end def run super OrmDev::LogUtil.info '[插件发布] '.green info = OrmDev::HTTPUtil.send_pulish_plugin_http(@account, @password, @push_type, @podspec_path, @zip, @changelog) OrmDev::LogUtil.info "插件发布完成!!! #{info}" end end end end