Class: BranchIOCLI::Command
- Inherits:
-
Object
- Object
- BranchIOCLI::Command
- Defined in:
- lib/branch_io_cli/command.rb
Class Method Summary collapse
- .config_helper ⇒ Object
- .helper ⇒ Object
- .patch_source(xcodeproj) ⇒ Object
- .setup(options) ⇒ Object
- .update_cartfile(options, project) ⇒ Object
- .update_podfile(options) ⇒ Object
- .validate(options) ⇒ Object
Class Method Details
.config_helper ⇒ Object
90 91 92 |
# File 'lib/branch_io_cli/command.rb', line 90 def config_helper Helper::ConfigurationHelper end |
.helper ⇒ Object
86 87 88 |
# File 'lib/branch_io_cli/command.rb', line 86 def helper Helper::BranchHelper end |
.patch_source(xcodeproj) ⇒ Object
172 173 174 |
# File 'lib/branch_io_cli/command.rb', line 172 def patch_source(xcodeproj) helper.patch_app_delegate_swift(xcodeproj) || helper.patch_app_delegate_objc(xcodeproj) end |
.setup(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/branch_io_cli/command.rb', line 7 def setup() config_helper. @keys = config_helper.keys @domains = config_helper.all_domains @xcodeproj_path = config_helper.xcodeproj_path xcodeproj = config_helper.xcodeproj update_podfile() || update_cartfile(, xcodeproj) target = .target # may be nil if !.no_validate && !helper.validate_team_and_bundle_ids_from_aasa_files(xcodeproj, target, @domains) say "Universal Link configuration failed validation." helper.errors.each { |error| say " #{error}" } return unless .force elsif !.no_validate say "Universal Link configuration passed validation. ✅" end # the following calls can all raise IOError helper.add_keys_to_info_plist xcodeproj, target, @keys helper.add_branch_universal_link_domains_to_info_plist xcodeproj, target, @domains new_path = helper.add_universal_links_to_project xcodeproj, target, @domains, false `git add #{new_path}` if .commit && new_path helper.add_system_frameworks xcodeproj, target, .frameworks unless .frameworks.nil? || .frameworks.empty? xcodeproj.save patch_source xcodeproj unless .no_patch_source return unless .commit current_pathname = Pathname.new File. "." changes = helper.changes.to_a.map { |c| Pathname.new(File.(c)).relative_path_from(current_pathname).to_s } `git commit #{changes.join(" ")} -m '[branch_io_cli] Branch SDK integration'` end |
.update_cartfile(options, project) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/branch_io_cli/command.rb', line 127 def update_cartfile(, project) cartfile_path = config_helper.cartfile_path return false if cartfile_path.nil? # 1. Patch Cartfile. Return if no change (Branch already present). return false unless helper.patch_cartfile cartfile_path # 2. carthage update Dir.chdir(File.dirname(cartfile_path)) do system "carthage update --platform ios" end # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified) helper.add_change cartfile_path helper.add_change "#{cartfile_path}.resolved" # 4. Add to target depependencies frameworks_group = project.frameworks_group branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework" target = helper.target_from_project project, .target target.frameworks_build_phase.add_file_reference branch_framework # 5. Add to copy-frameworks build phase carthage_build_phase = target.build_phases.find do |phase| phase.respond_to?(:shell_script) && phase.shell_script =~ /carthage\s+copy-frameworks/ end if carthage_build_phase carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework" carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework" end # 6. Check if Carthage folder is under SCM current_pathname = Pathname.new File. "." carthage_folder_path = Pathname.new(File.("../Carthage", cartfile_path)).relative_path_from current_pathname `git ls-files #{carthage_folder_path} --error-unmatch > /dev/null 2>&1` return true unless $?.exitstatus == 0 # 7. If so, add the Carthage folder to the commit (in case :commit param specified) helper.add_change carthage_folder_path `git add #{carthage_folder_path}` if .commit true end |
.update_podfile(options) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/branch_io_cli/command.rb', line 94 def update_podfile() podfile_path = config_helper.podfile_path return false if podfile_path.nil? # 1. Patch Podfile. Return if no change (Branch pod already present). return false unless helper.patch_podfile podfile_path # 2. pod install # command = "PATH='#{ENV['PATH']}' pod install" command = 'pod install' command += ' --repo-update' unless .no_pod_repo_update Dir.chdir(File.dirname(podfile_path)) do system command end # 3. Add Podfile and Podfile.lock to commit (in case :commit param specified) helper.add_change podfile_path helper.add_change "#{podfile_path}.lock" # 4. Check if Pods folder is under SCM current_pathname = Pathname.new File. "." pods_folder_path = Pathname.new(File.("../Pods", podfile_path)).relative_path_from current_pathname `git ls-files #{pods_folder_path} --error-unmatch > /dev/null 2>&1` return true unless $?.exitstatus == 0 # 5. If so, add the Pods folder to the commit (in case :commit param specified) helper.add_change pods_folder_path `git add #{pods_folder_path}` if .commit true end |
.validate(options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/branch_io_cli/command.rb', line 48 def validate() config_helper. # raises xcodeproj = config_helper.xcodeproj valid = true unless .domains.nil? || .domains.empty? domains_valid = helper.validate_project_domains( .domains, xcodeproj, .target ) if domains_valid say "Project domains match :domains parameter: ✅" else say "Project domains do not match specified :domains" helper.errors.each { |error| say " #{error}" } end valid &&= domains_valid end configuration_valid = helper.validate_team_and_bundle_ids_from_aasa_files xcodeproj, .target unless configuration_valid say "Universal Link configuration failed validation." helper.errors.each { |error| say " #{error}" } end valid &&= configuration_valid say "Universal Link configuration passed validation. ✅" if valid valid end |