branch_io_cli 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9adda8f92100e01cd272fa97fe2bf8b71db6b664
4
- data.tar.gz: c91ec03d311711ea448aec62ffa1db6f1f401e77
3
+ metadata.gz: 334a3a4f55aeb27b4a683036fb8c26c576c93e0e
4
+ data.tar.gz: 74ea173bc48c7eedd4868098612064ec6369a21c
5
5
  SHA512:
6
- metadata.gz: 3ce717958b072775a9fbd789c249c23a80972ba8fe45cd2a546074d03b2b019d9fa6fdc2a580539193abe289579470617db34d7a46e8d7a396b30c4d6cbe7325
7
- data.tar.gz: 84a1f6ef67c575e34c31c9306eeb62aea5858bf3005d7990769d5eba1bc8e4adbcdaa3561aca91cf4324b008a3d0114cefc049b9693e0ba704b649320cc054ab
6
+ metadata.gz: 49ff44e9f2aa8c44a9df062ce6a650682823c278028aa1ad6be2488d0c6ca603fe8baf60ce8bc23b7c5c316a9339b58d51682a9909e88eb2448c57f02f43f962
7
+ data.tar.gz: 6efb3a1bf7349f0b8772ef5e6f03e34b5fcd834004eef6799bcbf5de2eb4b4a719fcf3f549fa77304409d528e09ecc300d04475ec839b3bb681452608b04d855
data/README.md CHANGED
@@ -41,25 +41,30 @@ branch_io setup
41
41
  Integrates the Branch SDK into a native app project. This currently supports iOS only.
42
42
  It will infer the project location if there is exactly one .xcodeproj anywhere under
43
43
  the current directory, excluding any in a Pods or Carthage folder. Otherwise, specify
44
- the project location using the `--xcodeproj` option.
44
+ the project location using the `--xcodeproj` option, or the CLI will prompt you for the
45
+ location.
45
46
 
46
47
  If a Podfile or Cartfile is detected, the Branch SDK will be added to the relevant
47
48
  configuration file and the dependencies updated to include the Branch framework.
48
49
  This behavior may be suppressed using `--no_add_sdk`. If no Podfile or Cartfile
49
50
  is found, and Branch.framework is not already among the project's dependencies,
50
- you will be prompted for a number of choices.
51
+ you will be prompted for a number of choices, including setting up CocoaPods or
52
+ Carthage for the project or directly installing the Branch.framework.
51
53
 
52
54
  By default, all supplied Universal Link domains are validated. If validation passes,
53
55
  the setup continues. If validation fails, no further action is taken. Suppress
54
56
  validation using `--no_validate` or force changes when validation fails using
55
57
  `--force`.
56
58
 
57
- All relevant project settings are modified. The Branch keys are added to the Info.plist,
59
+ By default, this command will look for the first app target in the project. Test
60
+ targets are not supported. To set up an extension target, supply the `--target` option.
61
+
62
+ All relevant target settings are modified. The Branch keys are added to the Info.plist,
58
63
  along with the `branch_universal_link_domains` key for custom domains (when `--domains`
59
- is used). All domains are added to the project's Associated Domains entitlements.
60
- An entitlements file is added if none is found. Optionally, if `--frameworks` is
61
- specified, this command can add a list of system frameworks to the project (e.g.,
62
- AdSupport, CoreSpotlight, SafariServices).
64
+ is used). For app targets, all domains are added to the project's Associated Domains
65
+ entitlement. An entitlements file is also added for app targets if none is found.
66
+ Optionally, if `--frameworks` is specified, this command can add a list of system
67
+ frameworks to the target's dependencies (e.g., AdSupport, CoreSpotlight, SafariServices).
63
68
 
64
69
  A language-specific patch is applied to the AppDelegate (Swift or Objective-C).
65
70
  This can be suppressed using `--no_patch_source`.
@@ -114,6 +119,10 @@ signing team identifiers in the project as well as the app's Associated Domains.
114
119
  It requests the apple-app-site-association file for each domain and validates
115
120
  the file against the project's settings.
116
121
 
122
+ Only app targets are supported for this command. By default, it will validate the first.
123
+ If your project has multiple app targets, specify the <%= color('--target', BOLD) %> option to validate other
124
+ targets.
125
+
117
126
  #### Options
118
127
 
119
128
  |Option|Description|
@@ -20,25 +20,30 @@ EOF
20
20
  Integrates the Branch SDK into a native app project. This currently supports iOS only.
21
21
  It will infer the project location if there is exactly one .xcodeproj anywhere under
22
22
  the current directory, excluding any in a Pods or Carthage folder. Otherwise, specify
23
- the project location using the <%= color('--xcodeproj', BOLD) %> option.
23
+ the project location using the <%= color('--xcodeproj', BOLD) %> option, or the CLI will prompt you for the
24
+ location.
24
25
 
25
26
  If a Podfile or Cartfile is detected, the Branch SDK will be added to the relevant
26
27
  configuration file and the dependencies updated to include the Branch framework.
27
28
  This behavior may be suppressed using <%= color('--no_add_sdk', BOLD) %>. If no Podfile or Cartfile
28
29
  is found, and Branch.framework is not already among the project's dependencies,
29
- you will be prompted for a number of choices.
30
+ you will be prompted for a number of choices, including setting up CocoaPods or
31
+ Carthage for the project or directly installing the Branch.framework.
30
32
 
31
33
  By default, all supplied Universal Link domains are validated. If validation passes,
32
34
  the setup continues. If validation fails, no further action is taken. Suppress
33
35
  validation using <%= color('--no_validate', BOLD) %> or force changes when validation fails using
34
36
  <%= color('--force', BOLD) %>.
35
37
 
36
- All relevant project settings are modified. The Branch keys are added to the Info.plist,
38
+ By default, this command will look for the first app target in the project. Test
39
+ targets are not supported. To set up an extension target, supply the <%= color('--target', BOLD) %> option.
40
+
41
+ All relevant target settings are modified. The Branch keys are added to the Info.plist,
37
42
  along with the <%= color('branch_universal_link_domains', BOLD) %> key for custom domains (when <%= color('--domains', BOLD) %>
38
- is used). All domains are added to the project's Associated Domains entitlements.
39
- An entitlements file is added if none is found. Optionally, if <%= color('--frameworks', BOLD) %> is
40
- specified, this command can add a list of system frameworks to the project (e.g.,
41
- AdSupport, CoreSpotlight, SafariServices).
43
+ is used). For app targets, all domains are added to the project's Associated Domains
44
+ entitlement. An entitlements file is also added for app targets if none is found.
45
+ Optionally, if <%= color('--frameworks', BOLD) %> is specified, this command can add a list of system
46
+ frameworks to the target's dependencies (e.g., AdSupport, CoreSpotlight, SafariServices).
42
47
 
43
48
  A language-specific patch is applied to the AppDelegate (Swift or Objective-C).
44
49
  This can be suppressed using <%= color('--no_patch_source', BOLD) %>.
@@ -94,17 +99,22 @@ EOF
94
99
  c.syntax = "branch_io validate [OPTIONS]"
95
100
  c.summary = "Validates all Universal Link domains configured in a project"
96
101
  c.description = <<EOF
97
- This command validates all Universal Link domains configured in a project without making any modification.
98
- It validates both Branch and non-Branch domains. Unlike web-based Universal Link validators,
99
- this command operates directly on the project. It finds the bundle and
100
- signing team identifiers in the project as well as the app's Associated Domains.
101
- It requests the apple-app-site-association file for each domain and validates
102
- the file against the project's settings.
103
-
104
- All parameters are optional. If <%= color('--domains', BOLD) %> is specified, the list of Universal Link domains in the
105
- Associated Domains entitlement must exactly match this list, without regard to order. If no <%= color('--domains', BOLD) %>
106
- are provided, validation passes if at least one Universal Link domain is configured and passes validation,
107
- and no Universal Link domain is present that does not pass validation.
102
+ This command validates all Universal Link domains configured in a project without making any
103
+ modification. It validates both Branch and non-Branch domains. Unlike web-based Universal
104
+ Link validators, this command operates directly on the project. It finds the bundle and
105
+ signing team identifiers in the project as well as the app's Associated Domains. It requests
106
+ the apple-app-site-association file for each domain and validates the file against the
107
+ project's settings.
108
+
109
+ Only app targets are supported for this command. By default, it will validate the first.
110
+ If your project has multiple app targets, specify the <%= color('--target', BOLD) %> option to validate other
111
+ targets.
112
+
113
+ All parameters are optional. If <%= color('--domains', BOLD) %> is specified, the list of Universal Link domains in
114
+ the Associated Domains entitlement must exactly match this list, without regard to order. If
115
+ no <%= color('--domains', BOLD) %> are provided, validation passes if at least one Universal Link domain is
116
+ configured and passes validation, and no Universal Link domain is present that does not pass
117
+ validation.
108
118
 
109
119
  See https://github.com/BranchMetrics/branch_io_cli#validate-command for more information.
110
120
  EOF
@@ -14,24 +14,25 @@ module BranchIOCLI
14
14
 
15
15
  update_podfile(options) || update_cartfile(options, xcodeproj)
16
16
 
17
- target = options.target # may be nil
17
+ target_name = options.target # may be nil
18
+ is_app_target = !Helper::ConfigurationHelper.target.extension_target_type?
18
19
 
19
- if !options.no_validate &&
20
- !helper.validate_team_and_bundle_ids_from_aasa_files(xcodeproj, target, @domains)
20
+ if is_app_target && !options.no_validate &&
21
+ !helper.validate_team_and_bundle_ids_from_aasa_files(xcodeproj, target_name, @domains)
21
22
  say "Universal Link configuration failed validation."
22
23
  helper.errors.each { |error| say " #{error}" }
23
24
  return unless options.force
24
- elsif !options.no_validate
25
+ elsif is_app_target && !options.no_validate
25
26
  say "Universal Link configuration passed validation. ✅"
26
27
  end
27
28
 
28
29
  # the following calls can all raise IOError
29
- helper.add_keys_to_info_plist xcodeproj, target, @keys
30
- helper.add_branch_universal_link_domains_to_info_plist xcodeproj, target, @domains
31
- new_path = helper.add_universal_links_to_project xcodeproj, target, @domains, false
30
+ helper.add_keys_to_info_plist xcodeproj, target_name, @keys
31
+ helper.add_branch_universal_link_domains_to_info_plist xcodeproj, target_name, @domains if is_app_target
32
+ new_path = helper.add_universal_links_to_project xcodeproj, target_name, @domains, false if is_app_target
32
33
  `git add #{new_path}` if options.commit && new_path
33
34
 
34
- helper.add_system_frameworks xcodeproj, target, options.frameworks unless options.frameworks.nil? || options.frameworks.empty?
35
+ helper.add_system_frameworks xcodeproj, target_name, options.frameworks unless options.frameworks.nil? || options.frameworks.empty?
35
36
 
36
37
  xcodeproj.save
37
38
 
@@ -143,7 +144,7 @@ module BranchIOCLI
143
144
  # 4. Add to target depependencies
144
145
  frameworks_group = project.frameworks_group
145
146
  branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
146
- target = helper.target_from_project project, options.target
147
+ target = ConfigurationHelper.target
147
148
  target.frameworks_build_phase.add_file_reference branch_framework
148
149
 
149
150
  # 5. Add to copy-frameworks build phase
@@ -6,28 +6,77 @@ require "zip"
6
6
 
7
7
  module BranchIOCLI
8
8
  module Helper
9
+ # rubocop: disable Metrics/ClassLength
9
10
  class ConfigurationHelper
10
11
  class << self
12
+ APP_LINK_REGEXP = /\.app\.link$|\.test-app\.link$/
13
+
11
14
  attr_accessor :xcodeproj_path
12
15
  attr_accessor :xcodeproj
13
16
  attr_accessor :keys
14
17
  attr_accessor :all_domains
15
18
  attr_accessor :podfile_path
16
19
  attr_accessor :cartfile_path
20
+ attr_accessor :target
17
21
 
18
22
  def validate_setup_options(options)
23
+ print_identification "setup"
24
+
19
25
  say "--force is ignored when --no_validate is used." if options.no_validate && options.force
20
26
 
21
27
  validate_xcodeproj_path options
28
+ validate_target options
22
29
  validate_keys_from_setup_options options
23
- validate_all_domains options
30
+ validate_all_domains options, !@target.extension_target_type?
24
31
  validate_buildfile_path options, "Podfile"
25
32
  validate_buildfile_path options, "Cartfile"
33
+
34
+ print_setup_configuration
35
+
26
36
  validate_sdk_addition options
27
37
  end
28
38
 
29
39
  def validate_validation_options(options)
40
+ print_identification "validate"
41
+
30
42
  validate_xcodeproj_path options
43
+ validate_target options, false
44
+
45
+ print_validation_configuration
46
+ end
47
+
48
+ def print_identification(command)
49
+ say <<EOF
50
+
51
+ <%= color("branch_io #{command} v. #{VERSION}", BOLD) %>
52
+
53
+ EOF
54
+ end
55
+
56
+ def print_setup_configuration
57
+ say <<EOF
58
+
59
+ <%= color('Configuration:', BOLD) %>
60
+
61
+ <%= color('Xcode project:', BOLD) %> #{@xcodeproj_path}
62
+ <%= color('Target:', BOLD) %> #{@target.name}
63
+ <%= color('Live key:', BOLD) %> #{@keys[:live] || '(none)'}
64
+ <%= color('Test key:', BOLD) %> #{@keys[:test] || '(none)'}
65
+ <%= color('Domains:', BOLD) %> #{@all_domains}
66
+ <%= color('Podfile:', BOLD) %> #{@podfile_path || '(none)'}
67
+ <%= color('Cartfile:', BOLD) %> #{@cartfile_path || '(none)'}
68
+
69
+ EOF
70
+ end
71
+
72
+ def print_validation_configuration
73
+ say <<EOF
74
+ <%= color('Configuration:', BOLD) %>
75
+
76
+ <%= color('Xcode project:', BOLD) %> #{@xcodeproj_path}
77
+ <%= color('Target:', BOLD) %> #{@target.name}
78
+ <%= color('Domains:', BOLD) %> #{@all_domains}
79
+ EOF
31
80
  end
32
81
 
33
82
  def validate_keys_from_setup_options(options)
@@ -47,13 +96,26 @@ module BranchIOCLI
47
96
  end
48
97
  end
49
98
 
50
- def validate_all_domains(options)
51
- app_link_subdomains = app_link_subdomains options
52
- custom_domains = options.domains || []
99
+ def validate_all_domains(options, required = true)
100
+ app_link_roots = app_link_roots_from_domains options.domains
101
+
102
+ unless options.app_link_subdomain.nil? || app_link_roots.include?(options.app_link_subdomain)
103
+ app_link_roots << options.app_link_subdomain
104
+ end
105
+
106
+ # app_link_roots now contains options.app_link_subdomain, if supplied, and the roots of any
107
+ # .app.link or .test-app.link domains provided via options.domains.
108
+
109
+ app_link_subdomains = app_link_subdomains_from_roots app_link_roots
110
+
111
+ custom_domains = custom_domains_from_domains options.domains
112
+
53
113
  @all_domains = (app_link_subdomains + custom_domains).uniq
54
114
 
55
- while @all_domains.empty?
56
- @all_domains = ask "Please enter domains as a comma-separated list: ", ->(str) { str.split "," }
115
+ while required && @all_domains.empty?
116
+ domains = ask "Please enter domains as a comma-separated list: ", ->(str) { str.split "," }
117
+
118
+ @all_domains = all_domains_from_domains domains
57
119
  end
58
120
  end
59
121
 
@@ -92,13 +154,54 @@ module BranchIOCLI
92
154
  end
93
155
  end
94
156
 
95
- def app_link_subdomains(options)
96
- app_link_subdomain = options.app_link_subdomain
97
- live_key = options.live_key
98
- test_key = options.test_key
99
- return [] if live_key.nil? and test_key.nil?
157
+ def validate_target(options, allow_extensions = true)
158
+ non_test_targets = @xcodeproj.targets.reject(&:test_target_type?)
159
+ raise "No non-test target found in project" if non_test_targets.empty?
160
+
161
+ valid_targets = non_test_targets.reject { |t| !allow_extensions && t.extension_target_type? }
162
+
163
+ begin
164
+ target = BranchHelper.target_from_project @xcodeproj, options.target
165
+
166
+ # If a test target was explicitly specified.
167
+ raise "Cannot use test targets" if target.test_target_type?
168
+
169
+ # If an extension target was explicitly specified for validation.
170
+ raise "Extension targets not allowed for this command" if !allow_extensions && target.extension_target_type?
171
+
172
+ @target = target
173
+ rescue StandardError => e
174
+ say e.message
175
+
176
+ choice = choose do |menu|
177
+ valid_targets.each { |t| menu.choice t.name }
178
+ menu.prompt = "Which target do you wish to use? "
179
+ end
180
+
181
+ @target = @xcodeproj.targets.find { |t| t.name = choice }
182
+ end
183
+ end
184
+
185
+ def app_link_roots_from_domains(domains)
186
+ return [] if domains.nil?
187
+
188
+ domains.select { |d| d =~ APP_LINK_REGEXP }
189
+ .map { |d| d.sub(APP_LINK_REGEXP, '').sub(/-alternate$/, '') }
190
+ .uniq
191
+ end
192
+
193
+ def custom_domains_from_domains(domains)
194
+ return [] if domains.nil?
195
+ domains.reject { |d| d =~ APP_LINK_REGEXP }.uniq
196
+ end
197
+
198
+ def app_link_subdomains(root)
199
+ app_link_subdomain = root
100
200
  return [] if app_link_subdomain.nil?
101
201
 
202
+ live_key = @keys[:live]
203
+ test_key = @keys[:test]
204
+
102
205
  domains = []
103
206
  unless live_key.nil?
104
207
  domains += [
@@ -115,6 +218,17 @@ module BranchIOCLI
115
218
  domains
116
219
  end
117
220
 
221
+ def app_link_subdomains_from_roots(roots)
222
+ roots.inject([]) { |domains, root| domains + app_link_subdomains(root) }
223
+ end
224
+
225
+ def all_domains_from_domains(domains)
226
+ app_link_roots = app_link_roots_from_domains domains
227
+ app_link_subdomains = app_link_subdomains_from_roots app_link_roots
228
+ custom_domains = custom_domains_from_domains domains
229
+ custom_domains + app_link_subdomains
230
+ end
231
+
118
232
  def validate_buildfile_path(options, filename)
119
233
  # Disable Podfile/Cartfile update if --no_add_sdk is present
120
234
  return if options.no_add_sdk
@@ -364,4 +478,5 @@ EOF
364
478
  end
365
479
  end
366
480
  end
481
+ # rubocop enable: Metrics/ClassLength
367
482
  end
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.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.3.1
4
+ version: 0.3.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-20 00:00:00.000000000 Z
12
+ date: 2017-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander