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
@@ -23,7 +23,7 @@ module BranchIOCLI
23
23
  end
24
24
 
25
25
  def helper
26
- Helper::BranchHelper
26
+ BranchHelper
27
27
  end
28
28
 
29
29
  def xcode_settings
@@ -31,13 +31,11 @@ module BranchIOCLI
31
31
  end
32
32
 
33
33
  def base_xcodebuild_cmd
34
- cmd = "xcodebuild"
35
34
  if config.workspace_path
36
- cmd = "#{cmd} -workspace #{Shellwords.escape config.workspace_path}"
35
+ ["xcodebuild", "-workspace", config.workspace_path]
37
36
  else
38
- cmd = "#{cmd} -project #{Shellwords.escape config.xcodeproj_path}"
37
+ ["xcodebuild", "-project", config.xcodeproj_path]
39
38
  end
40
- cmd
41
39
  end
42
40
 
43
41
  def report_scheme
@@ -227,7 +225,7 @@ module BranchIOCLI
227
225
  exit(-1)
228
226
  end
229
227
 
230
- helper.verify_cocoapods
228
+ ToolHelper.verify_cocoapods
231
229
 
232
230
  install_command = "pod install"
233
231
 
@@ -242,7 +240,7 @@ some cases. If that happens, please rerun without --no-pod-repo-update or run
242
240
  end
243
241
 
244
242
  say "Running #{install_command.inspect}"
245
- if report.log_command(install_command).success?
243
+ if report.sh(install_command).success?
246
244
  say "Done ✅"
247
245
  else
248
246
  say "pod install failed. See report for details."
@@ -0,0 +1,329 @@
1
+ require "cocoapods-core"
2
+ require "fileutils"
3
+ require "pathname"
4
+ require "pattern_patch"
5
+ require "zip"
6
+
7
+ module BranchIOCLI
8
+ module Helper
9
+ class ToolHelper
10
+ extend Methods
11
+
12
+ class << self
13
+ def config
14
+ Configuration::Configuration.current
15
+ end
16
+
17
+ def helper
18
+ BranchHelper
19
+ end
20
+
21
+ def add_cocoapods(options)
22
+ verify_cocoapods
23
+
24
+ podfile_path = options.podfile_path
25
+
26
+ install_command = "pod install"
27
+ install_command += " --repo-update" if options.pod_repo_update
28
+ Dir.chdir(File.dirname(podfile_path)) do
29
+ sh "pod init"
30
+ PatternPatch::Patch.new(
31
+ regexp: /^(\s*)# Pods for #{options.target.name}$/,
32
+ mode: :append,
33
+ text: "\n\\1pod \"Branch\""
34
+ ).apply podfile_path
35
+ # Store a Pod::Podfile representation of this file.
36
+ options.open_podfile
37
+ sh install_command
38
+ end
39
+
40
+ return unless options.commit
41
+
42
+ helper.add_change podfile_path
43
+ helper.add_change "#{podfile_path}.lock"
44
+
45
+ # For now, add Pods folder to SCM.
46
+ pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
47
+ workspace_path = Pathname.new(File.expand_path(options.xcodeproj_path.sub(/.xcodeproj$/, ".xcworkspace"))).relative_path_from Pathname.pwd
48
+ podfile_pathname = Pathname.new(podfile_path).relative_path_from Pathname.pwd
49
+ helper.add_change pods_folder_path
50
+ helper.add_change workspace_path
51
+
52
+ sh(
53
+ "git",
54
+ "add",
55
+ podfile_pathname.to_s,
56
+ "#{podfile_pathname}.lock",
57
+ pods_folder_path.to_s,
58
+ workspace_path.to_s
59
+ )
60
+ end
61
+
62
+ def add_carthage(options)
63
+ # TODO: Collapse this and Command::update_cartfile
64
+ verify_carthage
65
+
66
+ # 1. Generate Cartfile
67
+ cartfile_path = options.cartfile_path
68
+ File.open(cartfile_path, "w") do |file|
69
+ file.write <<-EOF
70
+ github "BranchMetrics/ios-branch-deep-linking"
71
+ EOF
72
+ end
73
+
74
+ # 2. carthage update
75
+ sh "carthage #{options.carthage_command}", chdir: File.dirname(config.cartfile_path)
76
+
77
+ # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
78
+ helper.add_change cartfile_path
79
+ helper.add_change "#{cartfile_path}.resolved"
80
+ helper.add_change options.xcodeproj_path
81
+
82
+ # 4. Add to target dependencies
83
+ frameworks_group = options.xcodeproj.frameworks_group
84
+ branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
85
+ target = options.target
86
+ target.frameworks_build_phase.add_file_reference branch_framework
87
+
88
+ # 5. Create a copy-frameworks build phase
89
+ carthage_build_phase = target.new_shell_script_build_phase "carthage copy-frameworks"
90
+ carthage_build_phase.shell_script = "/usr/local/bin/carthage copy-frameworks"
91
+
92
+ carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
93
+ carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
94
+
95
+ update_framework_search_paths "$(SRCROOT)/Carthage/Build/iOS"
96
+
97
+ options.xcodeproj.save
98
+
99
+ return unless options.commit
100
+
101
+ # For now, add Carthage folder to SCM
102
+
103
+ # 6. Add the Carthage folder to the commit (in case :commit param specified)
104
+ carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from(Pathname.pwd)
105
+ cartfile_pathname = Pathname.new(cartfile_path).relative_path_from Pathname.pwd
106
+ helper.add_change carthage_folder_path
107
+ sh "git", "add", cartfile_pathname.to_s, "#{cartfile_pathname}.resolved", carthage_folder_path.to_s
108
+ end
109
+
110
+ def add_direct(options)
111
+ # Put the framework in the path for any existing Frameworks group in the project.
112
+ frameworks_group = options.xcodeproj.frameworks_group
113
+ framework_path = File.join frameworks_group.real_path, "Branch.framework"
114
+ raise "#{framework_path} exists." if File.exist? framework_path
115
+
116
+ say "Finding current framework release"
117
+
118
+ # Find the latest release from GitHub.
119
+ releases = JSON.parse helper.fetch "https://api.github.com/repos/BranchMetrics/ios-branch-deep-linking/releases"
120
+ current_release = releases.first
121
+ # Get the download URL for the framework.
122
+ framework_asset = current_release["assets"][0]
123
+ framework_url = framework_asset["browser_download_url"]
124
+
125
+ say "Downloading Branch.framework v. #{current_release['tag_name']} (#{framework_asset['size']} bytes zipped)"
126
+
127
+ Dir.mktmpdir do |download_folder|
128
+ zip_path = File.join download_folder, "Branch.framework.zip"
129
+
130
+ File.unlink zip_path if File.exist? zip_path
131
+
132
+ # Download the framework zip
133
+ helper.download framework_url, zip_path
134
+
135
+ say "Unzipping Branch.framework"
136
+
137
+ # Unzip
138
+ Zip::File.open zip_path do |zip_file|
139
+ # Start with just the framework and add dSYM, etc., later
140
+ zip_file.glob "Carthage/Build/iOS/Branch.framework/**/*" do |entry|
141
+ filename = entry.name.sub %r{^Carthage/Build/iOS}, frameworks_group.real_path.to_s
142
+ FileUtils.mkdir_p File.dirname filename
143
+ entry.extract filename
144
+ end
145
+ end
146
+ end
147
+
148
+ # Now the current framework is in framework_path
149
+
150
+ say "Adding to #{options.xcodeproj_path}"
151
+
152
+ # Add as a dependency in the Frameworks group
153
+ framework = frameworks_group.new_file "Branch.framework" # relative to frameworks_group.real_path
154
+ options.target.frameworks_build_phase.add_file_reference framework, true
155
+
156
+ update_framework_search_paths "$(SRCROOT)"
157
+
158
+ options.xcodeproj.save
159
+
160
+ helper.add_change options.xcodeproj_path
161
+ helper.add_change framework_path
162
+ sh "git", "add", framework_path if options.commit
163
+
164
+ say "Done. ✅"
165
+ end
166
+
167
+ def update_framework_search_paths(path)
168
+ # Make sure this is in the FRAMEWORK_SEARCH_PATHS if we just added it.
169
+ if config.xcodeproj.frameworks_group.files.count == 1
170
+ target = config.target
171
+ target.build_configurations.each do |c|
172
+ # this accounts for project-level settings as well
173
+ setting = target.resolved_build_setting("FRAMEWORK_SEARCH_PATHS")[c.name] || []
174
+ next if setting.include?(path) || setting.include?("#{path}/**")
175
+ setting << path
176
+
177
+ c.build_settings["FRAMEWORK_SEARCH_PATHS"] = setting
178
+ end
179
+ end
180
+ # If it already existed, it's almost certainly already in FRAMEWORK_SEARCH_PATHS.
181
+ end
182
+
183
+ def update_podfile(options)
184
+ verify_cocoapods
185
+
186
+ podfile_path = options.podfile_path
187
+ return false if podfile_path.nil?
188
+
189
+ # 1. Patch Podfile. Return if no change (Branch pod already present).
190
+ return false unless PatchHelper.patch_podfile podfile_path
191
+
192
+ # 2. pod install
193
+ # command = "PATH='#{ENV['PATH']}' pod install"
194
+ command = 'pod install'
195
+ command += ' --repo-update' if options.pod_repo_update
196
+
197
+ sh command, chdir: File.dirname(config.podfile_path)
198
+
199
+ # 3. Add Podfile and Podfile.lock to commit (in case :commit param specified)
200
+ helper.add_change podfile_path
201
+ helper.add_change "#{podfile_path}.lock"
202
+
203
+ # 4. Check if Pods folder is under SCM
204
+ pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
205
+ `git ls-files #{pods_folder_path.to_s.shellescape} --error-unmatch > /dev/null 2>&1`
206
+ return true unless $?.exitstatus == 0
207
+
208
+ # 5. If so, add the Pods folder to the commit (in case :commit param specified)
209
+ helper.add_change pods_folder_path
210
+ sh "git", "add", pods_folder_path.to_s if options.commit
211
+
212
+ true
213
+ end
214
+
215
+ def update_cartfile(options, project)
216
+ verify_carthage
217
+
218
+ cartfile_path = options.cartfile_path
219
+ return false if cartfile_path.nil?
220
+
221
+ # 1. Patch Cartfile. Return if no change (Branch already present).
222
+ return false unless PatchHelper.patch_cartfile cartfile_path
223
+
224
+ # 2. carthage update
225
+ sh "carthage #{options.carthage_command} ios-branch-deep-linking", chdir: File.dirname(config.cartfile_path)
226
+
227
+ # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
228
+ helper.add_change cartfile_path
229
+ helper.add_change "#{cartfile_path}.resolved"
230
+ helper.add_change options.xcodeproj_path
231
+
232
+ # 4. Add to target dependencies
233
+ frameworks_group = project.frameworks_group
234
+ branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
235
+ target = options.target
236
+ target.frameworks_build_phase.add_file_reference branch_framework
237
+
238
+ # 5. Add to copy-frameworks build phase
239
+ carthage_build_phase = target.build_phases.find do |phase|
240
+ phase.respond_to?(:shell_script) && phase.shell_script =~ /carthage\s+copy-frameworks/
241
+ end
242
+
243
+ if carthage_build_phase
244
+ carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
245
+ carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
246
+ end
247
+
248
+ # 6. Check if Carthage folder is under SCM
249
+ carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from Pathname.pwd
250
+ `git ls-files #{carthage_folder_path.to_s.shellescape} --error-unmatch > /dev/null 2>&1`
251
+ return true unless $?.exitstatus == 0
252
+
253
+ # 7. If so, add the Carthage folder to the commit (in case :commit param specified)
254
+ helper.add_change carthage_folder_path
255
+ sh "git", "add", carthage_folder_path.to_s if options.commit
256
+
257
+ true
258
+ end
259
+
260
+ def verify_cocoapods
261
+ pod_cmd = `which pod`
262
+ return unless pod_cmd.empty?
263
+
264
+ gem_cmd = `which gem`
265
+ if gem_cmd.empty?
266
+ say "'pod' command not available in PATH and 'gem' command not available in PATH to install cocoapods."
267
+ exit(-1)
268
+ end
269
+
270
+ install = confirm "'pod' command not available in PATH. Install cocoapods (may require a sudo password)?", true
271
+ unless install
272
+ say "Please install cocoapods or use --no-add-sdk to continue."
273
+ exit(-1)
274
+ end
275
+
276
+ gem_home = Gem.dir
277
+ if gem_home && File.writable?(gem_home)
278
+ sh "gem install cocoapods"
279
+ else
280
+ sh "sudo gem install cocoapods"
281
+ end
282
+
283
+ # Ensure master podspec repo is set up (will update if it exists).
284
+ sh "pod setup"
285
+ end
286
+
287
+ def verify_carthage
288
+ carthage_cmd = `which carthage`
289
+ return unless carthage_cmd.empty?
290
+
291
+ brew_cmd = `which brew`
292
+ if brew_cmd.empty?
293
+ say "'carthage' command not available in PATH and 'brew' command not available in PATH to install 'carthage'."
294
+ exit(-1)
295
+ end
296
+
297
+ install = confirm "'carthage' command not available in PATH. Use Homebrew to install carthage?", true
298
+ unless install
299
+ say "Please install carthage or use --no-add-sdk to continue."
300
+ exit(-1)
301
+ end
302
+
303
+ sh "brew install carthage"
304
+ end
305
+
306
+ def verify_git
307
+ return unless config.commit
308
+
309
+ git_cmd = `which git`
310
+ return unless git_cmd.empty?
311
+
312
+ xcode_select_path = `which xcode-select`
313
+ if xcode_select_path.empty?
314
+ say "'git' command not available in PATH and 'xcode-select' command not available in PATH to install 'git'."
315
+ exit(-1)
316
+ end
317
+
318
+ install = confirm "'git' command not available in PATH. Install Xcode command-line tools (requires password)?", true
319
+ unless install
320
+ say "Please install Xcode command tools or leave out the --commit option to continue."
321
+ exit(-1)
322
+ end
323
+
324
+ sh "xcode-select --install"
325
+ end
326
+ end
327
+ end
328
+ end
329
+ end
@@ -9,49 +9,28 @@ module BranchIOCLI
9
9
 
10
10
  def initialize(name = :branch, &b)
11
11
  namespace name do
12
- report_task
13
- setup_task
14
- validate_task
12
+ add_branch_task :report, "Generate a brief Branch report"
13
+ add_branch_task :setup, "Set a project up with the Branch SDK"
14
+ add_branch_task :validate, "Validate universal links in one or more projects"
15
15
  end
16
16
  end
17
17
 
18
- def report_task
19
- desc "Generate a brief Branch report"
20
- task :report, %i{paths options} do |task, args|
21
- paths = args[:paths]
22
- paths = [paths] unless paths.respond_to?(:each)
23
-
24
- paths.each do |path|
25
- Dir.chdir(path) do |p|
26
- Command::ReportCommand.new(Configuration::ReportConfiguration.wrapper(args[:options])).run!
27
- end
28
- end
29
- end
30
- end
31
-
32
- def setup_task
33
- desc "Set a project up with the Branch SDK"
34
- task :setup, %i{paths options} do |task, args|
35
- paths = args[:paths]
36
- paths = [paths] unless paths.respond_to?(:each)
37
-
38
- paths.each do |path|
39
- Dir.chdir(path) do |p|
40
- Command::SetupCommand.new(Configuration::SetupConfiguration.wrapper(args[:options])).run!
41
- end
42
- end
43
- end
44
- end
18
+ def add_branch_task(task_name, description)
19
+ command_class = Command.const_get("#{task_name.to_s.capitalize}Command")
20
+ configuration_class = Configuration.const_get("#{task_name.to_s.capitalize}Configuration")
45
21
 
46
- def validate_task
47
- desc "Validate universal links in one or more projects"
48
- task :validate, %i{paths options} do |task, args|
22
+ desc description
23
+ task task_name, %i{paths options} do |task, args|
49
24
  paths = args[:paths]
50
25
  paths = [paths] unless paths.respond_to?(:each)
51
26
 
52
27
  paths.each do |path|
53
- Dir.chdir(path) do |p|
54
- Command::ValidateCommand.new(Configuration::ValidateConfiguration.wrapper(args[:options] || {})).run!
28
+ Dir.chdir(path) do
29
+ begin
30
+ command_class.new(configuration_class.wrapper(args[:options] || {})).run!
31
+ rescue StandardError => e
32
+ say "Error from #{task_name} task in #{path}: #{e.message}"
33
+ end
55
34
  end
56
35
  end
57
36
  end
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.12.2"
2
+ VERSION = "0.12.3"
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.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branch
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-22 00:00:00.000000000 Z
12
+ date: 2017-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: artii
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: CFPropertyList
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -306,12 +320,16 @@ files:
306
320
  - lib/branch_io_cli/configuration/option.rb
307
321
  - lib/branch_io_cli/configuration/option_wrapper.rb
308
322
  - lib/branch_io_cli/configuration/report_configuration.rb
323
+ - lib/branch_io_cli/configuration/report_options.rb
309
324
  - lib/branch_io_cli/configuration/setup_configuration.rb
325
+ - lib/branch_io_cli/configuration/setup_options.rb
310
326
  - lib/branch_io_cli/configuration/validate_configuration.rb
327
+ - lib/branch_io_cli/configuration/validate_options.rb
311
328
  - lib/branch_io_cli/configuration/xcode_settings.rb
312
329
  - lib/branch_io_cli/core_ext.rb
313
330
  - lib/branch_io_cli/core_ext/io.rb
314
331
  - lib/branch_io_cli/core_ext/regexp.rb
332
+ - lib/branch_io_cli/core_ext/xcodeproj.rb
315
333
  - lib/branch_io_cli/format.rb
316
334
  - lib/branch_io_cli/format/highline_format.rb
317
335
  - lib/branch_io_cli/format/markdown_format.rb
@@ -323,8 +341,8 @@ files:
323
341
  - lib/branch_io_cli/helper/methods.rb
324
342
  - lib/branch_io_cli/helper/patch_helper.rb
325
343
  - lib/branch_io_cli/helper/report_helper.rb
344
+ - lib/branch_io_cli/helper/tool_helper.rb
326
345
  - lib/branch_io_cli/helper/util.rb
327
- - lib/branch_io_cli/helper/xcodeproj_ext.rb
328
346
  - lib/branch_io_cli/rake_task.rb
329
347
  - lib/branch_io_cli/version.rb
330
348
  homepage: http://github.com/BranchMetrics/branch_io_cli
@@ -347,7 +365,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
365
  version: '0'
348
366
  requirements: []
349
367
  rubyforge_project:
350
- rubygems_version: 2.7.2
368
+ rubygems_version: 2.7.3
351
369
  signing_key:
352
370
  specification_version: 4
353
371
  summary: Branch.io command-line interface for mobile app integration