fir-cli 1.1.5 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,110 +4,129 @@ module FIR
4
4
  module Publish
5
5
 
6
6
  def publish *args, options
7
- file_path = File.absolute_path(args.first.to_s)
8
- token = options[:token] || current_token
9
- changelog = options[:changelog].to_s
7
+ @file_path = File.absolute_path(args.first.to_s)
8
+ @token = options[:token] || current_token
9
+ @changelog = options[:changelog].to_s
10
+ @short = options[:short].to_s
10
11
 
11
- check_supported_file file_path
12
- check_token_cannot_be_blank token
13
- fetch_user_info(token)
12
+ check_file_exist @file_path
13
+ check_supported_file @file_path
14
+ check_token_cannot_be_blank @token
15
+ fetch_user_info @token
14
16
 
15
17
  logger.info "Publishing app......."
16
18
  logger_info_dividing_line
17
19
 
18
- file_type = File.extname(file_path).delete(".")
19
- @app_info = send("#{file_type}_info", file_path, true)
20
+ file_type = File.extname(@file_path).delete(".")
20
21
 
21
- uploading_info = fetch_uploading_info(type: @app_info[:type],
22
- bundle_id: @app_info[:identifier],
23
- api_token: token)
22
+ @app_info = send("#{file_type}_info", @file_path, true)
23
+ @uploading_info = fetch_uploading_info
24
+ @app_id = @uploading_info[:id]
24
25
 
25
- app_id = uploading_info[:id]
26
- icon_cert = uploading_info[:cert][:icon]
27
- binary_cert = uploading_info[:cert][:binary]
26
+ upload_app
28
27
 
29
- unless @app_info[:icons].blank?
30
- large_icon_path = @app_info[:icons].max_by { |f| File.size(f) }
31
- uncrushed_icon_path = convert_icon(large_icon_path)
32
- upload_app_icon(icon_cert, uncrushed_icon_path)
33
- end
28
+ logger_info_dividing_line
29
+ logger.info "Published succeed: #{fir_api[:domain]}/#{fetch_app_info[:short]}"
34
30
 
35
- uploaded_info = upload_app_binary(binary_cert, file_path, changelog)
31
+ if options[:mappingfile] && options[:proj]
32
+ logger_info_blank_line
36
33
 
37
- if uploaded_info[:is_completed]
38
- unless @app_info[:devices].blank?
39
- upload_device_info(key: binary_cert[:key],
40
- udids: @app_info[:devices].join(","),
41
- api_token: token)
42
- end
34
+ mapping options[:mappingfile], proj: options[:proj],
35
+ build: @app_info[:build],
36
+ version: @app_info[:version],
37
+ token: @token
38
+ end
43
39
 
44
- unless options[:short].blank?
45
- update_app_info(app_id, short: options[:short], api_token: token)
46
- end
40
+ logger_info_blank_line
41
+ end
47
42
 
48
- published_app_info = fetch_app_info(app_id, api_token: token)
43
+ private
44
+
45
+ def upload_app
46
+ @icon_cert = @uploading_info[:cert][:icon]
47
+ @binary_cert = @uploading_info[:cert][:binary]
49
48
 
50
- logger_info_dividing_line
51
- logger.info "Published succeed: #{api[:domain]}/#{published_app_info[:short]}"
49
+ upload_app_icon
50
+ upload_app_binary
51
+ upload_device_info
52
+ update_app_info
52
53
  end
53
- end
54
54
 
55
- private
55
+ def upload_app_icon
56
+ unless @app_info[:icons].blank?
57
+ logger.info "Uploading app's icon......"
56
58
 
57
- def convert_icon origin_path
58
- logger.info "Converting app's icon......"
59
- output_path = Tempfile.new("uncrushed_icon.png").path
59
+ icon_path = @app_info[:icons].max_by { |f| File.size(f) }
60
60
 
61
- Parser.uncrush_icon(origin_path, output_path) if @app_info[:type] == 'ios'
61
+ hash = {
62
+ key: @icon_cert[:key],
63
+ token: @icon_cert[:token],
64
+ file: File.new(icon_path, "rb")
65
+ }
62
66
 
63
- File.size(output_path) == 0 ? origin_path : output_path
64
- end
67
+ uploaded_info = post(@icon_cert[:upload_url], hash)
65
68
 
66
- def upload_app_icon icon_cert, icon_path
67
- logger.info "Uploading app's icon......"
68
- hash = {
69
- key: icon_cert[:key],
70
- token: icon_cert[:token],
71
- file: File.new(icon_path, "rb")
72
- }
73
- post icon_cert[:upload_url], hash
69
+ unless uploaded_info[:is_completed]
70
+ logger.error "Upload app icon failed"
71
+ exit 1
72
+ end
73
+ end
74
74
  end
75
75
 
76
- def upload_app_binary binary_cert, file_path, changelog
76
+ def upload_app_binary
77
77
  logger.info "Uploading app......"
78
+
78
79
  hash = {
79
- key: binary_cert[:key],
80
- token: binary_cert[:token],
81
- file: File.new(file_path, "rb"),
80
+ key: @binary_cert[:key],
81
+ token: @binary_cert[:token],
82
+ file: File.new(@file_path, "rb"),
82
83
  # Custom variables
83
84
  "x:name" => @app_info[:display_name] || @app_info[:name],
84
85
  "x:build" => @app_info[:build],
85
86
  "x:version" => @app_info[:version],
86
- "x:changelog" => changelog,
87
+ "x:changelog" => @changelog,
87
88
  "x:release_type" => @app_info[:release_type],
88
89
  }
89
- post binary_cert[:upload_url], hash
90
+
91
+ uploaded_info = post(@binary_cert[:upload_url], hash)
92
+
93
+ unless uploaded_info[:is_completed]
94
+ logger.error "Upload app binary failed"
95
+ exit 1
96
+ end
90
97
  end
91
98
 
92
- def upload_device_info hash
93
- logger.info "Updating devices info......"
94
- post api[:udids_url], hash
99
+ def upload_device_info
100
+ unless @app_info[:devices].blank?
101
+ logger.info "Updating devices info......"
102
+
103
+ post fir_api[:udids_url], key: @binary_cert[:key],
104
+ udids: @app_info[:devices].join(","),
105
+ api_token: @token
106
+ end
95
107
  end
96
108
 
97
- def update_app_info id, hash
98
- logger.info "Updating app info......"
99
- patch api[:app_url] + "/#{id}", hash
109
+ def update_app_info
110
+ unless @short.blank?
111
+ logger.info "Updating app info......"
112
+
113
+ patch fir_api[:app_url] + "/#{@app_id}", short: @short,
114
+ api_token: @token
115
+ end
100
116
  end
101
117
 
102
- def fetch_uploading_info hash
118
+ def fetch_uploading_info
103
119
  logger.info "Fetching #{@app_info[:identifier]}@FIR.im uploading info......"
104
120
 
105
- post api[:app_url], hash
121
+ post fir_api[:app_url], type: @app_info[:type],
122
+ bundle_id: @app_info[:identifier],
123
+ api_token: @token
106
124
  end
107
125
 
108
- def fetch_app_info id, hash
126
+ def fetch_app_info
109
127
  logger.info "Fetch app info from FIR.im"
110
- get api[:app_url] + "/#{id}", hash
128
+
129
+ get fir_api[:app_url] + "/#{@app_id}", api_token: @token
111
130
  end
112
131
  end
113
132
  end
data/lib/fir/util.rb CHANGED
@@ -1,32 +1,50 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative './util/http'
4
+ require_relative './util/config'
5
+ require_relative './util/parser'
3
6
  require_relative './util/login'
4
7
  require_relative './util/me'
5
8
  require_relative './util/info'
6
9
  require_relative './util/build'
7
10
  require_relative './util/publish'
11
+ require_relative './util/mapping'
8
12
 
9
13
  module FIR
10
14
  module Util
11
-
12
- def self.included base
13
- base.extend ClassMethods
14
- base.extend Login
15
- base.extend Me
16
- base.extend Info
17
- base.extend Build
18
- base.extend Publish
19
- end
15
+ extend ActiveSupport::Concern
20
16
 
21
17
  module ClassMethods
18
+ include FIR::Http
19
+ include FIR::Config
20
+ include FIR::Login
21
+ include FIR::Me
22
+ include FIR::Info
23
+ include FIR::Build
24
+ include FIR::Publish
25
+ include FIR::Mapping
26
+
27
+ attr_accessor :logger
22
28
 
23
29
  def fetch_user_info token
24
- get api[:user_url], api_token: token
30
+ get fir_api[:user_url], api_token: token
31
+ end
32
+
33
+ def fetch_user_uuid token
34
+ user_info = fetch_user_info(token)
35
+ user_info[:uuid]
36
+ end
37
+
38
+ def check_file_exist path
39
+ unless File.file?(path)
40
+ logger.error "File does not exist"
41
+ exit 1
42
+ end
25
43
  end
26
44
 
27
45
  def check_supported_file path
28
- unless File.file?(path) || APP_FILE_TYPE.include?(File.extname(path))
29
- logger.error "File does not exist or unsupported file type"
46
+ unless APP_FILE_TYPE.include?(File.extname(path))
47
+ logger.error "Unsupported file type"
30
48
  exit 1
31
49
  end
32
50
  end
@@ -45,6 +63,10 @@ module FIR
45
63
  end
46
64
  end
47
65
 
66
+ def logger_info_blank_line
67
+ logger.info ""
68
+ end
69
+
48
70
  def logger_info_dividing_line
49
71
  logger.info "✈ -------------------------------------------- ✈"
50
72
  end
data/lib/fir/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module FIR
4
- VERSION = "1.1.5"
4
+ VERSION = "1.1.7"
5
5
  end
data/lib/fir.rb CHANGED
@@ -23,83 +23,5 @@ require 'fir/version'
23
23
  require 'fir/cli'
24
24
 
25
25
  module FIR
26
- CONFIG_PATH = "#{ENV['HOME']}/.fir-cli"
27
- API_YML_PATH = "#{File.dirname(__FILE__)}/fir/api.yml"
28
- APP_FILE_TYPE = %w(.ipa .apk).freeze
29
-
30
26
  include Util
31
-
32
- class << self
33
- attr_accessor :logger, :api, :config
34
-
35
- def api
36
- @api ||= YAML.load_file(API_YML_PATH).symbolize_keys
37
- end
38
-
39
- def config
40
- @config ||= YAML.load_file(CONFIG_PATH).symbolize_keys if File.exist?(CONFIG_PATH)
41
- end
42
-
43
- def reload_config
44
- @config = YAML.load_file(CONFIG_PATH).symbolize_keys
45
- end
46
-
47
- def write_config hash
48
- File.open(CONFIG_PATH, 'w+') { |f| f << YAML.dump(hash) }
49
- end
50
-
51
- def current_token
52
- @token ||= config[:token] if config
53
- end
54
-
55
- def get url, params = {}
56
- begin
57
- res = RestClient.get(url, default_headers.merge(params: params))
58
- rescue => e
59
- logger.error "#{e.class}\n#{e.message}"
60
- exit 1
61
- end
62
-
63
- JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
64
- end
65
-
66
- def post url, query
67
- begin
68
- res = RestClient.post(url, query, default_headers)
69
- rescue => e
70
- logger.error "#{e.class}\n#{e.message}"
71
- exit 1
72
- end
73
-
74
- JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
75
- end
76
-
77
- def patch url, query
78
- begin
79
- res = RestClient.patch(url, query, default_headers)
80
- rescue => e
81
- logger.error "#{e.class}\n#{e.message}"
82
- exit 1
83
- end
84
-
85
- JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
86
- end
87
-
88
- def put url, query
89
- begin
90
- res = RestClient.put(url, query, default_headers)
91
- rescue => e
92
- logger.error "#{e.class}\n#{e.message}"
93
- exit 1
94
- end
95
-
96
- JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
97
- end
98
-
99
- def default_headers
100
- { content_type: :json, source: 'fir-cli', cli_version: FIR::VERSION }
101
- end
102
-
103
- alias_method :☠, :exit
104
- end
105
27
  end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ class BuildIpaTest < Minitest::Test
4
+
5
+ def test_build_ipa
6
+ # Only for OSX
7
+ assert true
8
+ end
9
+ end
Binary file
@@ -0,0 +1 @@
1
+ this is a text
Binary file
data/test/info_test.rb ADDED
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ class InfoTest < Minitest::Test
4
+
5
+ def test_apk_info
6
+ info = FIR.apk_info(default_apk, true)
7
+
8
+ assert_equal 'android', info[:type]
9
+ assert_equal 'com.bughd.myapplication', info[:identifier]
10
+ assert_equal 'My Application', info[:name]
11
+ assert_equal '1', info[:build]
12
+ assert_equal '1.0', info[:version]
13
+
14
+ assert_equal true, File.exist?(info[:icons].first)
15
+
16
+ assert FIR.info(default_apk, {})
17
+ end
18
+
19
+ def test_ipa_info
20
+ info = FIR.ipa_info(default_ipa, true)
21
+
22
+ assert_equal 'ios', info[:type]
23
+ assert_equal 'im.fir.build-ipa', info[:identifier]
24
+ assert_equal 'build_ipa', info[:name]
25
+ assert_equal '1', info[:build]
26
+ assert_equal '1.0', info[:version]
27
+
28
+ # Only for OSX
29
+ # assert_equal nil, info[:display_name]
30
+ # assert_equal default_device_udid, info[:devices].first
31
+ # assert_equal 'adhoc', info[:release_type]
32
+ # assert_equal default_distribution_name, info[:distribution_name]
33
+
34
+ assert_equal true, info[:plist].is_a?(Hash)
35
+ assert_equal true, info[:mobileprovision].is_a?(Hash)
36
+
37
+ assert FIR.info(default_ipa, {})
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ class LoginTest < Minitest::Test
4
+
5
+ def test_login
6
+ user_info = FIR.fetch_user_info(default_token)
7
+
8
+ assert_equal default_email, user_info.fetch(:email, '')
9
+
10
+ assert FIR.login(default_token)
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ class MappingTest < Minitest::Test
4
+
5
+ def test_mapping
6
+ options = {
7
+ token: default_token,
8
+ version: '1.1',
9
+ build: '1'
10
+ }
11
+
12
+ assert FIR.mapping(default_dsym_mapping, options.merge(proj: default_bughd_project_ios_id))
13
+ assert FIR.mapping(default_txt_mapping, options.merge(proj: default_bughd_project_android_id))
14
+ end
15
+ end
data/test/me_test.rb ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ class MeTest < Minitest::Test
4
+
5
+ def test_me
6
+ user_info = FIR.fetch_user_info(default_token)
7
+
8
+ FIR.write_config(email: user_info.fetch(:email, ''), token: default_token)
9
+ FIR.reload_config
10
+
11
+ me_info = FIR.fetch_user_info(FIR.current_token)
12
+
13
+ assert_equal default_email, me_info.fetch(:email, '')
14
+
15
+ assert FIR.me
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ class PublishTest < Minitest::Test
4
+
5
+ def test_publish
6
+ options = {
7
+ token: default_token,
8
+ changelog: "test from fir-cli #{Time.now.to_i}"
9
+ }
10
+
11
+ assert FIR.publish(default_ipa, options)
12
+ assert FIR.publish(default_apk, options)
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/autorun'
4
+ require 'fir'
5
+
6
+ FIR.logger = Logger.new(STDOUT)
7
+
8
+ class Minitest::Test
9
+
10
+ def default_token
11
+ '2dd8a99ef9d19c540bb583624b939960'
12
+ end
13
+
14
+ def default_email
15
+ 'fir-cli_test@fir.im'
16
+ end
17
+
18
+ def default_apk
19
+ File.expand_path('../cases', __FILE__) + '/test_apk.apk'
20
+ end
21
+
22
+ def default_ipa
23
+ File.expand_path('../cases', __FILE__) + '/test_ipa.ipa'
24
+ end
25
+
26
+ def default_bughd_project_ios_id
27
+ '55bb2839692d647a46000004'
28
+ end
29
+
30
+ def default_bughd_project_android_id
31
+ '55be454a692d351278000002'
32
+ end
33
+
34
+ def default_dsym_mapping
35
+ File.expand_path('../cases', __FILE__) + '/test_ipa_dsym'
36
+ end
37
+
38
+ def default_txt_mapping
39
+ File.expand_path('../cases', __FILE__) + '/test_apk_txt'
40
+ end
41
+
42
+ def default_device_udid
43
+ "cf8b87e3f469d7b185fd64c057778aecbc2017a6"
44
+ end
45
+
46
+ def default_distribution_name
47
+ 'iOSTeam Provisioning Profile: im.fir.* - Fly It Remotely LLC.'
48
+ end
49
+ 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: 1.1.5
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - FIR.im
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-23 00:00:00.000000000 Z
12
+ date: 2015-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '5.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.10'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.10'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: thor
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +131,7 @@ executables:
117
131
  extensions: []
118
132
  extra_rdoc_files: []
119
133
  files:
134
+ - ".codeclimate.yml"
120
135
  - ".gitignore"
121
136
  - ".travis.yml"
122
137
  - CHANGELOG
@@ -131,21 +146,32 @@ files:
131
146
  - lib/fir/api.yml
132
147
  - lib/fir/cli.rb
133
148
  - lib/fir/patches.rb
134
- - lib/fir/patches/bin/pngcrush
149
+ - lib/fir/patches/concern.rb
135
150
  - lib/fir/patches/native_patch.rb
136
151
  - lib/fir/patches/os_patch.rb
137
- - lib/fir/patches/parser_patch.rb
138
152
  - lib/fir/util.rb
139
153
  - lib/fir/util/build.rb
154
+ - lib/fir/util/config.rb
155
+ - lib/fir/util/http.rb
140
156
  - lib/fir/util/info.rb
141
157
  - lib/fir/util/login.rb
158
+ - lib/fir/util/mapping.rb
142
159
  - lib/fir/util/me.rb
160
+ - lib/fir/util/parser.rb
143
161
  - lib/fir/util/publish.rb
144
162
  - lib/fir/version.rb
145
163
  - lib/fir_cli.rb
164
+ - test/build_ipa_test.rb
146
165
  - test/cases/test_apk.apk
166
+ - test/cases/test_apk_txt
147
167
  - test/cases/test_ipa.ipa
148
- - test/fir_cli_test.rb
168
+ - test/cases/test_ipa_dsym
169
+ - test/info_test.rb
170
+ - test/login_test.rb
171
+ - test/mapping_test.rb
172
+ - test/me_test.rb
173
+ - test/publish_test.rb
174
+ - test/test_helper.rb
149
175
  homepage: http://blog.fir.im/fir_cli
150
176
  licenses:
151
177
  - MIT
@@ -153,9 +179,14 @@ metadata: {}
153
179
  post_install_message: "\n ______________ ________ ____\n /
154
180
  ____/ _/ __ \\ / ____/ / / _/\n / /_ / // /_/ /_____/ / / / /
155
181
  /\n / __/ _/ // _, _/_____/ /___/ /____/ /\n /_/ /___/_/ |_| \\____/_____/___/\n\n
156
- \ ## 更新记录\n ### FIR-CLI 1.1.5\n - 完全兼容新版 API ✔\n - 请使用新版 API Token\n - 新版 API
157
- Token 查看地址: `http://fir.im/user/info`\n - 增加 `fir me` 指令查看当前登录用户\n - 增加团队成员直接上传
158
- app\n - https://github.com/FIRHQ/fir-cli\n "
182
+ \ ## 更新记录\n ### FIR-CLI 1.1.7\n - 完全兼容新版 API ✔\n - 请使用新版 API Token\n - 新版 API
183
+ Token 查看地址: `http://fir.im/user/info`\n - 增加符号表上传指令, `fir mapping(alias m)`\n -
184
+ 有以下三种方式上传符号表(目前已经支持 dSYM 和 txt 两种格式的符号表文件上传)\n - 1. 指定 version 和 build 上传: `fir
185
+ m <mapping file path> -P <bughd project id> -v <app version> -b <app build> -T <your
186
+ api token>`\n - 2. 在 publish 的时候自动上传: `fir p <app file path> -m <mapping file
187
+ path> -P <bughd project id> -T <your api token>`\n - 3. 在 build_ipa 的时候自动上传:
188
+ `fir b <project dir> -P <bughd project id> -M -p -T <your api token>`\n - https://github.com/FIRHQ/fir-cli\n
189
+ \ "
159
190
  rdoc_options: []
160
191
  require_paths:
161
192
  - lib
@@ -176,6 +207,14 @@ signing_key:
176
207
  specification_version: 4
177
208
  summary: FIR.im command tool
178
209
  test_files:
210
+ - test/build_ipa_test.rb
179
211
  - test/cases/test_apk.apk
212
+ - test/cases/test_apk_txt
180
213
  - test/cases/test_ipa.ipa
181
- - test/fir_cli_test.rb
214
+ - test/cases/test_ipa_dsym
215
+ - test/info_test.rb
216
+ - test/login_test.rb
217
+ - test/mapping_test.rb
218
+ - test/me_test.rb
219
+ - test/publish_test.rb
220
+ - test/test_helper.rb
Binary file