branch_io_cli 0.12.2 → 0.12.3

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 (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/branch_io_cli/cli.rb +1 -1
  3. data/lib/branch_io_cli/command/command.rb +5 -3
  4. data/lib/branch_io_cli/command/report_command.rb +12 -7
  5. data/lib/branch_io_cli/command/setup_command.rb +66 -48
  6. data/lib/branch_io_cli/configuration.rb +3 -0
  7. data/lib/branch_io_cli/configuration/configuration.rb +9 -2
  8. data/lib/branch_io_cli/configuration/report_configuration.rb +0 -80
  9. data/lib/branch_io_cli/configuration/report_options.rb +86 -0
  10. data/lib/branch_io_cli/configuration/setup_configuration.rb +1 -146
  11. data/lib/branch_io_cli/configuration/setup_options.rb +152 -0
  12. data/lib/branch_io_cli/configuration/validate_configuration.rb +0 -31
  13. data/lib/branch_io_cli/configuration/validate_options.rb +38 -0
  14. data/lib/branch_io_cli/configuration/xcode_settings.rb +12 -7
  15. data/lib/branch_io_cli/core_ext.rb +1 -0
  16. data/lib/branch_io_cli/core_ext/io.rb +34 -11
  17. data/lib/branch_io_cli/core_ext/regexp.rb +4 -0
  18. data/lib/branch_io_cli/{helper/xcodeproj_ext.rb → core_ext/xcodeproj.rb} +0 -0
  19. data/lib/branch_io_cli/format/markdown_format.rb +1 -3
  20. data/lib/branch_io_cli/format/shell_format.rb +1 -3
  21. data/lib/branch_io_cli/helper.rb +1 -1
  22. data/lib/branch_io_cli/helper/branch_helper.rb +0 -8
  23. data/lib/branch_io_cli/helper/ios_helper.rb +0 -319
  24. data/lib/branch_io_cli/helper/methods.rb +15 -11
  25. data/lib/branch_io_cli/helper/patch_helper.rb +6 -6
  26. data/lib/branch_io_cli/helper/report_helper.rb +5 -7
  27. data/lib/branch_io_cli/helper/tool_helper.rb +329 -0
  28. data/lib/branch_io_cli/rake_task.rb +14 -35
  29. data/lib/branch_io_cli/version.rb +1 -1
  30. metadata +22 -4
@@ -11,4 +11,8 @@ class Regexp
11
11
 
12
12
  match contents
13
13
  end
14
+
15
+ def match_file?(file)
16
+ !match_file(file).nil?
17
+ end
14
18
  end
@@ -54,9 +54,7 @@ module BranchIOCLI
54
54
  end
55
55
 
56
56
  def render_command(name)
57
- @command = Object.const_get("BranchIOCLI")
58
- .const_get("Command")
59
- .const_get("#{name.to_s.capitalize}Command")
57
+ @command = BranchIOCLI::Command.const_get("#{name.to_s.capitalize}Command")
60
58
  render :command
61
59
  end
62
60
  end
@@ -24,9 +24,7 @@ module BranchIOCLI
24
24
  end
25
25
 
26
26
  def options_for_command(command)
27
- @configuration = Object.const_get("BranchIOCLI")
28
- .const_get("Configuration")
29
- .const_get("#{command.capitalize}Configuration")
27
+ @configuration = BranchIOCLI::Configuration.const_get("#{command.capitalize}Configuration")
30
28
  @configuration.available_options.map { |o| option(o.name) }.join(" ")
31
29
  end
32
30
  end
@@ -2,5 +2,5 @@ require "branch_io_cli/helper/branch_helper"
2
2
  require "branch_io_cli/helper/methods"
3
3
  require "branch_io_cli/helper/patch_helper"
4
4
  require "branch_io_cli/helper/report_helper"
5
+ require "branch_io_cli/helper/tool_helper"
5
6
  require "branch_io_cli/helper/util"
6
- require "branch_io_cli/helper/xcodeproj_ext"
@@ -67,14 +67,6 @@ module BranchIOCLI
67
67
  end
68
68
  end
69
69
  end
70
-
71
- def ensure_directory(path)
72
- return if path == "/" || path == "."
73
- parent = File.dirname path
74
- ensure_directory parent
75
- return if Dir.exist? path
76
- Dir.mkdir path
77
- end
78
70
  end
79
71
  end
80
72
  end
@@ -1,13 +1,6 @@
1
- require "cocoapods-core"
2
1
  require "json"
3
- require "net/http"
4
2
  require "openssl"
5
- require "pathname"
6
- require "pattern_patch"
7
3
  require "plist"
8
- require "shellwords"
9
- require "tmpdir"
10
- require "zip"
11
4
 
12
5
  require "branch_io_cli/configuration"
13
6
  require "branch_io_cli/helper/methods"
@@ -397,318 +390,6 @@ module BranchIOCLI
397
390
 
398
391
  associated_domains.select { |d| d =~ /^applinks:/ }.map { |d| d.sub(/^applinks:/, "") }
399
392
  end
400
-
401
- def add_cocoapods(options)
402
- verify_cocoapods
403
-
404
- podfile_path = options.podfile_path
405
-
406
- install_command = "pod install"
407
- install_command += " --repo-update" if options.pod_repo_update
408
- Dir.chdir(File.dirname(podfile_path)) do
409
- sh "pod init"
410
- PatternPatch::Patch.new(
411
- regexp: /^(\s*)# Pods for #{options.target.name}$/,
412
- mode: :append,
413
- text: "\n\\1pod \"Branch\""
414
- ).apply podfile_path
415
- # Store a Pod::Podfile representation of this file.
416
- options.open_podfile
417
- sh install_command
418
- end
419
-
420
- return unless options.commit
421
-
422
- add_change podfile_path
423
- add_change "#{podfile_path}.lock"
424
-
425
- # For now, add Pods folder to SCM.
426
- pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
427
- workspace_path = Pathname.new(File.expand_path(options.xcodeproj_path.sub(/.xcodeproj$/, ".xcworkspace"))).relative_path_from Pathname.pwd
428
- podfile_pathname = Pathname.new(podfile_path).relative_path_from Pathname.pwd
429
- add_change pods_folder_path
430
- add_change workspace_path
431
-
432
- sh [
433
- "git",
434
- "add",
435
- podfile_pathname,
436
- "#{podfile_pathname}.lock",
437
- pods_folder_path,
438
- workspace_path
439
- ]
440
- end
441
-
442
- def add_carthage(options)
443
- # TODO: Collapse this and Command::update_cartfile
444
- verify_carthage
445
-
446
- # 1. Generate Cartfile
447
- cartfile_path = options.cartfile_path
448
- File.open(cartfile_path, "w") do |file|
449
- file.write <<EOF
450
- github "BranchMetrics/ios-branch-deep-linking"
451
- EOF
452
- end
453
-
454
- # 2. carthage update
455
- Dir.chdir(File.dirname(cartfile_path)) do
456
- sh "carthage #{options.carthage_command}"
457
- end
458
-
459
- # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
460
- add_change cartfile_path
461
- add_change "#{cartfile_path}.resolved"
462
- add_change options.xcodeproj_path
463
-
464
- # 4. Add to target dependencies
465
- frameworks_group = options.xcodeproj.frameworks_group
466
- branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
467
- target = options.target
468
- target.frameworks_build_phase.add_file_reference branch_framework
469
-
470
- # 5. Create a copy-frameworks build phase
471
- carthage_build_phase = target.new_shell_script_build_phase "carthage copy-frameworks"
472
- carthage_build_phase.shell_script = "/usr/local/bin/carthage copy-frameworks"
473
-
474
- carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
475
- carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
476
-
477
- update_framework_search_paths "$(SRCROOT)/Carthage/Build/iOS"
478
-
479
- options.xcodeproj.save
480
-
481
- return unless options.commit
482
-
483
- # For now, add Carthage folder to SCM
484
-
485
- # 6. Add the Carthage folder to the commit (in case :commit param specified)
486
- carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from(Pathname.pwd)
487
- cartfile_pathname = Pathname.new(cartfile_path).relative_path_from Pathname.pwd
488
- add_change carthage_folder_path
489
- sh ["git", "add", cartfile_pathname, "#{cartfile_pathname}.resolved", carthage_folder_path]
490
- end
491
-
492
- def add_direct(options)
493
- # Put the framework in the path for any existing Frameworks group in the project.
494
- frameworks_group = options.xcodeproj.frameworks_group
495
- framework_path = File.join frameworks_group.real_path, "Branch.framework"
496
- raise "#{framework_path} exists." if File.exist? framework_path
497
-
498
- say "Finding current framework release"
499
-
500
- # Find the latest release from GitHub.
501
- releases = JSON.parse fetch "https://api.github.com/repos/BranchMetrics/ios-branch-deep-linking/releases"
502
- current_release = releases.first
503
- # Get the download URL for the framework.
504
- framework_asset = current_release["assets"][0]
505
- framework_url = framework_asset["browser_download_url"]
506
-
507
- say "Downloading Branch.framework v. #{current_release['tag_name']} (#{framework_asset['size']} bytes zipped)"
508
-
509
- Dir.mktmpdir do |download_folder|
510
- zip_path = File.join download_folder, "Branch.framework.zip"
511
-
512
- File.unlink zip_path if File.exist? zip_path
513
-
514
- # Download the framework zip
515
- download framework_url, zip_path
516
-
517
- say "Unzipping Branch.framework"
518
-
519
- # Unzip
520
- Zip::File.open zip_path do |zip_file|
521
- # Start with just the framework and add dSYM, etc., later
522
- zip_file.glob "Carthage/Build/iOS/Branch.framework/**/*" do |entry|
523
- filename = entry.name.sub %r{^Carthage/Build/iOS}, frameworks_group.real_path.to_s
524
- ensure_directory File.dirname filename
525
- entry.extract filename
526
- end
527
- end
528
- end
529
-
530
- # Now the current framework is in framework_path
531
-
532
- say "Adding to #{options.xcodeproj_path}"
533
-
534
- # Add as a dependency in the Frameworks group
535
- framework = frameworks_group.new_file "Branch.framework" # relative to frameworks_group.real_path
536
- options.target.frameworks_build_phase.add_file_reference framework, true
537
-
538
- update_framework_search_paths "$(SRCROOT)"
539
-
540
- options.xcodeproj.save
541
-
542
- add_change options.xcodeproj_path
543
- add_change framework_path
544
- sh ["git", "add", framework_path] if options.commit
545
-
546
- say "Done. ✅"
547
- end
548
-
549
- def update_framework_search_paths(path)
550
- # Make sure this is in the FRAMEWORK_SEARCH_PATHS if we just added it.
551
- if config.xcodeproj.frameworks_group.files.count == 1
552
- target = config.target
553
- target.build_configurations.each do |c|
554
- # this accounts for project-level settings as well
555
- setting = target.resolved_build_setting("FRAMEWORK_SEARCH_PATHS")[c.name] || []
556
- next if setting.include?(path) || setting.include?("#{path}/**")
557
- setting << path
558
-
559
- c.build_settings["FRAMEWORK_SEARCH_PATHS"] = setting
560
- end
561
- end
562
- # If it already existed, it's almost certainly already in FRAMEWORK_SEARCH_PATHS.
563
- end
564
-
565
- def update_podfile(options)
566
- verify_cocoapods
567
-
568
- podfile_path = options.podfile_path
569
- return false if podfile_path.nil?
570
-
571
- # 1. Patch Podfile. Return if no change (Branch pod already present).
572
- return false unless PatchHelper.patch_podfile podfile_path
573
-
574
- # 2. pod install
575
- # command = "PATH='#{ENV['PATH']}' pod install"
576
- command = 'pod install'
577
- command += ' --repo-update' if options.pod_repo_update
578
-
579
- Dir.chdir(File.dirname(podfile_path)) do
580
- sh command
581
- end
582
-
583
- # 3. Add Podfile and Podfile.lock to commit (in case :commit param specified)
584
- add_change podfile_path
585
- add_change "#{podfile_path}.lock"
586
-
587
- # 4. Check if Pods folder is under SCM
588
- pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
589
- `git ls-files #{pods_folder_path.to_s.shellescape} --error-unmatch > /dev/null 2>&1`
590
- return true unless $?.exitstatus == 0
591
-
592
- # 5. If so, add the Pods folder to the commit (in case :commit param specified)
593
- add_change pods_folder_path
594
- sh ["git", "add", pods_folder_path] if options.commit
595
-
596
- true
597
- end
598
-
599
- def update_cartfile(options, project)
600
- verify_carthage
601
-
602
- cartfile_path = options.cartfile_path
603
- return false if cartfile_path.nil?
604
-
605
- # 1. Patch Cartfile. Return if no change (Branch already present).
606
- return false unless PatchHelper.patch_cartfile cartfile_path
607
-
608
- # 2. carthage update
609
- Dir.chdir(File.dirname(cartfile_path)) do
610
- sh "carthage #{options.carthage_command} ios-branch-deep-linking"
611
- end
612
-
613
- # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
614
- add_change cartfile_path
615
- add_change "#{cartfile_path}.resolved"
616
- add_change options.xcodeproj_path
617
-
618
- # 4. Add to target dependencies
619
- frameworks_group = project.frameworks_group
620
- branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
621
- target = options.target
622
- target.frameworks_build_phase.add_file_reference branch_framework
623
-
624
- # 5. Add to copy-frameworks build phase
625
- carthage_build_phase = target.build_phases.find do |phase|
626
- phase.respond_to?(:shell_script) && phase.shell_script =~ /carthage\s+copy-frameworks/
627
- end
628
-
629
- if carthage_build_phase
630
- carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
631
- carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
632
- end
633
-
634
- # 6. Check if Carthage folder is under SCM
635
- carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from Pathname.pwd
636
- `git ls-files #{carthage_folder_path.to_s.shellescape} --error-unmatch > /dev/null 2>&1`
637
- return true unless $?.exitstatus == 0
638
-
639
- # 7. If so, add the Carthage folder to the commit (in case :commit param specified)
640
- add_change carthage_folder_path
641
- sh ["git", "add", carthage_folder_path] if options.commit
642
-
643
- true
644
- end
645
-
646
- def verify_cocoapods
647
- pod_cmd = `which pod`
648
- return unless pod_cmd.empty?
649
-
650
- gem_cmd = `which gem`
651
- if gem_cmd.empty?
652
- say "'pod' command not available in PATH and 'gem' command not available in PATH to install cocoapods."
653
- exit(-1)
654
- end
655
-
656
- install = confirm "'pod' command not available in PATH. Install cocoapods (may require a sudo password)?", true
657
- unless install
658
- say "Please install cocoapods or use --no-add-sdk to continue."
659
- exit(-1)
660
- end
661
-
662
- gem_home = Gem.dir
663
- if gem_home && File.writable?(gem_home)
664
- sh "gem install cocoapods"
665
- else
666
- sh "sudo gem install cocoapods"
667
- end
668
-
669
- # Ensure master podspec repo is set up (will update if it exists).
670
- sh "pod setup"
671
- end
672
-
673
- def verify_carthage
674
- carthage_cmd = `which carthage`
675
- return unless carthage_cmd.empty?
676
-
677
- brew_cmd = `which brew`
678
- if brew_cmd.empty?
679
- say "'carthage' command not available in PATH and 'brew' command not available in PATH to install 'carthage'."
680
- exit(-1)
681
- end
682
-
683
- install = confirm "'carthage' command not available in PATH. Use Homebrew to install carthage?", true
684
- unless install
685
- say "Please install carthage or use --no-add-sdk to continue."
686
- exit(-1)
687
- end
688
-
689
- sh "brew install carthage"
690
- end
691
-
692
- def verify_git
693
- return unless config.commit
694
-
695
- git_cmd = `which git`
696
- return unless git_cmd.empty?
697
-
698
- xcode_select_path = `which xcode-select`
699
- if xcode_select_path.empty?
700
- say "'git' command not available in PATH and 'xcode-select' command not available in PATH to install 'git'."
701
- exit(-1)
702
- end
703
-
704
- install = confirm "'git' command not available in PATH. Install Xcode command-line tools (requires password)?", true
705
- unless install
706
- say "Please install Xcode command tools or leave out the --commit option to continue."
707
- exit(-1)
708
- end
709
-
710
- sh "xcode-select --install"
711
- end
712
393
  end
713
394
  end
714
395
  end
@@ -3,9 +3,18 @@ module BranchIOCLI
3
3
  class CommandError < RuntimeError
4
4
  attr_reader :status
5
5
  def initialize(args)
6
- message, status = *args
6
+ @args = args.first
7
+ @status = args.second
7
8
  super message
8
- @status = status
9
+ end
10
+
11
+ def message
12
+ if @args.count == 1
13
+ return @args.first.shelljoin if @args.first.kind_of?(Array)
14
+ return @args.first.to_s
15
+ else
16
+ return @args.shelljoin
17
+ end
9
18
  end
10
19
  end
11
20
 
@@ -13,17 +22,12 @@ module BranchIOCLI
13
22
  # Execute a shell command with reporting.
14
23
  # The command itself is logged, then output from
15
24
  # both stdout and stderr, then a success or failure
16
- # message. Raises CommandError on error.
17
- #
18
- # If output is STDOUT (the default), no redirection occurs. In all
19
- # other cases, both stdout and stderr are redirected to output.
20
- # In these cases, formatting (colors, highlights) may be lost.
25
+ # message. Raises CommandError on error. No redirection occurs.
21
26
  #
22
27
  # @param command [String, Array] A shell command to execute
23
- # @param output [IO] An optional IO object to receive stdout and stderr from the command
24
- def sh(command, output = STDOUT)
25
- status = output.log_command command
26
- raise CommandError, [%{Error executing "#{command}": #{status}.}, status] unless status.success?
28
+ def sh(*command)
29
+ status = STDOUT.sh(*command)
30
+ raise CommandError, [command, status] unless status.success?
27
31
  end
28
32
 
29
33
  # Clear the screen and move the cursor to the top using highline
@@ -31,7 +31,7 @@ module BranchIOCLI
31
31
  # Can't just check for the import here, since there may be a bridging header.
32
32
  # This may match branch.initSession (if the Branch instance is stored) or
33
33
  # Branch.getInstance().initSession, etc.
34
- !/branch.*initsession|^\s*import\s+branch/i.match_file(path).nil?
34
+ /branch.*initsession|^\s*import\s+branch/i.match_file? path
35
35
  end
36
36
 
37
37
  def patch_bridging_header
@@ -53,10 +53,10 @@ module BranchIOCLI
53
53
 
54
54
  say "Patching #{config.bridging_header_path}"
55
55
 
56
- if /^\s*(#import|#include|@import)/.match_file config.bridging_header_path
56
+ if /^\s*(#import|#include|@import)/.match_file? config.bridging_header_path
57
57
  # Add among other imports
58
58
  patch(:objc_import).apply config.bridging_header_path
59
- elsif /\n\s*#ifndef\s+(\w+).*\n\s*#define\s+\1.*?\n/m.match_file config.bridging_header_path
59
+ elsif /\n\s*#ifndef\s+(\w+).*\n\s*#define\s+\1.*?\n/m.match_file? config.bridging_header_path
60
60
  # Has an include guard. Add inside.
61
61
  patch(:objc_import_include_guard).apply config.bridging_header_path
62
62
  else
@@ -202,14 +202,14 @@ module BranchIOCLI
202
202
  patch(:swift_import).apply path
203
203
  end
204
204
 
205
- is_new_method = !/didBecomeActive\(with.*?\{[^\n]*\n/m.match_file(path)
205
+ is_new_method = !/didBecomeActive\(with.*?\{[^\n]*\n/m.match_file?(path)
206
206
  patch_name += "#{is_new_method ? 'new_' : ''}swift"
207
207
  else
208
- return false if %r{^\s+#import\s+<Branch/Branch.h>|^\s+@import\s+Branch\s*;}.match_file(path)
208
+ return false if %r{^\s+#import\s+<Branch/Branch.h>|^\s+@import\s+Branch\s*;}.match_file?(path)
209
209
 
210
210
  patch(:objc_import).apply path
211
211
 
212
- is_new_method = !/didBecomeActiveWithConversation.*?\{[^\n]*\n/m.match_file(path)
212
+ is_new_method = !/didBecomeActiveWithConversation.*?\{[^\n]*\n/m.match_file?(path)
213
213
  patch_name += "#{is_new_method ? 'new_' : ''}objc"
214
214
  end
215
215