Class: BranchIOCLI::Command
- Inherits:
-
Object
- Object
- BranchIOCLI::Command
- Defined in:
- lib/branch_io_cli/command.rb
Class Method Summary collapse
- .cartfile_path(options) ⇒ Object
- .helper ⇒ Object
- .patch_source(xcodeproj) ⇒ Object
- .podfile_path(options) ⇒ Object
- .setup(options) ⇒ Object
- .update_cartfile(options, project) ⇒ Object
- .update_podfile(options) ⇒ Object
- .validate(options) ⇒ Object
Class Method Details
.cartfile_path(options) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/branch_io_cli/command.rb', line 103 def cartfile_path() # Disable Cartfile update if add_sdk: false is present return nil if .no_add_sdk # Use the :cartfile parameter if present if .cartfile raise "--cartfile argument must specify a path ending in '/Cartfile'" unless .cartfile =~ %r{/Cartfile$} cartfile_path = File. .cartfile, "." return cartfile_path if File.exist? cartfile_path raise "#{cartfile_path} not found" end # Look in the same directory as the project (typical setup) cartfile_path = File. "../Cartfile", @xcodeproj_path return cartfile_path if File.exist? cartfile_path end |
.helper ⇒ Object
82 83 84 |
# File 'lib/branch_io_cli/command.rb', line 82 def helper BranchIOCLI::Helper::BranchHelper end |
.patch_source(xcodeproj) ⇒ Object
194 195 196 |
# File 'lib/branch_io_cli/command.rb', line 194 def patch_source(xcodeproj) helper.patch_app_delegate_swift(xcodeproj) || helper.patch_app_delegate_objc(xcodeproj) end |
.podfile_path(options) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/branch_io_cli/command.rb', line 86 def podfile_path() # Disable Podfile update if add_sdk: false is present return nil if .no_add_sdk # Use the :podfile parameter if present if .podfile raise "--podfile argument must specify a path ending in '/Podfile'" unless .podfile =~ %r{/Podfile$} podfile_path = File. .podfile, "." return podfile_path if File.exist? podfile_path raise "#{podfile_path} not found" end # Look in the same directory as the project (typical setup) podfile_path = File. "../Podfile", @xcodeproj_path return podfile_path if File.exist? podfile_path end |
.setup(options) ⇒ Object
6 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 |
# File 'lib/branch_io_cli/command.rb', line 6 def setup() = Helper::ConfigurationHelper. @keys = Helper::ConfigurationHelper.keys @domains = Helper::ConfigurationHelper.all_domains @xcodeproj_path = .xcodeproj xcodeproj = Helper::ConfigurationHelper.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 `git commit #{helper.changes.join(" ")} -m '[branch_io_cli] Branch SDK integration'` end |
.update_cartfile(options, project) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/branch_io_cli/command.rb', line 151 def update_cartfile(, project) cartfile_path = 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 `carthage update` 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'] 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 carthage_folder_path = File. "../Carthage", cartfile_path `git ls-files #{carthage_folder_path} --error-unmatch > /dev/null 2>&1` return true unless $?.exitstatus == 0 # 7. If so, add the Pods folder to the commit (in case :commit param specified) helper.add_change carthage_folder_path other_action.git_add path: carthage_folder_path if .commit true end |
.update_podfile(options) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/branch_io_cli/command.rb', line 120 def update_podfile() podfile_path = 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 `#{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 pods_folder_path = File. "../Pods", podfile_path `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 other_action.git_add path: pods_folder_path if .commit true end |
.validate(options) ⇒ Object
44 45 46 47 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 |
# File 'lib/branch_io_cli/command.rb', line 44 def validate() = Helper::ConfigurationHelper. # raises xcodeproj = Helper::ConfigurationHelper.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 |