sigh 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db85e11943b178f32aadb154d095505508646da2
4
- data.tar.gz: fe0d2b97fcc0338630c738815211dc42cd370f2c
3
+ metadata.gz: b5999ae3911bed107f327d8beef03e61407c6493
4
+ data.tar.gz: 04564599bd5c894b8e63fbcda115b7fc3473c068
5
5
  SHA512:
6
- metadata.gz: b9207d6283508a3de3f7e55901a891abd8a943f7f0fa7422521c10c4b7c6907cbdb9f7ca1e0f278211ecec286b0de53ab86623344f40da84652faa5bce911fe4
7
- data.tar.gz: 9e7deaf7f2f3f3f1213144fce7e06a140b8761566ae5eb01445e659a7821858d4f954288acc8012cd8bb9ed6c762660070c3f3f19419ab34b032a87c17454847
6
+ metadata.gz: 54981675f063943ed973b25392e5a8717094573e19e70753af97b736e36c223134e72fb7b3787cbc65d67fa478eb9a9af75df4840f1727f978091ba9e1faa5f6
7
+ data.tar.gz: afaffef16c71115c3fd0a3202807c76e7a245522d90505981c3041b077cd157fb2dbe2e77fdcee6ff1cf4813838d249a88c01756019a7fb553e1ea54d72ae064
data/bin/sigh CHANGED
@@ -43,13 +43,13 @@ class SighApplication
43
43
  app = app_identifier(options)
44
44
  username(options)
45
45
 
46
- type = Sigh::DeveloperCenter::APPSTORE
47
- type = Sigh::DeveloperCenter::ADHOC if options.adhoc
48
- type = Sigh::DeveloperCenter::DEVELOPMENT if options.development
46
+ type = FastlaneCore::DeveloperCenter::APPSTORE
47
+ type = FastlaneCore::DeveloperCenter::ADHOC if options.adhoc
48
+ type = FastlaneCore::DeveloperCenter::DEVELOPMENT if options.development
49
49
 
50
50
  ENV['SIGH_CERTIFICATE'] = options.cert_owner if options.cert_owner
51
51
 
52
- path = Sigh::DeveloperCenter.new.run(app, type, options.cert_name, options.force, options.cert_date)
52
+ path = FastlaneCore::DeveloperCenter.new.run(app, type, options.cert_name, options.force, options.cert_date)
53
53
 
54
54
  if path
55
55
  file_name = options.filename || File.basename(path)
@@ -1,18 +1,15 @@
1
- require 'json'
2
1
  require 'sigh/version'
3
- require 'sigh/helper'
4
2
  require 'sigh/dependency_checker'
5
3
  require 'sigh/developer_center'
6
- require 'sigh/update_checker'
7
4
  require 'sigh/resign'
8
5
 
9
- # Third Party code
10
- require 'colored'
11
- require 'phantomjs/poltergeist'
6
+ require 'fastlane_core'
12
7
 
13
8
  module Sigh
14
- TMP_FOLDER = "/tmp/sigh/"
9
+ Helper = FastlaneCore::Helper # you gotta love Ruby: Helper.* should use the Helper class contained in FastlaneCore
15
10
 
16
- Sigh::UpdateChecker.verify_latest_version
11
+ ENV['FASTLANE_TEAM_ID'] ||= ENV["SIGH_TEAM_ID"]
12
+
13
+ FastlaneCore::UpdateChecker.verify_latest_version('sigh', Sigh::VERSION)
17
14
  DependencyChecker.check_dependencies
18
15
  end
@@ -1,178 +1,24 @@
1
- require 'credentials_manager/password_manager'
2
- require 'open-uri'
3
- require 'openssl'
1
+ require 'fastlane_core/developer_center/developer_center'
4
2
 
5
- require 'capybara'
6
- require 'capybara/poltergeist'
7
- require 'phantomjs/poltergeist'
8
-
9
- module Sigh
3
+ module FastlaneCore
10
4
  class DeveloperCenter
11
- # This error occurs only if there is something wrong with the given login data
12
- class DeveloperCenterLoginError < StandardError
13
- end
14
-
15
- # This error can occur for many reaons. It is
16
- # usually raised when a UI element could not be found
17
- class DeveloperCenterGeneralError < StandardError
18
- end
19
-
20
5
  # Types of certificates
21
6
  APPSTORE = "AppStore"
22
7
  ADHOC = "AdHoc"
23
8
  DEVELOPMENT = "Development"
24
9
 
25
- include Capybara::DSL
26
-
27
- DEVELOPER_CENTER_URL = "https://developer.apple.com/devcenter/ios/index.action"
28
- PROFILES_URL = "https://developer.apple.com/account/ios/profile/profileList.action?type=production"
29
10
  PROFILES_URL_DEV = "https://developer.apple.com/account/ios/profile/profileList.action?type=limited"
30
11
 
31
-
32
- def initialize
33
- FileUtils.mkdir_p TMP_FOLDER
34
-
35
- Capybara.run_server = false
36
- Capybara.default_driver = :poltergeist
37
- Capybara.javascript_driver = :poltergeist
38
- Capybara.current_driver = :poltergeist
39
- Capybara.app_host = DEVELOPER_CENTER_URL
40
-
41
- # Since Apple has some SSL errors, we have to configure the client properly:
42
- # https://github.com/ariya/phantomjs/issues/11239
43
- Capybara.register_driver :poltergeist do |a|
44
- conf = ['--debug=no', '--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1']
45
- Capybara::Poltergeist::Driver.new(a, {
46
- phantomjs: Phantomjs.path,
47
- phantomjs_options: conf,
48
- phantomjs_logger: File.open("#{TMP_FOLDER}/poltergeist_log.txt", "a"),
49
- js_errors: false
50
- })
51
- end
52
-
53
- page.driver.headers = { "Accept-Language" => "en" }
54
-
55
- self.login
56
- end
57
-
58
- # Loggs in a user with the given login data on the Dev Center Frontend.
59
- # You don't need to pass a username and password. It will
60
- # Automatically be fetched using the {CredentialsManager::PasswordManager}.
61
- # This method will also automatically be called when triggering other
62
- # actions like {#open_app_page}
63
- # @param user (String) (optional) The username/email address
64
- # @param password (String) (optional) The password
65
- # @return (bool) true if everything worked fine
66
- # @raise [DeveloperCenterGeneralError] General error while executing
67
- # this action
68
- # @raise [DeveloperCenterLoginError] Login data is wrong
69
- def login(user = nil, password = nil)
70
- begin
71
- Helper.log.info "Login into iOS Developer Center"
72
-
73
- user ||= CredentialsManager::PasswordManager.shared_manager.username
74
- password ||= CredentialsManager::PasswordManager.shared_manager.password
75
-
76
- result = visit PROFILES_URL
77
- raise "Could not open Developer Center" unless result['status'] == 'success'
78
-
79
- # Already logged in
80
- return true if page.has_content? "Member Center"
81
-
82
- (wait_for_elements(".button.blue").first.click rescue nil) # maybe already logged in
83
-
84
- (wait_for_elements('#accountpassword') rescue nil) # when the user is already logged in, this will raise an exception
85
-
86
- # Already logged in
87
- return true if page.has_content? "Member Center"
88
-
89
- fill_in "accountname", with: user
90
- fill_in "accountpassword", with: password
91
-
92
- all(".button.large.blue.signin-button").first.click
93
-
94
- begin
95
- # If the user is not on multiple teams
96
- select_team if page.has_content? "Select Team"
97
- rescue => ex
98
- Helper.log.debug ex
99
- raise DeveloperCenterLoginError.new("Error loggin in user #{user}. User is on multiple teams and we were unable to correctly retrieve them.")
100
- end
101
-
102
- begin
103
- wait_for_elements('.ios.profiles.gridList')
104
- visit PROFILES_URL # again, since after the login, the dev center loses the production GET value
105
- rescue => ex
106
- Helper.log.debug ex
107
- if page.has_content?"Getting Started"
108
- raise "There was no valid signing certificate found. Please log in and follow the 'Getting Started guide' on '#{current_url}'".red
109
- else
110
- raise DeveloperCenterLoginError.new("Error logging in user #{user} with the given password. Make sure you entered them correctly.")
111
- end
112
- end
113
-
114
-
115
- Helper.log.info "Login successful"
116
-
117
- true
118
- rescue => ex
119
- error_occured(ex)
120
- end
121
- end
122
-
123
-
124
- def select_team
125
- team_id = ENV["SIGH_TEAM_ID"]
126
- team_id = nil if team_id.to_s.length == 0
127
-
128
- unless team_id
129
- Helper.log.info "You can store you preferred team using the environment variable `SIGH_TEAM_ID`".green
130
- Helper.log.info "Your ID belongs to the following teams:".green
131
- end
132
-
133
- available_options = []
134
-
135
- teams = find("div.input").all('.team-value') # Grab all the teams data
136
- teams.each_with_index do |val, index|
137
- current_team_id = '"' + val.find("input").value + '"'
138
- team_text = val.find(".label-primary").text
139
- description_text = val.find(".label-secondary").text
140
- description_text = "(#{description_text})" unless description_text.empty? # Include the team description if any
141
- index_text = (index + 1).to_s + "."
142
-
143
- available_options << [index_text, current_team_id, team_text, description_text].join(" ")
144
- end
145
-
146
- unless team_id
147
- puts available_options.join("\n").green
148
- team_index = ask("Please select the team number you would like to access: ".green)
149
- team_id = teams[team_index.to_i - 1].find(".radio").value
150
- end
151
-
152
- team_button = first(:xpath, "//input[@type='radio' and @value='#{team_id}']") # Select the desired team
153
- if team_button
154
- team_button.click
155
- else
156
- Helper.log.fatal "Could not find given Team. Available options: ".red
157
- puts available_options.join("\n").yellow
158
- raise DeveloperCenterLoginError.new("Error finding given team #{team_id}.".red)
159
- end
160
-
161
- all(".button.large.blue.submit").first.click
162
-
163
- result = visit PROFILES_URL
164
- raise "Could not open Developer Center" unless result['status'] == 'success'
165
- end
166
-
12
+
167
13
  def run(app_identifier, type, cert_name = nil, force = false, cert_date = nil)
168
14
  cert = maintain_app_certificate(app_identifier, type, force, cert_date)
169
-
15
+
170
16
  type_name = type
171
17
  type_name = "Distribution" if type == APPSTORE # both enterprise and App Store
172
18
  cert_name ||= "#{type_name}_#{app_identifier}.mobileprovision" # default name
173
19
  cert_name += '.mobileprovision' unless cert_name.include?'mobileprovision'
174
20
 
175
- output_path = TMP_FOLDER + cert_name
21
+ output_path = File.join(TMP_FOLDER, cert_name)
176
22
  File.write(output_path, cert)
177
23
 
178
24
  return output_path
@@ -336,7 +182,7 @@ module Sigh
336
182
  wait_for_elements('.row-details')
337
183
  click_on "Done"
338
184
  else
339
- Helper.log.info "Looking for certificate: #{certificate}. Found: #{certs}"
185
+ Helper.log.info "Looking for certificate: #{certificate}."
340
186
  raise "Could not find certificate in the list of available certificates."
341
187
  end
342
188
  end
@@ -364,200 +210,5 @@ module Sigh
364
210
  raise "Error fetching details for provisioning profile '#{profile_id}'".red
365
211
  end
366
212
  end
367
-
368
- # Returns a array of hashs, that contains information about the iOS certificate
369
- # @example
370
- # [{"certRequestId"=>"B23Q2P396B",
371
- # "name"=>"SunApps GmbH",
372
- # "statusString"=>"Issued",
373
- # "expirationDate"=>"2015-11-25T22:45:50Z",
374
- # "expirationDateString"=>"Nov 25, 2015",
375
- # "ownerType"=>"team",
376
- # "ownerName"=>"SunApps GmbH",
377
- # "ownerId"=>"....",
378
- # "canDownload"=>true,
379
- # "canRevoke"=>true,
380
- # "certificateId"=>"....",
381
- # "certificateStatusCode"=>0,
382
- # "certRequestStatusCode"=>4,
383
- # "certificateTypeDisplayId"=>"...",
384
- # "serialNum"=>"....",
385
- # "typeString"=>"iOS Distribution"},
386
- # {another sertificate...}]
387
- def code_signing_certificates(type, cert_date)
388
- certs_url = "https://developer.apple.com/account/ios/certificate/certificateList.action?type="
389
- certs_url << (type == DEVELOPMENT ? 'development' : 'distribution')
390
- visit certs_url
391
-
392
- certificateDataURL = wait_for_variable('certificateDataURL')
393
- certificateRequestTypes = wait_for_variable('certificateRequestTypes')
394
- certificateStatuses = wait_for_variable('certificateStatuses')
395
-
396
- url = [certificateDataURL, certificateRequestTypes, certificateStatuses].join('')
397
-
398
- # https://developer.apple.com/services-account/.../account/ios/certificate/listCertRequests.action?content-type=application/x-www-form-urlencoded&accept=application/json&requestId=...&userLocale=en_US&teamId=...&types=...&status=4&certificateStatus=0&type=distribution
399
-
400
- certs = post_ajax(url)['certRequests']
401
-
402
- ret_certs = []
403
- certificate_name = ENV['SIGH_CERTIFICATE']
404
-
405
- # The other profiles are push profiles
406
- certificate_type = type == DEVELOPMENT ? 'iOS Development' : 'iOS Distribution'
407
-
408
- # New profiles first
409
- certs.sort! do |a, b|
410
- Time.parse(b['expirationDate']) <=> Time.parse(a['expirationDate'])
411
- end
412
-
413
- certs.each do |current_cert|
414
- next unless current_cert['typeString'] == certificate_type
415
-
416
- if cert_date || certificate_name
417
- if current_cert['expirationDateString'] == cert_date
418
- Helper.log.info "Certificate ID '#{current_cert['certificateId']}' with expiry date '#{current_cert['expirationDateString']}' located"
419
- ret_certs << current_cert
420
- end
421
- if current_cert['name'] == certificate_name
422
- Helper.log.info "Certificate ID '#{current_cert['certificateId']}' with name '#{certificate_name}' located"
423
- ret_certs << current_cert
424
- end
425
- else
426
- ret_certs << current_cert
427
- end
428
- end
429
-
430
- return ret_certs unless ret_certs.empty?
431
-
432
- predicates = []
433
- predicates << "name: #{certificate_name}" if certificate_name
434
- predicates << "expiry date: #{cert_date}" if cert_date
435
-
436
- predicates_str = " with #{predicates.join(' or ')}"
437
-
438
- raise "Could not find a Certificate#{predicates_str}. Please open #{current_url} and make sure you have a signing profile created.".red
439
- end
440
-
441
- # Download a file from the dev center, by using a HTTP client. This will return the content of the file
442
- def download_file(url)
443
- Helper.log.info "Downloading profile..."
444
- host = Capybara.current_session.current_host
445
- url = [host, url].join('')
446
-
447
- cookieString = ""
448
-
449
- page.driver.cookies.each do |key, cookie|
450
- cookieString << "#{cookie.name}=#{cookie.value};" # append all known cookies
451
- end
452
-
453
- data = open(url, {'Cookie' => cookieString}).read
454
-
455
- raise "Something went wrong when downloading the file from the Dev Center" unless data
456
- Helper.log.info "Successfully downloaded provisioning profile"
457
- return data
458
- end
459
-
460
- def post_ajax(url)
461
- JSON.parse(page.evaluate_script("$.ajax({type: 'POST', url: '#{url}', async: false})")['responseText'])
462
- end
463
-
464
- def click_next
465
- wait_for_elements('.button.small.blue.right.submit').last.click
466
- end
467
-
468
- def error_occured(ex)
469
- snap
470
- raise ex # re-raise the error after saving the snapshot
471
- end
472
-
473
- def snap
474
- path = "Error#{Time.now.to_i}.png"
475
- save_screenshot(path, :full => true)
476
- system("open '#{path}'") unless ENV['SIGH_DISABLE_OPEN_ERROR']
477
- end
478
-
479
- def wait_for(method, parameter, success)
480
- counter = 0
481
- result = method.call(parameter)
482
- while !success.call(result)
483
- sleep 0.2
484
-
485
- result = method.call(parameter)
486
-
487
- counter += 1
488
- if counter > 100
489
- Helper.log.debug caller
490
- raise DeveloperCenterGeneralError.new("Couldn't find '#{parameter}' after waiting for quite some time")
491
- end
492
- end
493
- return result
494
- end
495
-
496
- def wait_for_elements(name)
497
- method = Proc.new { |n| all(name) }
498
- success = Proc.new { |r| r.count > 0 }
499
- return wait_for(method, name, success)
500
- end
501
-
502
- def wait_for_variable(name)
503
- method = Proc.new { |n|
504
- retval = page.html.match(/var #{n} = "(.*)"/)
505
- retval[1] unless retval == nil
506
- }
507
- success = Proc.new { |r| r != nil }
508
- return wait_for(method, name, success)
509
- end
510
213
  end
511
214
  end
512
-
513
-
514
-
515
-
516
- # Example response 1)
517
- # => {"resultCode"=>0,
518
- # "protocolVersion"=>"....",
519
- # "isAdmin"=>true,
520
- # "isMember"=>false,
521
- # "isAgent"=>true,
522
- # "pageNumber"=>nil,
523
- # "pageSize"=>nil,
524
- # "totalRecords"=>nil,
525
- # "provisioningProfile"=>
526
- # {"provisioningProfileId"=>"....",
527
- # "name"=>"Gut Altentann Development",
528
- # "status"=>"Active",
529
- # "type"=>"iOS Development",
530
- # "distributionMethod"=>"limited",
531
- # "proProPlatform"=>"ios",
532
- # "version"=>"ProvisioningProfilev1",
533
- # "dateExpire"=>"2015-02-22",
534
- # "managingApp"=>nil,
535
- # "appId"=>
536
- # {"appIdId"=>".....",
537
- # "name"=>"SunApps",
538
- # "appIdPlatform"=>"ios",
539
- # "prefix"=>"....",
540
- # "identifier"=>"net.sunapps.123",
541
- # "isWildCard"=>true,
542
- # "isDuplicate"=>false,
543
- # "features"=>
544
- # {"push"=>false,
545
- # "inAppPurchase"=>false,
546
- # "gameCenter"=>false,
547
- # "passbook"=>false,
548
- # "dataProtection"=>"",
549
- # "homeKit"=>false,
550
- # "cloudKitVersion"=>1,
551
- # "iCloud"=>false,
552
- # "LPLF93JG7M"=>false,
553
- # "WC421J6T7P"=>false},
554
- # "enabledFeatures"=>[],
555
- # "isDevPushEnabled"=>false,
556
- # "isProdPushEnabled"=>false,
557
- # "associatedApplicationGroupsCount"=>nil,
558
- # "associatedCloudContainersCount"=>nil,
559
- # "associatedIdentifiersCount"=>nil},
560
- # "appIdId"=>".....",
561
- # "deviceCount"=>8,
562
- # "certificateCount"=>1,
563
- # "UUID"=>"F670D427-2D0E-4782-8171-....."}}
@@ -23,7 +23,7 @@ module Sigh
23
23
  end
24
24
 
25
25
  def get_inputs(options, args)
26
- @resign_path = File.join(Helper.gem_path, 'lib', 'assets', 'resign.sh')
26
+ @resign_path = File.join(Helper.gem_path('sigh'), 'lib', 'assets', 'resign.sh')
27
27
  raise "Could not find resign.sh file. Please try re-installing the gem.".red unless File.exists?@resign_path
28
28
 
29
29
  @ipa = args.first || find_ipa || ask("Path to ipa file: ")
@@ -1,3 +1,3 @@
1
1
  module Sigh
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sigh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-11 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: fastlane_core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -24,104 +24,6 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: highline
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 1.6.21
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: 1.6.21
41
- - !ruby/object:Gem::Dependency
42
- name: colored
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: commander
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '4'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '4'
69
- - !ruby/object:Gem::Dependency
70
- name: credentials_manager
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: phantomjs
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- version: 1.9.8
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ~>
95
- - !ruby/object:Gem::Version
96
- version: 1.9.8
97
- - !ruby/object:Gem::Dependency
98
- name: capybara
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: 2.4.3
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: 2.4.3
111
- - !ruby/object:Gem::Dependency
112
- name: poltergeist
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: 1.5.1
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ~>
123
- - !ruby/object:Gem::Version
124
- version: 1.5.1
125
27
  - !ruby/object:Gem::Dependency
126
28
  name: bundler
127
29
  requirement: !ruby/object:Gem::Requirement
@@ -236,9 +138,7 @@ files:
236
138
  - lib/sigh.rb
237
139
  - lib/sigh/dependency_checker.rb
238
140
  - lib/sigh/developer_center.rb
239
- - lib/sigh/helper.rb
240
141
  - lib/sigh/resign.rb
241
- - lib/sigh/update_checker.rb
242
142
  - lib/sigh/version.rb
243
143
  homepage: http://fastlane.tools
244
144
  licenses:
@@ -1,58 +0,0 @@
1
- require 'logger'
2
-
3
- module Sigh
4
- module Helper
5
-
6
- # Logging happens using this method
7
- def self.log
8
- if is_test?
9
- @@log ||= Logger.new(STDOUT) # don't show any logs when running tests
10
- else
11
- @@log ||= Logger.new(STDOUT)
12
- end
13
-
14
- @@log.formatter = proc do |severity, datetime, progname, msg|
15
- string = "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: "
16
- second = "#{msg}\n"
17
-
18
- if severity == "DEBUG"
19
- string = string.magenta
20
- elsif severity == "INFO"
21
- string = string.white
22
- elsif severity == "WARN"
23
- string = string.yellow
24
- elsif severity == "ERROR"
25
- string = string.red
26
- elsif severity == "FATAL"
27
- string = string.red.bold
28
- end
29
-
30
-
31
- [string, second].join("")
32
- end
33
-
34
- @@log
35
- end
36
-
37
- # @return true if the currently running program is a unit test
38
- def self.is_test?
39
- defined?SpecHelper
40
- end
41
-
42
- # @return the full path to the Xcode developer tools of the currently
43
- # running system
44
- def self.xcode_path
45
- return "" if self.is_test? and not OS.mac?
46
- `xcode-select -p`.gsub("\n", '') + "/"
47
- end
48
-
49
- # Path to the installed gem to load resources (e.g. resign.sh)
50
- def self.gem_path
51
- if not Helper.is_test? and Gem::Specification::find_all_by_name('sigh').any?
52
- return Gem::Specification.find_by_name('sigh').gem_dir
53
- else
54
- return './'
55
- end
56
- end
57
- end
58
- end
@@ -1,44 +0,0 @@
1
- require 'open-uri'
2
-
3
- module Sigh
4
- # Verifies, the user runs the latest version of this gem
5
- class UpdateChecker
6
- # This method will check if the latest version is installed and show a warning if that's not the case
7
- def self.verify_latest_version
8
- if self.update_available?
9
- v = fetch_latest
10
- puts '#######################################################################'.green
11
- puts "# sigh #{v} is available.".green
12
- puts "# It is recommended to use the latest version.".green
13
- puts "# Update using '(sudo) gem update sigh'.".green
14
- puts "# To see what's new, open https://github.com/KrauseFx/sigh/releases.".green
15
- puts '#######################################################################'.green
16
- return true
17
- end
18
- false
19
- end
20
-
21
- # Is a new official release available (this does not include pre-releases)
22
- def self.update_available?
23
- begin
24
- latest = fetch_latest
25
- if latest and Gem::Version.new(latest) > Gem::Version.new(current_version)
26
- return true
27
- end
28
- rescue => ex
29
- Helper.log.error("Could not check if 'sigh' is up to date.")
30
- end
31
- return false
32
- end
33
-
34
- # The currently used version of this gem
35
- def self.current_version
36
- Sigh::VERSION
37
- end
38
-
39
- private
40
- def self.fetch_latest
41
- JSON.parse(open("http://rubygems.org/api/v1/gems/sigh.json").read)["version"]
42
- end
43
- end
44
- end