Class: FirCli
- Inherits:
-
Thor
- Object
- Thor
- FirCli
- Defined in:
- lib/fir-cli.rb
Overview
p Lagunitas::App.new(”).respond_to? :mobileprovision
Instance Method Summary collapse
- #config ⇒ Object
- #info(path) ⇒ Object
-
#initialize(*args) ⇒ FirCli
constructor
A new instance of FirCli.
- #login(token) ⇒ Object
- #publish(path) ⇒ Object
- #resign(ipath, opath) ⇒ Object
- #update(path) ⇒ Object
Constructor Details
#initialize(*args) ⇒ FirCli
Returns a new instance of FirCli.
19 20 21 22 23 24 |
# File 'lib/fir-cli.rb', line 19 def initialize(*args) super @uconfig = UserConfig.new '.fir' @ipa_config = @uconfig['ipa.yaml'] if @ipa_config['resign'] == nil then @ipa_config['resign'] = false end end |
Instance Method Details
#config ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fir-cli.rb', line 42 def config if ![:verbose] .each do |conf| puts "> #{ Paint[conf[0].to_s.rjust(10), :blue] } : #{ @ipa_config[conf[0].to_s] } => #{ conf[1] }" @ipa_config[conf[0]] = conf[1] end @ipa_config.save end puts "> 当前设置:" @ipa_config.each {|conf| puts "> #{ Paint[conf[0].to_s.rjust(10), :blue] } => #{conf[1]}"} end |
#info(path) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/fir-cli.rb', line 139 def info(path) app = _info path, false, ['verbose'] app.each { |i| puts "#{ Paint[i[0].to_s.rjust(15), :blue] } #{ i[1] }" } if [:fir] fir_app = _fir_info app[:identifier] fir_app.each { |i| puts "#{ Paint[i[0].to_s.rjust(15), :blue] } #{ i[1] }" } end end |
#login(token) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/fir-cli.rb', line 27 def login(token) ot = @ipa_config['token'] if ot && ot != token puts "> 替换用户 #{ot} => #{token}" end @ipa_config['token'] = token @ipa_config.save puts "> 当前用户:#{token}" end |
#publish(path) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fir-cli.rb', line 82 def publish(path) if _opt_resign tfile = Tempfile.new SecureRandom.hex resign path, tfile.path path = tfile.path end app = _info path fir_app = _fir_info app[:identifier] id = fir_app[:id] short = fir_app[:short] bundle_app = fir_app[:bundle][:pkg] bundle_icon = fir_app[:bundle][:icon] puts '> 上传应用...' res = RestClient.post bundle_app[:url], :key => bundle_app[:key], :token => bundle_app[:token], :file => File.new(path, 'rb') puts '> 上传应用成功' upload_res = JSON.parse res.body, :symbolize_names => true if app[:icons] != nil icon_path = app[:icons][0][:path] puts '> 转换图标...' Pngdefry.defry icon_path, icon_path puts "> 上传图标..." RestClient.post bundle_icon[:url], :key => bundle_icon[:key], :token => bundle_icon[:token], :file => File.new(icon_path, 'rb') puts '上传图标成功' end _fir_put fir_app[:id], :name => app[:display_name] || app[:name], :short => [:short] || fir_app[:short], :version => app[:version], :versionShort => app[:short_version] _fir_vput upload_res[:versionOid], :version => app[:version], :versionShort => app[:short_version], :devices => app[:devices], :release_type => app[:release_type], :changelog => [:changelog] puts "> http://fir.im/#{short}" end |
#resign(ipath, opath) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/fir-cli.rb', line 150 def resign(ipath, opath) puts '! resign.tapbeta.com 签名服务风险提示' puts '! 无法保证签名证书的长期有效性,当某种条件满足后' puts '! 苹果会禁止该企业账号,所有由该企业账号所签发的' puts '! 证书都会失效。您如果使用该网站提供的服务进行应' puts "! 用分发,请注意:#{ Paint['当证书失效后,所有安装以失效证', :red ] }" puts "! #{ Paint['书签名的的用户都会无法正常运行应用;同时托管在', :red ] }" puts "! #{ Paint['fir.im 的应用将无法正常安装。', :red ] }" if _opt_email == nil puts Paint['! 您需要提供邮件地址才能使用 resign.tapbeta.com 的签名服务', :red] puts Paint['! 使用 fir config --email=EMAIL 进行设置', :green] exit end if !/\.ipa$/.match ipath puts Paint['! 只能给以 ipa 为扩展名的文件签名', :red] exit end puts '> 正在申请上传令牌...' upload_res = RestClient.post 'http://api.resign.tapbeta.com/public/upload', :email => @email, :file => File.basename(ipath) form = JSON.parse upload_res.body, :symbolize_names => true tapbeta = {} form.each do |f| if /^tb_/.match f[0] tapbeta[f[0]] = f[1] form.delete f[0] end end form[:file] = File.new Pathname.new(Dir.pwd).join(ipath).cleanpath, 'rb' puts '> 正在上传...' RestClient.post tapbeta[:tb_upload_url], form puts '> 正在排队...' nped = true info = {} loop do res = RestClient.get "http://api.resign.tapbeta.com/public/#{ tapbeta[:tb_upload_key] }", :params => { :__mr => 'eyJ1cmwiOiIkKHVybCkiLCAicmVzaWduU3RhdHVzIjogIiQocmVzaWduU3RhdHVzKSJ9' } info = JSON.parse res.body, :symbolize_names => true if nped && info[:resignStatus] == 'doing' puts '> 正在签名...' nped = false end if info[:url] != '' then break end sleep 5 end opath = Pathname.new(Dir.pwd).join(opath).cleanpath puts "> 正在下载到 #{ opath }..." `curl #{info[:url]} -o #{opath} -s` end |
#update(path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fir-cli.rb', line 57 def update(path) app = _info path, false, true fir_app = _fir_info app[:identifier] opt_short = [:short] post = {} post[:public] = [:public] != nil ? [:public] : @ipa_config['public'] if opt_short then post[:short] = opt_short end post.each { |i| if i[1] == fir_app[i[0]] then post.delete i[0] end } if post.length == 0 then puts '> 没有可以更新的项目'; return end _fir_put fir_app[:id], post fir_app = _fir_info app[:identifier] if opt_short && opt_short != fir_app[:short] puts "> 短地址 #{ opt_short } 被占用,FIR.im 自动更新短地址为 #{ fir_app[:short] }" end puts "> http://fir.im/#{fir_app[:short]}" end |