fir-cli 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fir-cli.rb +77 -22
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7542e6029327b193019ad292029cda16611bb3df
4
- data.tar.gz: a8211154ff64bd79f1111a4530bcf304a8a3516a
3
+ metadata.gz: 57e26467b901310219bb57a2b199da8f27aff22e
4
+ data.tar.gz: 9acdc07d57db5c388e9cc7b7aaff1123d4ce25e2
5
5
  SHA512:
6
- metadata.gz: 594509c71c4ef5933ceb9e80bbfed36dcb03971ece925301256da6a370e445d10728de088d6a8cc41255a68e5a4265b9b9d978182f0e1c0e84d6e0cb206440f0
7
- data.tar.gz: ad35e24c12be9f02ee2335c4639736e85dd09be297192b4d42c0f01c951b4d6d372d44284643e2d1ccbec582b960b0bfde7c8ad0614ab31c82717848016dfb92
6
+ metadata.gz: d70acc52ac8ef678d5f8ed17d4760b5a5b201fa721796412cbc0ada45fdd45cfb85ad0e886c61051d6328fc7ddbc3b6f66ab1554b6ec9ad583b5df58b602f25e
7
+ data.tar.gz: a8ed609c3a197976fb6c4d102e1908bc2cc2711febfaacd12e90d1eedab4092670db2b31afa3106964cdd6170a76aeb1a36ea5bad9de433c54c8dcb96f8d061b
data/lib/fir-cli.rb CHANGED
@@ -12,6 +12,7 @@ require 'rest_client'
12
12
  require 'lagunitas'
13
13
  require 'lagunitas.patch'
14
14
  require 'lagunitas.ext'
15
+ require 'ruby_apk'
15
16
 
16
17
  # p Lagunitas::App.new('').respond_to? :mobileprovision
17
18
 
@@ -20,7 +21,8 @@ class FirCli < Thor
20
21
  super
21
22
  @uconfig = UserConfig.new '.fir'
22
23
  @ipa_config = @uconfig['ipa.yaml']
23
- if @ipa_config['resign'] == nil then @ipa_config['resign'] = false end
24
+ @ipa_config['resign'] = false if @ipa_config['resign'] == nil
25
+ @tmpfiles = []
24
26
  end
25
27
 
26
28
  desc 'login USER_TOKEN', '以 USER_TOKEN 身份登陆'
@@ -55,19 +57,18 @@ class FirCli < Thor
55
57
  option :short, :aliases => '-s', :desc => '自定义短地址'
56
58
  option :token, :aliases => '-t', :desc => '用户令牌,不写则使用已经登陆信息'
57
59
  def update(path)
58
- app = _info path, false, true
59
- fir_app = _fir_info app[:identifier]
60
+ app = _info path
61
+ fir_app = _fir_info app[:identifier], app[:type]
60
62
  opt_short = options[:short]
61
63
  post = {}
62
- post[:public] = options[:public] != nil ? options[:public] : @ipa_config['public']
63
- if opt_short then post[:short] = opt_short end
64
+ post[:short] = opt_short if opt_short
64
65
 
65
- post.each { |i| if i[1] == fir_app[i[0]] then post.delete i[0] end }
66
+ post.each { |i| post.delete i[0] if i[1] == fir_app[i[0]] }
66
67
 
67
68
  if post.length == 0 then puts '> 没有可以更新的项目'; return end
68
69
  _fir_put fir_app[:id], post
69
70
 
70
- fir_app = _fir_info app[:identifier]
71
+ fir_app = _fir_info app[:identifier], app[:type]
71
72
  if opt_short && opt_short != fir_app[:short]
72
73
  puts "> 短地址 #{ opt_short } 被占用,FIR.im 自动更新短地址为 #{ fir_app[:short] }"
73
74
  end
@@ -80,13 +81,13 @@ class FirCli < Thor
80
81
  option :token, :aliases => '-t', :desc => '用户令牌,不写则使用已经登陆信息'
81
82
  option :changelog, :aliases => '-c', :desc => '修改纪录,默认为空字符串', :default => ''
82
83
  def publish(path)
83
- if _opt_resign
84
+ if _opt_resign && _is_ipa(path)
84
85
  tfile = Tempfile.new SecureRandom.hex
85
86
  resign path, tfile.path
86
87
  path = tfile.path
87
88
  end
88
- app = _info path
89
- fir_app = _fir_info app[:identifier]
89
+ app = _info path, false, true
90
+ fir_app = _fir_info app[:identifier], app[:type]
90
91
 
91
92
  id = fir_app[:id]
92
93
  short = fir_app[:short]
@@ -104,8 +105,10 @@ class FirCli < Thor
104
105
  if app[:icons] != nil
105
106
  icon_path = app[:icons][0][:path]
106
107
 
107
- puts '> 转换图标...'
108
- Pngdefry.defry icon_path, icon_path
108
+ if _is_ipa path
109
+ puts '> 转换图标...'
110
+ Pngdefry.defry icon_path, icon_path
111
+ end
109
112
 
110
113
  puts "> 上传图标..."
111
114
  RestClient.post bundle_icon[:url],
@@ -113,7 +116,7 @@ class FirCli < Thor
113
116
  :token => bundle_icon[:token],
114
117
  :file => File.new(icon_path, 'rb')
115
118
 
116
- puts '上传图标成功'
119
+ puts '> 上传图标成功'
117
120
  end
118
121
 
119
122
  _fir_put fir_app[:id],
@@ -140,7 +143,7 @@ class FirCli < Thor
140
143
  app = _info path, false, options['verbose']
141
144
  app.each { |i| puts "#{ Paint[i[0].to_s.rjust(15), :blue] } #{ i[1] }" }
142
145
  if options[:fir]
143
- fir_app = _fir_info app[:identifier]
146
+ fir_app = _fir_info app[:identifier], app[:type]
144
147
  fir_app.each { |i| puts "#{ Paint[i[0].to_s.rjust(15), :blue] } #{ i[1] }" }
145
148
  end
146
149
  end
@@ -190,7 +193,7 @@ class FirCli < Thor
190
193
  puts '> 正在签名...'
191
194
  nped = false
192
195
  end
193
- if info[:url] != '' then break end
196
+ break if info[:url] != ''
194
197
  sleep 5
195
198
  end
196
199
  opath = Pathname.new(Dir.pwd).join(opath).cleanpath
@@ -199,12 +202,48 @@ class FirCli < Thor
199
202
  end
200
203
 
201
204
  private
202
- def _info(path, quiet = false, more = false)
205
+ def _path(path)
203
206
  path = Pathname.new(Dir.pwd).join(path).cleanpath
207
+ end
208
+ def _info(path, quiet = false, more = false, bin = false)
209
+ if _is_ipa path
210
+ _ipa_info path, quiet, more
211
+ elsif _is_apk path
212
+ _apk_info path, quiet, more
213
+ else
214
+ puts Paint['! 只能支持后缀为 ipa 和 apk 地文件', :red]
215
+ end
216
+ end
217
+ def _apk_info(path, quiet = false, more = false)
218
+ path = _path path
219
+ apk = Android::Apk.new path
220
+ info = {
221
+ :type => 'android',
222
+ :identifier => apk.manifest.package_name,
223
+ :name => apk.label,
224
+ :version => apk.manifest.version_code,
225
+ :short_version => apk.manifest.version_name
226
+ }
227
+ if more
228
+ info[:icons] = apk.icon.map do |name, data|
229
+ tfile = Tempfile.new SecureRandom.hex
230
+ tfile.write data
231
+ @tmpfiles.push tfile
232
+ {
233
+ :name => File.basename(name),
234
+ :path => tfile.path
235
+ }
236
+ end
237
+ end
238
+ info
239
+ end
240
+ def _ipa_info(path, quiet = false, more = false, bin = false)
241
+ path = _path path
204
242
  ipa = Lagunitas::IPA.new path
205
- if !quiet then puts '> 正在解析 ipa 文件...' end
243
+ puts '> 正在解析 ipa 文件...' if !quiet
206
244
  app = ipa.app
207
245
  info = {
246
+ :type => 'ios',
208
247
  :identifier => app.identifier,
209
248
  :name => app.name,
210
249
  :display_name => app.display_name,
@@ -215,20 +254,29 @@ class FirCli < Thor
215
254
  # :distribution_name => app.distribution_name
216
255
  }
217
256
  if more
218
- info[:icons] = app.icons
257
+ info[:icons] = app.icons.map do |icon|
258
+ tfile = Tempfile.new SecureRandom.hex
259
+ @tmpfiles.push tfile
260
+ File.copy icon[:path], tfile.path
261
+ {
262
+ :name => File.basename(icon[:path]),
263
+ :path => tfile.path
264
+ }
265
+ end
219
266
  info[:plist] = app.info
220
267
  end
221
268
  ipa.cleanup
222
269
  info
223
270
  end
224
- def _fir_info(identifier, quiet = false)
271
+ def _fir_info(identifier, type = 'ios', quiet = false)
225
272
  if !_opt_token
226
273
  puts Paint['! 您还没有登录', :red]
227
274
  puts Paint['! 请 fir login USER_TOKEN 登录', :green]
228
275
  exit
229
276
  end
230
277
  body = { :token => @token }
231
- if !quiet then puts '> 正在获取 fir 的应用信息...' end
278
+ body[:type] = type
279
+ puts '> 正在获取 fir 的应用信息...' if !quiet
232
280
  res = RestClient.get "http://fir.im/api/v2/app/info/#{identifier}?#{URI.encode_www_form body}"
233
281
  JSON.parse res.body, :symbolize_names => true
234
282
  end
@@ -239,7 +287,7 @@ class FirCli < Thor
239
287
  exit
240
288
  end
241
289
  body[:token] = @token
242
- if !quiet then puts '> 正在更新 fir 的应用信息...' end
290
+ puts '> 正在更新 fir 的应用信息...' if !quiet
243
291
  RestClient.put "http://fir.im/api/v2/app/#{id}?#{URI.encode_www_form body}", body
244
292
  puts '> 更新成功'
245
293
  end
@@ -250,7 +298,7 @@ class FirCli < Thor
250
298
  exit
251
299
  end
252
300
  body[:token] = @token
253
- if !quiet then puts '> 正在更新 fir 的应用版本信息...' end
301
+ puts '> 正在更新 fir 的应用版本信息...' if !quiet
254
302
  RestClient.put "http://fir.im/api/v2/appVersion/#{id}/complete?#{URI.encode_www_form body}", body
255
303
  puts '> 更新成功'
256
304
  end
@@ -261,6 +309,13 @@ class FirCli < Thor
261
309
  @email = options[:email] || @ipa_config['email'] || nil
262
310
  end
263
311
  def _opt_resign
312
+ return options[:resign] if defined? options[:resign]
264
313
  @resign = options[:resign] || @ipa_config['resign'] || nil
265
314
  end
315
+ def _is_ipa(path)
316
+ /\.ipa$/.match path
317
+ end
318
+ def _is_apk(path)
319
+ /\.apk$/.match path
320
+ end
266
321
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fir-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yan
@@ -94,7 +94,21 @@ dependencies:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.19.1
97
- description: FIR.im 命令行工具
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby_apk
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.1
111
+ description: FIR.im 命令行工具,支持 ios 和 android
98
112
  email: idy0013@gmail.com
99
113
  executables:
100
114
  - fir