Class: Fir::Cli
- Inherits:
-
Thor
- Object
- Thor
- Fir::Cli
- Defined in:
- lib/fir-cli.core.ext.rb,
lib/fir-cli.utils.ext.rb,
lib/fir-cli-commands/info.rb,
lib/fir-cli-commands/login.rb,
lib/fir-cli-commands/config.rb,
lib/fir-cli-commands/resign.rb,
lib/fir-cli-commands/publish.rb,
lib/fir-cli-commands/upgrade.rb
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #info(path) ⇒ Object
-
#initialize(*args) ⇒ Cli
constructor
A new instance of Cli.
- #login ⇒ Object
- #publish(path) ⇒ Object
- #resign(ipath, opath) ⇒ Object
- #upgrade ⇒ Object
Constructor Details
#initialize(*args) ⇒ Cli
Returns a new instance of Cli.
3 4 5 6 7 |
# File 'lib/fir-cli.utils.ext.rb', line 3 def initialize(*args) super _init_config _puts_welcome end |
Class Method Details
.find_extends ⇒ Object
8 9 10 11 12 13 |
# File 'lib/fir-cli.utils.ext.rb', line 8 def self.find_extends `gem list --local` .each_line("\n") .map { |gem| /^[^\s]+/.match(gem)[0] } .select { |gem| true if gem.start_with? 'fir-cli-' } end |
Instance Method Details
#config ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fir-cli-commands/config.rb', line 9 def config if .length > 0 .each do |option| puts "> #{ Paint[option[0].to_s.rjust(10), :blue] } : #{ @config[option[0].to_s] } => #{ option[1] }" @config[option[0].to_s] = option[1] end if @config['token'] && !_user(@config['token']) _puts_invalid_token exit 1 end @config.save end puts '> 设置完成,您现在使用的设置是' @config.each {|conf| puts "> #{ Paint[conf[0].to_s.rjust(10), :blue] } => #{ conf[1] }"} end |
#info(path) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/fir-cli-commands/info.rb', line 8 def info(path) app = _info path, [:all] app.each { |i| puts "#{ Paint[i[0].to_s.rjust(18), :blue] } #{ i[1] }" } if [:fir] fir_app = _fir_info app[:identifier], app[:type] fir_app.each { |i| puts "#{ Paint[i[0].to_s.rjust(18), :blue] } #{ i[1] }" } end end |
#login ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fir-cli-commands/login.rb', line 6 def login token = _prompt_secret('输入你的用户 token:') if token.empty? _puts_require_token exit 1 end user = _user token if !user _puts_invalid_token exit 1 end if _opt_token && _opt_token != token _puts "> 已登陆用户: #{ _opt_token }" _puts "> 替换为用户: #{ token }" end if user[:email] _puts "> 设置用户邮件地址为: #{ user[:email] }" @config['email'] = user[:email] end @config['token'] = token @config.save _puts "> 当前登陆用户为:#{ token }" end |
#publish(path) ⇒ Object
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 41 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/fir-cli-commands/publish.rb', line 10 def publish(path) if _opt_resign && _is_ipa(path) tfile = Tempfile.new ["resign-#{ SecureRandom.hex }", '.ipa'] resign path, tfile.path path = tfile.path end app = _info path, true fir_app = _fir_info app[:identifier], app[:type] id = fir_app[:id] short = fir_app[:short] bundle_app = fir_app[:bundle][:pkg] bundle_icon = fir_app[:bundle][:icon] if app[:icons] != nil && app[:icons].length > 0 icon_path = app[:icons][0][:path] if _is_ipa path _puts '> 转换图标...' Pngdefry.defry icon_path, icon_path end _puts "> 上传图标..." RestClient.post bundle_icon[:url], :key => bundle_icon[:key], :token => bundle_icon[:token], :file => File.new(icon_path, 'rb') _puts '> 上传图标成功' end _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 _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
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 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 |
# File 'lib/fir-cli-commands/resign.rb', line 7 def resign(ipath, opath) _puts "! #{ Paint['resign.tapbeta.com 签名服务风险提示', :red] }" _puts '! tapbeta 无法保证签名证书的长期有效性,苹果随时可' _puts '! 能封杀他们的企业账号,所有由这个企业账号签发的证' _puts '! 书都会失效。你如果使用该网站提供的证书进行应用签' _puts "! 发,请注意:#{ Paint['当证书失效后,所有通过已失效证书签名', :red ] }" _puts "! #{ Paint['的应用都会无法正常运行;同时托管在 fir.im 的应用', :red ] }" _puts "! #{ Paint['将无法正常安装。', :red ] }" if _opt_email == nil @email = _prompt '请输入你的邮件地址:' if !@email || @email.length == 0 _puts "! #{ Paint['你需要提供邮件地址才能使用 resign.tapbeta.com 的', :red] }" _puts "! #{ Paint['签名服务, 请使用', :red] } fir config --email=EMAIL #{ Paint['进行设', :red] }" _puts "! #{ Paint['置', :red] }" exit 1 elsif !_is_email @email _puts_invalid_email exit 1 end end if !/\.ipa$/.match ipath _puts Paint['! 只能给以 ipa 为扩展名的文件签名', :red] exit 1 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 '> 正在上传...' res = RestClient.post tapbeta[:tb_upload_url], form # Upyun's notify is fucking, handle it specific # if tapbeta[:tb_upload_url].include? 'upyun' # RestClient.get "#{ form[:'notify-url'] }?#{ URI.encode_www_form JSON.parse res.body }" # end _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 break if info[:url] != '' sleep 5 end opath = Pathname.new(Dir.pwd).join(opath).cleanpath _puts "> 正在下载到 #{ opath }..." `curl #{ info[:url] } -o #{ opath } -s` end |
#upgrade ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/fir-cli-commands/upgrade.rb', line 6 def upgrade _puts '> gem update fir-cli' `gem update fir-cli` _extends.each do |gem| _puts "> gem update #{ gem }" `gem update #{ gem }` end end |