branch_io_cli 0.4.1 → 0.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d162acf761ea219b350dd56f71eeced3220beea
4
- data.tar.gz: e1417382cbc30b4d92d94268a7e5eb789492f9b9
3
+ metadata.gz: 7b2291799982aa8205535d5f28f0b4b372c2726b
4
+ data.tar.gz: 9986e2a7e85b74827fda5c4abd30a6b979d1b137
5
5
  SHA512:
6
- metadata.gz: 70795421103af48548a3181849b1cc7dc399ed19034522582adcb46442a3654f7931cfeda9a804ace14d5f9aad285f3d10526b65ef1ad8c973022939b316801b
7
- data.tar.gz: b53517cf8c3841cd5e6d7ce2531902beed7679dc1426ea4d46697de7c9415ea435c6bbd72192d0b6272ce3310dfe34b3e96b4debe39adf875c611fc78f7a9bc1
6
+ metadata.gz: e51e2863451a8deebb9fad4046a797893dcc776ec1eaa88c80fc13d2ea2af6f59fd9594fd88dc0a92a5dc1514b27b73d56bad4f0ab0f8f772e6ef5f8d7707e3a
7
+ data.tar.gz: 06e4ecb04f1c65eee5636eb1d1dc7f6776ac50d73b511bfd7d47b50f415465d7f24d105c419c7506823a00a18039d28f161371bfd6ffc90f6c6f0b733b1c1e85
@@ -1,6 +1,7 @@
1
1
  require "json"
2
2
  require "net/http"
3
3
  require "pathname"
4
+ require "tmpdir"
4
5
  require "xcodeproj"
5
6
  require "zip"
6
7
 
@@ -57,7 +58,6 @@ EOF
57
58
 
58
59
  def print_setup_configuration
59
60
  say <<EOF
60
-
61
61
  <%= color('Configuration:', BOLD) %>
62
62
 
63
63
  <%= color('Xcode project:', BOLD) %> #{@xcodeproj_path}
@@ -291,7 +291,7 @@ EOF
291
291
 
292
292
  # If no CocoaPods or Carthage, check to see if the framework is linked.
293
293
  target = BranchHelper.target_from_project @xcodeproj, options.target
294
- return if target.frameworks_build_phase.files.map(&:file_ref).map(&:path).any? { |p| p =~ %r{/Branch.framework$} }
294
+ return if target.frameworks_build_phase.files.map(&:file_ref).map(&:path).any? { |p| p =~ /Branch.framework$/ }
295
295
 
296
296
  # --podfile, --cartfile not specified. No Podfile found. No Cartfile found. No Branch.framework in project.
297
297
  # Prompt the user:
@@ -388,12 +388,12 @@ EOF
388
388
  end
389
389
 
390
390
  def add_direct(options)
391
- # TODO: Put these intermediates in a temp directory until Branch.framework is unzipped
392
- # (and validated?). For now dumped in the current directory.
393
- File.unlink "Branch.framework.zip" if File.exist? "Branch.framework.zip"
394
- remove_directory "Branch.framework"
391
+ # Put the framework in the path for any existing Frameworks group in the project.
392
+ frameworks_group = @xcodeproj.frameworks_group
393
+ framework_path = File.join frameworks_group.real_path, "Branch.framework"
394
+ raise "#{framework_path} exists." if File.exist? framework_path
395
395
 
396
- say "Finding current framework release..."
396
+ say "Finding current framework release"
397
397
 
398
398
  # Find the latest release from GitHub.
399
399
  releases = JSON.parse fetch "https://api.github.com/repos/BranchMetrics/ios-branch-deep-linking/releases"
@@ -402,50 +402,52 @@ EOF
402
402
  framework_asset = current_release["assets"][0]
403
403
  framework_url = framework_asset["browser_download_url"]
404
404
 
405
- say "Downloading Branch.framework v. #{current_release['tag_name']} (#{framework_asset['size']} bytes zipped)..."
405
+ say "Downloading Branch.framework v. #{current_release['tag_name']} (#{framework_asset['size']} bytes zipped)"
406
+
407
+ Dir.mktmpdir do |download_folder|
408
+ zip_path = File.join download_folder, "Branch.framework.zip"
406
409
 
407
- # Download the framework zip
408
- download framework_url, "Branch.framework.zip"
410
+ File.unlink zip_path if File.exist? zip_path
409
411
 
410
- say "Unzipping Branch.framework..."
412
+ # Download the framework zip
413
+ download framework_url, zip_path
411
414
 
412
- # Unzip
413
- Zip::File.open "Branch.framework.zip" do |zip_file|
414
- # Start with just the framework and add dSYM, etc., later
415
- zip_file.glob "Carthage/Build/iOS/Branch.framework/**/*" do |entry|
416
- filename = entry.name.sub %r{^Carthage/Build/iOS/}, ""
417
- ensure_directory File.dirname filename
418
- entry.extract filename
415
+ say "Unzipping Branch.framework"
416
+
417
+ # Unzip
418
+ Zip::File.open zip_path do |zip_file|
419
+ # Start with just the framework and add dSYM, etc., later
420
+ zip_file.glob "Carthage/Build/iOS/Branch.framework/**/*" do |entry|
421
+ filename = entry.name.sub %r{^Carthage/Build/iOS}, frameworks_group.real_path.to_s
422
+ ensure_directory File.dirname filename
423
+ entry.extract filename
424
+ end
419
425
  end
420
426
  end
421
427
 
422
- # Remove intermediate zip file
423
- File.unlink "Branch.framework.zip"
428
+ # Now the current framework is in framework_path
424
429
 
425
- # Now the current framework is in ./Branch.framework
426
-
427
- say "Adding to #{@xcodeproj_path}..."
430
+ say "Adding to #{@xcodeproj_path}"
428
431
 
429
432
  # Add as a dependency in the Frameworks group
430
- frameworks_group = @xcodeproj.frameworks_group
431
- framework = frameworks_group.new_file "Branch.framework"
432
- target = BranchHelper.target_from_project @xcodeproj, options.target
433
- target.frameworks_build_phase.add_file_reference framework, true
434
-
435
- # Make sure this is in the FRAMEWORK_SEARCH_PATHS
436
- @xcodeproj.build_configurations.each do |config|
437
- setting = config.build_settings["FRAMEWORK_SEARCH_PATHS"] || []
438
- setting = [setting] if setting.kind_of? String
439
- next if setting.any? { |p| p == "$(SRCROOT)" }
440
-
441
- setting << "$(SRCROOT)"
442
- config.build_settings["FRAMEWORK_SEARCH_PATHS"] = setting
433
+ framework = frameworks_group.new_file "Branch.framework" # relative to frameworks_group.real_path
434
+ @target.frameworks_build_phase.add_file_reference framework, true
435
+
436
+ # Make sure this is in the FRAMEWORK_SEARCH_PATHS if we just added it.
437
+ if frameworks_group.files.count == 1
438
+ @target.build_configurations.each do |config|
439
+ paths = config.build_settings["FRAMEWORK_SEARCH_PATHS"] || []
440
+ next if paths.any? { |p| p == '$(SRCROOT)' || p == '$(SRCROOT)/**' }
441
+ paths << '$(SRCROOT)'
442
+ config.build_settings["FRAMEWORK_SEARCH_PATHS"] = paths
443
+ end
443
444
  end
445
+ # If it already existed, it's almost certainly already in FRAMEWORK_SEARCH_PATHS.
444
446
 
445
447
  @xcodeproj.save
446
448
 
447
- BranchHelper.add_change File.expand_path "Branch.framework"
448
- `git add Branch.framework` if options.commit
449
+ BranchHelper.add_change framework_path
450
+ `git add #{framework_path}` if options.commit
449
451
 
450
452
  say "Done. ✅"
451
453
  end
@@ -472,11 +474,25 @@ EOF
472
474
  http.request request do |response|
473
475
  case response
474
476
  when Net::HTTPSuccess
477
+ bytes_downloaded = 0
478
+ dots_reported = 0
479
+ # report a dot every 100 kB
480
+ per_dot = 102_400
481
+
475
482
  File.open dest, 'w' do |io|
476
483
  response.read_body do |chunk|
477
484
  io.write chunk
485
+
486
+ # print progress
487
+ bytes_downloaded += chunk.length
488
+ while (bytes_downloaded - per_dot * dots_reported) >= per_dot
489
+ print "."
490
+ dots_reported += 1
491
+ end
492
+ STDOUT.flush
478
493
  end
479
494
  end
495
+ say "\n"
480
496
  when Net::HTTPRedirection
481
497
  download response['location'], dest
482
498
  else
@@ -494,15 +510,6 @@ EOF
494
510
  Dir.mkdir path
495
511
  end
496
512
 
497
- def remove_directory(path)
498
- return unless File.exist? path
499
-
500
- Dir["#{path}/*"].each do |file|
501
- remove_directory(file) and next if File.directory?(file)
502
- File.unlink file
503
- end
504
- end
505
-
506
513
  SDK_OPTIONS =
507
514
  {
508
515
  "Set this project up to use CocoaPods and add the Branch SDK." => :cocoapods,
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branch_io_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branch
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-25 00:00:00.000000000 Z
12
+ date: 2017-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander