branch_io_cli 0.4.2 → 0.5.0

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: 7b2291799982aa8205535d5f28f0b4b372c2726b
4
- data.tar.gz: 9986e2a7e85b74827fda5c4abd30a6b979d1b137
3
+ metadata.gz: 5f269c7f617c87a8f5850bbb836a909dd272fb0f
4
+ data.tar.gz: 91b44ebe0922c603e3e89a4725adae1917dce458
5
5
  SHA512:
6
- metadata.gz: e51e2863451a8deebb9fad4046a797893dcc776ec1eaa88c80fc13d2ea2af6f59fd9594fd88dc0a92a5dc1514b27b73d56bad4f0ab0f8f772e6ef5f8d7707e3a
7
- data.tar.gz: 06e4ecb04f1c65eee5636eb1d1dc7f6776ac50d73b511bfd7d47b50f415465d7f24d105c419c7506823a00a18039d28f161371bfd6ffc90f6c6f0b733b1c1e85
6
+ metadata.gz: 72f42f3ae7b88c0491560360c93ca896c6c18da4d17edef7458df1f741375e50eda5b0bb2eeb6f57e86bdfd6ab38f8b641264ceeba2e91e651b8fcffff581a14
7
+ data.tar.gz: 0c2ddfedf72348323628c7fcd11b26a9cf30c1b7204b3da66c81c1ba106e8f404a5ab5a6a969837d790cf37dd56310c7e9c1c3b48d3977c754f6ae62919a6818
data/README.md CHANGED
@@ -46,14 +46,14 @@ location.
46
46
 
47
47
  If a Podfile or Cartfile is detected, the Branch SDK will be added to the relevant
48
48
  configuration file and the dependencies updated to include the Branch framework.
49
- This behavior may be suppressed using `--no_add_sdk`. If no Podfile or Cartfile
49
+ This behavior may be suppressed using `--no-add-sdk`. If no Podfile or Cartfile
50
50
  is found, and Branch.framework is not already among the project's dependencies,
51
51
  you will be prompted for a number of choices, including setting up CocoaPods or
52
52
  Carthage for the project or directly installing the Branch.framework.
53
53
 
54
54
  By default, all supplied Universal Link domains are validated. If validation passes,
55
55
  the setup continues. If validation fails, no further action is taken. Suppress
56
- validation using `--no_validate` or force changes when validation fails using
56
+ validation using `--no-validate` or force changes when validation fails using
57
57
  `--force`.
58
58
 
59
59
  By default, this command will look for the first app target in the project. Test
@@ -67,7 +67,7 @@ Optionally, if `--frameworks` is specified, this command can add a list of syste
67
67
  frameworks to the target's dependencies (e.g., AdSupport, CoreSpotlight, SafariServices).
68
68
 
69
69
  A language-specific patch is applied to the AppDelegate (Swift or Objective-C).
70
- This can be suppressed using `--no_patch_source`.
70
+ This can be suppressed using `--no-patch-source`.
71
71
 
72
72
  #### Prerequisites
73
73
 
@@ -86,26 +86,52 @@ command, respectively, available in your path.
86
86
 
87
87
  |Option|Description|
88
88
  |------|-----------|
89
- |--live_key key_live_xxxx|Branch live key|
90
- |--test_key key_test_yyyy|Branch test key|
91
- |--app_link_subdomain myapp|Branch app.link subdomain, e.g. myapp for myapp.app.link|
92
- |--domains example.com,www.example.com|Comma-separated list of custom domain(s) or non-Branch domain(s)|
93
- |--uri_scheme myurischeme[://]|Custom URI scheme used in the Branch Dashboard for this app|
89
+ |-L, --live-key key_live_xxxx|Branch live key|
90
+ |-T, --test-key key_test_yyyy|Branch test key|
91
+ |--app-link-subdomain myapp|Branch app.link subdomain, e.g. myapp for myapp.app.link|
92
+ |-D, --domains example.com,www.example.com|Comma-separated list of custom domain(s) or non-Branch domain(s)|
93
+ |-U, --uri-scheme myurischeme[://]|Custom URI scheme used in the Branch Dashboard for this app|
94
94
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
95
95
  |--target MyAppTarget|Name of a target to modify in the Xcode project|
96
96
  |--podfile /path/to/Podfile|Path to the Podfile for the project|
97
97
  |--cartfile /path/to/Cartfile|Path to the Cartfile for the project|
98
98
  |--frameworks AdSupport,CoreSpotlight,SafariServices|Comma-separated list of system frameworks to add to the project|
99
- |--no_pod_repo_update|Skip update of the local podspec repo before installing|
100
- |--no_validate|Skip validation of Universal Link configuration|
101
- |--force|Update project even if Universal Link validation fails|
102
- |--no_add_sdk|Don't add the Branch framework to the project|
103
- |--no_patch_source|Don't add Branch SDK calls to the AppDelegate|
104
- |--commit|Commit the results to Git|
99
+ |--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|
100
+ |--[no-]validate|Validate Universal Link configuration (default: yes)|
101
+ |--[no-]force|Update project even if Universal Link validation fails (default: no)|
102
+ |--[no-]add-sdk|Add the Branch framework to the project (default: yes)|
103
+ |--[no-]patch-source|Add Branch SDK calls to the AppDelegate (default: yes)|
104
+ |--[no-]commit|Commit the results to Git (default: no)|
105
105
 
106
106
  All parameters are optional. A live key or test key, or both is required, as well as at least one domain.
107
- Specify --live_key, --test_key or both and --app_link_subdomain, --domains or both. If these are not
108
- specified, this command will prompt you for this information.
107
+ Specify --live-key, --test-key or both and --app-link-subdomain, --domains or both. If these are not
108
+ specified, this command will prompt you for the information.
109
+
110
+ #### Examples
111
+
112
+ ##### Test without validation (can use dummy keys and domains)
113
+
114
+ ```bash
115
+ branch_io setup -L key_live_xxxx -D myapp.app.link --no-validate
116
+ ```
117
+
118
+ ##### Use both live and test keys
119
+
120
+ ```bash
121
+ branch_io setup -L key_live_xxxx -T key_test_yyyy -D myapp.app.link
122
+ ```
123
+
124
+ ##### Use custom or non-Branch domains
125
+
126
+ ```bash
127
+ branch_io setup -D myapp.app.link,example.com,www.example.com
128
+ ```
129
+
130
+ ##### Avoid pod repo update
131
+
132
+ ```bash
133
+ branch_io setup --no-pod-repo-update
134
+ ```
109
135
 
110
136
  ### Validate command
111
137
 
@@ -128,7 +154,7 @@ targets.
128
154
 
129
155
  |Option|Description|
130
156
  |------|-----------|
131
- |--domains example.com,www.example.com|Comma-separated list of domains. May include app.link subdomains.|
157
+ |-D, --domains example.com,www.example.com|Comma-separated list of domains. May include app.link subdomains.|
132
158
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
133
159
  |--target MyAppTarget|Name of a target to modify in the Xcode project|
134
160
 
@@ -1,4 +1,4 @@
1
1
  require "branch_io_cli/cli"
2
- require "branch_io_cli/command"
2
+ require "branch_io_cli/commands"
3
3
  require "branch_io_cli/helper"
4
4
  require "branch_io_cli/version"
@@ -25,14 +25,14 @@ location.
25
25
 
26
26
  If a Podfile or Cartfile is detected, the Branch SDK will be added to the relevant
27
27
  configuration file and the dependencies updated to include the Branch framework.
28
- This behavior may be suppressed using <%= color('--no_add_sdk', BOLD) %>. If no Podfile or Cartfile
28
+ This behavior may be suppressed using <%= color('--no-add-sdk', BOLD) %>. If no Podfile or Cartfile
29
29
  is found, and Branch.framework is not already among the project's dependencies,
30
30
  you will be prompted for a number of choices, including setting up CocoaPods or
31
31
  Carthage for the project or directly installing the Branch.framework.
32
32
 
33
33
  By default, all supplied Universal Link domains are validated. If validation passes,
34
34
  the setup continues. If validation fails, no further action is taken. Suppress
35
- validation using <%= color('--no_validate', BOLD) %> or force changes when validation fails using
35
+ validation using <%= color('--no-validate', BOLD) %> or force changes when validation fails using
36
36
  <%= color('--force', BOLD) %>.
37
37
 
38
38
  By default, this command will look for the first app target in the project. Test
@@ -46,7 +46,7 @@ Optionally, if <%= color('--frameworks', BOLD) %> is specified, this command can
46
46
  frameworks to the target's dependencies (e.g., AdSupport, CoreSpotlight, SafariServices).
47
47
 
48
48
  A language-specific patch is applied to the AppDelegate (Swift or Objective-C).
49
- This can be suppressed using <%= color('--no_patch_source', BOLD) %>.
49
+ This can be suppressed using <%= color('--no-patch-source', BOLD) %>.
50
50
 
51
51
  <%= color('Prerequisites', BOLD) %>
52
52
 
@@ -64,7 +64,7 @@ To add the SDK with CocoaPods or Carthage, you must have the <%= color('pod', BO
64
64
  command, respectively, available in your path.
65
65
 
66
66
  All parameters are optional. A live key or test key, or both is required, as well
67
- as at least one domain. Specify <%= color('--live_key', BOLD) %>, <%= color('--test_key', BOLD) %> or both and <%= color('--app_link_subdomain', BOLD) %>,
67
+ as at least one domain. Specify <%= color('--live-key', BOLD) %>, <%= color('--test-key', BOLD) %> or both and <%= color('--app-link-subdomain', BOLD) %>,
68
68
  <%= color('--domains', BOLD) %> or both. If these are not specified, this command will prompt you
69
69
  for this information.
70
70
 
@@ -72,11 +72,11 @@ See https://github.com/BranchMetrics/branch_io_cli#setup-command for more inform
72
72
  EOF
73
73
 
74
74
  # Required Branch params
75
- c.option "--live_key key_live_xxxx", String, "Branch live key"
76
- c.option "--test_key key_test_yyyy", String, "Branch test key"
77
- c.option "--app_link_subdomain myapp", String, "Branch app.link subdomain, e.g. myapp for myapp.app.link"
78
- c.option "--domains example.com,www.example.com", Array, "Comma-separated list of custom domain(s) or non-Branch domain(s)"
79
- c.option "--uri_scheme myurischeme[://]", String, "Custom URI scheme used in the Branch Dashboard for this app"
75
+ c.option "-L", "--live-key key_live_xxxx", String, "Branch live key"
76
+ c.option "-T", "--test-key key_test_yyyy", String, "Branch test key"
77
+ c.option "--app-link-subdomain myapp", String, "Branch app.link subdomain, e.g. myapp for myapp.app.link"
78
+ c.option "-D", "--domains example.com,www.example.com", Array, "Comma-separated list of custom domain(s) or non-Branch domain(s)"
79
+ c.option "-U", "--uri-scheme myurischeme[://]", String, "Custom URI scheme used in the Branch Dashboard for this app"
80
80
 
81
81
  c.option "--xcodeproj MyProject.xcodeproj", String, "Path to an Xcode project to update"
82
82
  c.option "--target MyAppTarget", String, "Name of a target to modify in the Xcode project"
@@ -84,15 +84,29 @@ EOF
84
84
  c.option "--cartfile /path/to/Cartfile", String, "Path to the Cartfile for the project"
85
85
  c.option "--frameworks AdSupport,CoreSpotlight,SafariServices", Array, "Comma-separated list of system frameworks to add to the project"
86
86
 
87
- c.option "--no_pod_repo_update", TrueClass, "Skip update of the local podspec repo before installing"
88
- c.option "--no_validate", TrueClass, "Skip validation of Universal Link configuration"
89
- c.option "--force", TrueClass, "Update project even if Universal Link validation fails"
90
- c.option "--no_add_sdk", TrueClass, "Don't add the Branch framework to the project"
91
- c.option "--no_patch_source", TrueClass, "Don't add Branch SDK calls to the AppDelegate"
92
- c.option "--commit", TrueClass, "Commit the results to Git"
87
+ c.option "--[no-]pod-repo-update", "Update the local podspec repo before installing (default: yes)"
88
+ c.option "--[no-]validate", "Validate Universal Link configuration (default: yes)"
89
+ c.option "--[no-]force", "Update project even if Universal Link validation fails (default: no)"
90
+ c.option "--[no-]add-sdk", "Add the Branch framework to the project (default: yes)"
91
+ c.option "--[no-]patch-source", "Add Branch SDK calls to the AppDelegate (default: yes)"
92
+ c.option "--[no-]commit", "Commit the results to Git (default: no)"
93
+
94
+ c.example "Test without validation (can use dummy keys and domains)", "branch_io setup -L key_live_xxxx -D myapp.app.link --no-validate"
95
+ c.example "Use both live and test keys", "branch_io setup -L key_live_xxxx -T key_test_yyyy -D myapp.app.link"
96
+ c.example "Use custom or non-Branch domains", "branch_io setup -D myapp.app.link,example.com,www.example.com"
97
+ c.example "Avoid pod repo update", "branch_io setup --no-pod-repo-update"
93
98
 
94
99
  c.action do |args, options|
95
- Command.setup options
100
+ options.default(
101
+ # Defaults for boolean options
102
+ pod_repo_update: true,
103
+ validate: true,
104
+ force: false,
105
+ add_sdk: true,
106
+ patch_source: true,
107
+ commit: false
108
+ )
109
+ Commands::SetupCommand.new(options).run!
96
110
  end
97
111
  end
98
112
 
@@ -120,12 +134,12 @@ validation.
120
134
  See https://github.com/BranchMetrics/branch_io_cli#validate-command for more information.
121
135
  EOF
122
136
 
137
+ c.option "-D", "--domains example.com,www.example.com", Array, "Comma-separated list of domains to validate (Branch domains or non-Branch domains)"
123
138
  c.option "--xcodeproj MyProject.xcodeproj", String, "Path to an Xcode project to update"
124
139
  c.option "--target MyAppTarget", String, "Name of a target to modify in the Xcode project"
125
- c.option "--domains example.com,www.example.com", Array, "Comma-separated list of domains to validate (Branch domains or non-Branch domains)"
126
140
 
127
141
  c.action do |args, options|
128
- valid = Command.validate options
142
+ valid = Commands::ValidateCommand.new(options).run!
129
143
  exit_code = valid ? 0 : 1
130
144
  exit exit_code
131
145
  end
@@ -0,0 +1,3 @@
1
+ require "branch_io_cli/commands/command"
2
+ require "branch_io_cli/commands/setup_command"
3
+ require "branch_io_cli/commands/validate_command"
@@ -0,0 +1,23 @@
1
+ module BranchIOCLI
2
+ module Commands
3
+ class Command
4
+ attr_reader :options
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def run!
11
+ # implemented by subclasses
12
+ end
13
+
14
+ def helper
15
+ Helper::BranchHelper
16
+ end
17
+
18
+ def config_helper
19
+ Helper::ConfigurationHelper
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,67 @@
1
+ module BranchIOCLI
2
+ module Commands
3
+ class SetupCommand < Command
4
+ def initialize(options)
5
+ super
6
+ config_helper.validate_setup_options options
7
+ @keys = config_helper.keys
8
+ @domains = config_helper.all_domains
9
+ end
10
+
11
+ # rubocop: disable Metrics/PerceivedComplexity
12
+ def run!
13
+ xcodeproj = config_helper.xcodeproj
14
+
15
+ case config_helper.sdk_integration_mode
16
+ when :cocoapods
17
+ if File.exist? config_helper.podfile_path
18
+ helper.update_podfile options
19
+ else
20
+ helper.add_cocoapods options
21
+ end
22
+ when :carthage
23
+ if File.exist? config_helper.cartfile_path
24
+ helper.update_cartfile options, xcodeproj
25
+ else
26
+ helper.add_carthage options
27
+ end
28
+ when :direct
29
+ helper.add_direct options
30
+ end
31
+
32
+ target_name = options.target # may be nil
33
+ is_app_target = config_helper.target.extension_target_type?
34
+
35
+ if is_app_target && options.validate &&
36
+ !helper.validate_team_and_bundle_ids_from_aasa_files(xcodeproj, target_name, @domains)
37
+ say "Universal Link configuration failed validation."
38
+ helper.errors.each { |error| say " #{error}" }
39
+ return unless options.force
40
+ elsif is_app_target && options.validate
41
+ say "Universal Link configuration passed validation. ✅"
42
+ end
43
+
44
+ # the following calls can all raise IOError
45
+ helper.add_keys_to_info_plist xcodeproj, target_name, @keys
46
+ helper.add_branch_universal_link_domains_to_info_plist xcodeproj, target_name, @domains if is_app_target
47
+ helper.ensure_uri_scheme_in_info_plist if is_app_target # does nothing if already present
48
+
49
+ new_path = helper.add_universal_links_to_project xcodeproj, target_name, @domains, false if is_app_target
50
+ `git add #{new_path}` if options.commit && new_path
51
+
52
+ helper.add_system_frameworks xcodeproj, target_name, options.frameworks unless options.frameworks.nil? || options.frameworks.empty?
53
+
54
+ xcodeproj.save
55
+
56
+ helper.patch_source xcodeproj if options.patch_source
57
+
58
+ return unless options.commit
59
+
60
+ changes = helper.changes.to_a.map { |c| Pathname.new(File.expand_path(c)).relative_path_from(Pathname.pwd).to_s }
61
+
62
+ `git commit #{changes.join(" ")} -m '[branch_io_cli] Branch SDK integration'`
63
+ end
64
+ # rubocop: enable Metrics/PerceivedComplexity
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,46 @@
1
+ module BranchIOCLI
2
+ module Commands
3
+ module ValidateCommand
4
+ def initialize(options)
5
+ super
6
+ config_helper.validate_validation_options options
7
+ end
8
+
9
+ def run!
10
+ # raises
11
+ xcodeproj = config_helper.xcodeproj
12
+
13
+ valid = true
14
+
15
+ unless options.domains.nil? || options.domains.empty?
16
+ domains_valid = helper.validate_project_domains(
17
+ options.domains,
18
+ xcodeproj,
19
+ options.target
20
+ )
21
+
22
+ if domains_valid
23
+ say "Project domains match :domains parameter: ✅"
24
+ else
25
+ say "Project domains do not match specified :domains"
26
+ helper.errors.each { |error| say " #{error}" }
27
+ end
28
+
29
+ valid &&= domains_valid
30
+ end
31
+
32
+ configuration_valid = helper.validate_team_and_bundle_ids_from_aasa_files xcodeproj, options.target
33
+ unless configuration_valid
34
+ say "Universal Link configuration failed validation."
35
+ helper.errors.each { |error| say " #{error}" }
36
+ end
37
+
38
+ valid &&= configuration_valid
39
+
40
+ say "Universal Link configuration passed validation. ✅" if valid
41
+
42
+ valid
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,6 @@
1
1
  require "branch_io_cli/helper/android_helper"
2
2
  require "branch_io_cli/helper/ios_helper"
3
+ require "net/http"
3
4
  require "pattern_patch"
4
5
  require "set"
5
6
 
@@ -33,6 +34,64 @@ module BranchIOCLI
33
34
  file.write modified
34
35
  end
35
36
  end
37
+
38
+ def fetch(url)
39
+ response = Net::HTTP.get_response URI(url)
40
+
41
+ case response
42
+ when Net::HTTPSuccess
43
+ response.body
44
+ when Net::HTTPRedirection
45
+ fetch response['location']
46
+ else
47
+ raise "Error fetching #{url}: #{response.code} #{response.message}"
48
+ end
49
+ end
50
+
51
+ def download(url, dest)
52
+ uri = URI(url)
53
+
54
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
55
+ request = Net::HTTP::Get.new uri
56
+
57
+ http.request request do |response|
58
+ case response
59
+ when Net::HTTPSuccess
60
+ bytes_downloaded = 0
61
+ dots_reported = 0
62
+ # report a dot every 100 kB
63
+ per_dot = 102_400
64
+
65
+ File.open dest, 'w' do |io|
66
+ response.read_body do |chunk|
67
+ io.write chunk
68
+
69
+ # print progress
70
+ bytes_downloaded += chunk.length
71
+ while (bytes_downloaded - per_dot * dots_reported) >= per_dot
72
+ print "."
73
+ dots_reported += 1
74
+ end
75
+ STDOUT.flush
76
+ end
77
+ end
78
+ say "\n"
79
+ when Net::HTTPRedirection
80
+ download response['location'], dest
81
+ else
82
+ raise "Error downloading #{url}: #{response.code} #{response.message}"
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def ensure_directory(path)
89
+ return if path == "/" || path == "."
90
+ parent = File.dirname path
91
+ ensure_directory parent
92
+ return if Dir.exist? path
93
+ Dir.mkdir path
94
+ end
36
95
  end
37
96
  end
38
97
  end
@@ -1,42 +1,73 @@
1
- require "json"
2
- require "net/http"
3
1
  require "pathname"
4
- require "tmpdir"
5
2
  require "xcodeproj"
6
- require "zip"
7
3
 
8
4
  module BranchIOCLI
9
5
  module Helper
10
- # rubocop: disable Metrics/ClassLength
6
+ # Processes CLI options.
7
+ # Validates options.
8
+ # Prompts for input in a number of cases.
11
9
  class ConfigurationHelper
12
- class << self
13
- APP_LINK_REGEXP = /\.app\.link$|\.test-app\.link$/
10
+ APP_LINK_REGEXP = /\.app\.link$|\.test-app\.link$/
11
+ SDK_OPTIONS =
12
+ {
13
+ "Set this project up to use CocoaPods and add the Branch SDK." => :cocoapods,
14
+ "Set this project up to use Carthage and add the Branch SDK." => :carthage,
15
+ "Add Branch.framework directly to the project's dependencies." => :direct,
16
+ "Skip adding the framework to the project." => :skip
17
+ }
14
18
 
15
- attr_accessor :xcodeproj_path
16
- attr_accessor :xcodeproj
17
- attr_accessor :keys
18
- attr_accessor :all_domains
19
- attr_accessor :podfile_path
20
- attr_accessor :cartfile_path
21
- attr_accessor :target
22
- attr_accessor :uri_scheme
19
+ class << self
20
+ attr_reader :xcodeproj_path
21
+ attr_reader :xcodeproj
22
+ attr_reader :keys
23
+ attr_reader :all_domains
24
+ attr_reader :podfile_path
25
+ attr_reader :cartfile_path
26
+ attr_reader :target
27
+ attr_reader :uri_scheme
28
+ attr_reader :pod_repo_update
29
+ attr_reader :validate
30
+ attr_reader :add_sdk
31
+ attr_reader :force
32
+ attr_reader :patch_source
33
+ attr_reader :commit
34
+ attr_reader :sdk_integration_mode
23
35
 
24
36
  def validate_setup_options(options)
25
37
  print_identification "setup"
26
38
 
27
- say "--force is ignored when --no_validate is used." if options.no_validate && options.force
39
+ @pod_repo_update = options.pod_repo_update
40
+ @validate = options.validate
41
+ @patch_source = options.patch_source
42
+ @add_sdk = options.add_sdk
43
+ @force = options.force
44
+ @commit = options.commit
45
+
46
+ say "--force is ignored when --no-validate is used." if !options.validate && options.force
47
+ if options.cartfile && options.podfile
48
+ say "--cartfile and --podfile are mutually exclusive. Please specify the file to patch."
49
+ exit 1
50
+ end
28
51
 
29
52
  validate_xcodeproj_path options
30
53
  validate_target options
31
54
  validate_keys_from_setup_options options
32
55
  validate_all_domains options, !@target.extension_target_type?
33
56
  validate_uri_scheme options
34
- validate_buildfile_path options, "Podfile"
35
- validate_buildfile_path options, "Cartfile"
36
57
 
37
- print_setup_configuration
58
+ # If neither --podfile nor --cartfile is present, arbitrarily look for a Podfile
59
+ # first.
60
+
61
+ # If --cartfile is present, don't look for a Podfile. Just validate that
62
+ # Cartfile.
63
+ validate_buildfile_path options, "Podfile" if options.cartfile.nil?
64
+
65
+ # If --podfile is present or a Podfile was found, don't look for a Cartfile.
66
+ validate_buildfile_path options, "Cartfile" if @podfile.nil?
38
67
 
39
68
  validate_sdk_addition options
69
+
70
+ print_setup_configuration
40
71
  end
41
72
 
42
73
  def validate_validation_options(options)
@@ -68,6 +99,13 @@ EOF
68
99
  <%= color('URI scheme:', BOLD) %> #{@uri_scheme || '(none)'}
69
100
  <%= color('Podfile:', BOLD) %> #{@podfile_path || '(none)'}
70
101
  <%= color('Cartfile:', BOLD) %> #{@cartfile_path || '(none)'}
102
+ <%= color('Pod repo update:', BOLD) %> #{@pod_repo_update.inspect}
103
+ <%= color('Validate:', BOLD) %> #{@validate.inspect}
104
+ <%= color('Force:', BOLD) %> #{@force.inspect}
105
+ <%= color('Add SDK:', BOLD) %> #{@add_sdk.inspect}
106
+ <%= color('Patch source:', BOLD) %> #{@patch_source.inspect}
107
+ <%= color('Commit:', BOLD) %> #{@commit.inspect}
108
+ <%= color('SDK integration mode:', BOLD) %> #{@sdk_integration_mode || '(none)'}
71
109
 
72
110
  EOF
73
111
  end
@@ -244,10 +282,10 @@ EOF
244
282
  end
245
283
 
246
284
  def validate_buildfile_path(options, filename)
247
- # Disable Podfile/Cartfile update if --no_add_sdk is present
248
- return if options.no_add_sdk
285
+ # Disable Podfile/Cartfile update if --no-add-sdk is present
286
+ return unless options.add_sdk && @sdk_integration_mode.nil?
249
287
 
250
- buildfile_path = filename == "Podfile" ? options.podfile : options.cartfile
288
+ buildfile_path = options.send filename.downcase
251
289
 
252
290
  # Was --podfile/--cartfile used?
253
291
  if buildfile_path
@@ -284,10 +322,12 @@ EOF
284
322
  else
285
323
  @cartfile_path = buildfile_path
286
324
  end
325
+
326
+ @sdk_integration_mode = filename == "Podfile" ? :cocoapods : :carthage
287
327
  end
288
328
 
289
329
  def validate_sdk_addition(options)
290
- return if options.no_add_sdk || @podfile_path || @cartfile_path
330
+ return if !options.add_sdk || @sdk_integration_mode
291
331
 
292
332
  # If no CocoaPods or Carthage, check to see if the framework is linked.
293
333
  target = BranchHelper.target_from_project @xcodeproj, options.target
@@ -303,222 +343,16 @@ EOF
303
343
  menu.prompt = "What would you like to do?"
304
344
  end
305
345
 
306
- option = SDK_OPTIONS[selected]
307
-
308
- case option
309
- when :skip
310
- return
311
- else
312
- send "add_#{option}", options
313
- end
314
- end
315
-
316
- def add_cocoapods(options)
317
- @podfile_path = File.expand_path "../Podfile", @xcodeproj_path
318
- target = BranchHelper.target_from_project @xcodeproj, options.target
319
-
320
- install_command = "pod install"
321
- install_command += " --repo-update" unless options.no_pod_repo_update
322
- Dir.chdir(File.dirname(@podfile_path)) do
323
- system "pod init"
324
- BranchHelper.apply_patch(
325
- files: @podfile_path,
326
- regexp: /^(\s*)# Pods for #{target.name}$/,
327
- mode: :append,
328
- text: "\n\\1pod \"Branch\"",
329
- global: false
330
- )
331
- system install_command
332
- end
333
-
334
- BranchHelper.add_change @podfile_path
335
- BranchHelper.add_change "#{@podfile_path}.lock"
336
-
337
- # For now, add Pods folder to SCM.
338
- pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
339
- workspace_path = Pathname.new(File.expand_path(@xcodeproj_path.sub(/.xcodeproj$/, ".xcworkspace"))).relative_path_from Pathname.pwd
340
- podfile_pathname = Pathname.new(@podfile_path).relative_path_from Pathname.pwd
341
- BranchHelper.add_change pods_folder_path
342
- BranchHelper.add_change workspace_path
343
- `git add #{podfile_pathname} #{podfile_pathname}.lock #{pods_folder_path} #{workspace_path}` if options.commit
344
- end
345
-
346
- def add_carthage(options)
347
- # TODO: Collapse this and Command::update_cartfile
348
-
349
- # 1. Generate Cartfile
350
- @cartfile_path = File.expand_path "../Cartfile", @xcodeproj_path
351
- File.open(@cartfile_path, "w") do |file|
352
- file.write <<EOF
353
- github "BranchMetrics/ios-branch-deep-linking"
354
- EOF
355
- end
356
-
357
- # 2. carthage update
358
- Dir.chdir(File.dirname(@cartfile_path)) do
359
- system "carthage update --platform ios"
360
- end
361
-
362
- # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
363
- BranchHelper.add_change cartfile_path
364
- BranchHelper.add_change "#{cartfile_path}.resolved"
365
-
366
- # 4. Add to target dependencies
367
- frameworks_group = @xcodeproj.frameworks_group
368
- branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
369
- target = BranchHelper.target_from_project @xcodeproj, options.target
370
- target.frameworks_build_phase.add_file_reference branch_framework
371
-
372
- # 5. Create a copy-frameworks build phase
373
- carthage_build_phase = target.new_shell_script_build_phase "carthage copy-frameworks"
374
- carthage_build_phase.shell_script = "/usr/local/bin/carthage copy-frameworks"
375
-
376
- carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
377
- carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
378
-
379
- @xcodeproj.save
380
-
381
- # For now, add Carthage folder to SCM
382
-
383
- # 6. Add the Carthage folder to the commit (in case :commit param specified)
384
- carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from(Pathname.pwd)
385
- cartfile_pathname = Pathname.new(@cartfile_path).relative_path_from Pathname.pwd
386
- BranchHelper.add_change carthage_folder_path
387
- `git add #{cartfile_pathname} #{cartfile_pathname}.resolved #{carthage_folder_path}` if options.commit
388
- end
389
-
390
- def add_direct(options)
391
- # Put the framework in the path for any existing Frameworks group in the project.
392
- frameworks_group = @xcodeproj.frameworks_group
393
- framework_path = File.join frameworks_group.real_path, "Branch.framework"
394
- raise "#{framework_path} exists." if File.exist? framework_path
395
-
396
- say "Finding current framework release"
397
-
398
- # Find the latest release from GitHub.
399
- releases = JSON.parse fetch "https://api.github.com/repos/BranchMetrics/ios-branch-deep-linking/releases"
400
- current_release = releases.first
401
- # Get the download URL for the framework.
402
- framework_asset = current_release["assets"][0]
403
- framework_url = framework_asset["browser_download_url"]
404
-
405
- say "Downloading Branch.framework v. #{current_release['tag_name']} (#{framework_asset['size']} bytes zipped)"
406
-
407
- Dir.mktmpdir do |download_folder|
408
- zip_path = File.join download_folder, "Branch.framework.zip"
409
-
410
- File.unlink zip_path if File.exist? zip_path
411
-
412
- # Download the framework zip
413
- download framework_url, zip_path
414
-
415
- say "Unzipping Branch.framework"
416
-
417
- # Unzip
418
- Zip::File.open zip_path do |zip_file|
419
- # Start with just the framework and add dSYM, etc., later
420
- zip_file.glob "Carthage/Build/iOS/Branch.framework/**/*" do |entry|
421
- filename = entry.name.sub %r{^Carthage/Build/iOS}, frameworks_group.real_path.to_s
422
- ensure_directory File.dirname filename
423
- entry.extract filename
424
- end
425
- end
426
- end
427
-
428
- # Now the current framework is in framework_path
429
-
430
- say "Adding to #{@xcodeproj_path}"
431
-
432
- # Add as a dependency in the Frameworks group
433
- framework = frameworks_group.new_file "Branch.framework" # relative to frameworks_group.real_path
434
- @target.frameworks_build_phase.add_file_reference framework, true
435
-
436
- # Make sure this is in the FRAMEWORK_SEARCH_PATHS if we just added it.
437
- if frameworks_group.files.count == 1
438
- @target.build_configurations.each do |config|
439
- paths = config.build_settings["FRAMEWORK_SEARCH_PATHS"] || []
440
- next if paths.any? { |p| p == '$(SRCROOT)' || p == '$(SRCROOT)/**' }
441
- paths << '$(SRCROOT)'
442
- config.build_settings["FRAMEWORK_SEARCH_PATHS"] = paths
443
- end
444
- end
445
- # If it already existed, it's almost certainly already in FRAMEWORK_SEARCH_PATHS.
446
-
447
- @xcodeproj.save
346
+ @sdk_integration_mode = SDK_OPTIONS[selected]
448
347
 
449
- BranchHelper.add_change framework_path
450
- `git add #{framework_path}` if options.commit
451
-
452
- say "Done. ✅"
453
- end
454
-
455
- def fetch(url)
456
- response = Net::HTTP.get_response URI(url)
457
-
458
- case response
459
- when Net::HTTPSuccess
460
- response.body
461
- when Net::HTTPRedirection
462
- fetch response['location']
463
- else
464
- raise "Error fetching #{url}: #{response.code} #{response.message}"
348
+ case @sdk_integration_mode
349
+ when :cocoapods
350
+ @podfile_path = File.expand_path "../Podfile", @xcodeproj_path
351
+ when :carthage
352
+ @cartfile_path = File.expand_path "../Cartfile", @xcodeproj_path
465
353
  end
466
354
  end
467
-
468
- def download(url, dest)
469
- uri = URI(url)
470
-
471
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
472
- request = Net::HTTP::Get.new uri
473
-
474
- http.request request do |response|
475
- case response
476
- when Net::HTTPSuccess
477
- bytes_downloaded = 0
478
- dots_reported = 0
479
- # report a dot every 100 kB
480
- per_dot = 102_400
481
-
482
- File.open dest, 'w' do |io|
483
- response.read_body do |chunk|
484
- io.write chunk
485
-
486
- # print progress
487
- bytes_downloaded += chunk.length
488
- while (bytes_downloaded - per_dot * dots_reported) >= per_dot
489
- print "."
490
- dots_reported += 1
491
- end
492
- STDOUT.flush
493
- end
494
- end
495
- say "\n"
496
- when Net::HTTPRedirection
497
- download response['location'], dest
498
- else
499
- raise "Error downloading #{url}: #{response.code} #{response.message}"
500
- end
501
- end
502
- end
503
- end
504
-
505
- def ensure_directory(path)
506
- return if path == "/" || path == "."
507
- parent = File.dirname path
508
- ensure_directory parent
509
- return if Dir.exist? path
510
- Dir.mkdir path
511
- end
512
-
513
- SDK_OPTIONS =
514
- {
515
- "Set this project up to use CocoaPods and add the Branch SDK." => :cocoapods,
516
- "Set this project up to use Carthage and add the Branch SDK." => :carthage,
517
- "Add Branch.framework directly to the project's dependencies." => :direct,
518
- "Skip adding the framework to the project." => :skip
519
- }
520
355
  end
521
356
  end
522
357
  end
523
- # rubocop enable: Metrics/ClassLength
524
358
  end
@@ -1,7 +1,10 @@
1
1
  require "json"
2
2
  require "net/http"
3
3
  require "openssl"
4
+ require "pathname"
4
5
  require "plist"
6
+ require "tmpdir"
7
+ require "zip"
5
8
 
6
9
  module BranchIOCLI
7
10
  module Helper
@@ -679,6 +682,227 @@ EOF
679
682
 
680
683
  true
681
684
  end
685
+
686
+ def add_cocoapods(options)
687
+ podfile_path = ConfigurationHelper.podfile_path
688
+
689
+ install_command = "pod install"
690
+ install_command += " --repo-update" if options.pod_repo_update
691
+ Dir.chdir(File.dirname(podfile_path)) do
692
+ system "pod init"
693
+ apply_patch(
694
+ files: podfile_path,
695
+ regexp: /^(\s*)# Pods for #{ConfigurationHelper.target.name}$/,
696
+ mode: :append,
697
+ text: "\n\\1pod \"Branch\"",
698
+ global: false
699
+ )
700
+ system install_command
701
+ end
702
+
703
+ add_change podfile_path
704
+ add_change "#{podfile_path}.lock"
705
+
706
+ # For now, add Pods folder to SCM.
707
+ pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
708
+ workspace_path = Pathname.new(File.expand_path(ConfigurationHelper.xcodeproj_path.sub(/.xcodeproj$/, ".xcworkspace"))).relative_path_from Pathname.pwd
709
+ podfile_pathname = Pathname.new(podfile_path).relative_path_from Pathname.pwd
710
+ add_change pods_folder_path
711
+ add_change workspace_path
712
+ `git add #{podfile_pathname} #{podfile_pathname}.lock #{pods_folder_path} #{workspace_path}` if options.commit
713
+ end
714
+
715
+ def add_carthage(options)
716
+ # TODO: Collapse this and Command::update_cartfile
717
+
718
+ # 1. Generate Cartfile
719
+ cartfile_path = ConfigurationHelper.cartfile_path
720
+ File.open(cartfile_path, "w") do |file|
721
+ file.write <<EOF
722
+ github "BranchMetrics/ios-branch-deep-linking"
723
+ EOF
724
+ end
725
+
726
+ # 2. carthage update
727
+ Dir.chdir(File.dirname(cartfile_path)) do
728
+ system "carthage update --platform ios"
729
+ end
730
+
731
+ # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
732
+ add_change cartfile_path
733
+ add_change "#{cartfile_path}.resolved"
734
+ add_change ConfigurationHelper.xcodeproj_path
735
+
736
+ # 4. Add to target dependencies
737
+ frameworks_group = ConfigurationHelper.xcodeproj.frameworks_group
738
+ branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
739
+ target = ConfigurationHelper.target
740
+ target.frameworks_build_phase.add_file_reference branch_framework
741
+
742
+ # 5. Create a copy-frameworks build phase
743
+ carthage_build_phase = target.new_shell_script_build_phase "carthage copy-frameworks"
744
+ carthage_build_phase.shell_script = "/usr/local/bin/carthage copy-frameworks"
745
+
746
+ carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
747
+ carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
748
+
749
+ ConfigurationHelper.xcodeproj.save
750
+
751
+ # For now, add Carthage folder to SCM
752
+
753
+ # 6. Add the Carthage folder to the commit (in case :commit param specified)
754
+ carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from(Pathname.pwd)
755
+ cartfile_pathname = Pathname.new(cartfile_path).relative_path_from Pathname.pwd
756
+ add_change carthage_folder_path
757
+ `git add #{cartfile_pathname} #{cartfile_pathname}.resolved #{carthage_folder_path}` if options.commit
758
+ end
759
+
760
+ def add_direct(options)
761
+ # Put the framework in the path for any existing Frameworks group in the project.
762
+ frameworks_group = ConfigurationHelper.xcodeproj.frameworks_group
763
+ framework_path = File.join frameworks_group.real_path, "Branch.framework"
764
+ raise "#{framework_path} exists." if File.exist? framework_path
765
+
766
+ say "Finding current framework release"
767
+
768
+ # Find the latest release from GitHub.
769
+ releases = JSON.parse fetch "https://api.github.com/repos/BranchMetrics/ios-branch-deep-linking/releases"
770
+ current_release = releases.first
771
+ # Get the download URL for the framework.
772
+ framework_asset = current_release["assets"][0]
773
+ framework_url = framework_asset["browser_download_url"]
774
+
775
+ say "Downloading Branch.framework v. #{current_release['tag_name']} (#{framework_asset['size']} bytes zipped)"
776
+
777
+ Dir.mktmpdir do |download_folder|
778
+ zip_path = File.join download_folder, "Branch.framework.zip"
779
+
780
+ File.unlink zip_path if File.exist? zip_path
781
+
782
+ # Download the framework zip
783
+ download framework_url, zip_path
784
+
785
+ say "Unzipping Branch.framework"
786
+
787
+ # Unzip
788
+ Zip::File.open zip_path do |zip_file|
789
+ # Start with just the framework and add dSYM, etc., later
790
+ zip_file.glob "Carthage/Build/iOS/Branch.framework/**/*" do |entry|
791
+ filename = entry.name.sub %r{^Carthage/Build/iOS}, frameworks_group.real_path.to_s
792
+ ensure_directory File.dirname filename
793
+ entry.extract filename
794
+ end
795
+ end
796
+ end
797
+
798
+ # Now the current framework is in framework_path
799
+
800
+ say "Adding to #{@xcodeproj_path}"
801
+
802
+ # Add as a dependency in the Frameworks group
803
+ framework = frameworks_group.new_file "Branch.framework" # relative to frameworks_group.real_path
804
+ ConfigurationHelper.target.frameworks_build_phase.add_file_reference framework, true
805
+
806
+ # Make sure this is in the FRAMEWORK_SEARCH_PATHS if we just added it.
807
+ if frameworks_group.files.count == 1
808
+ ConfigurationHelper.target.build_configurations.each do |config|
809
+ paths = config.build_settings["FRAMEWORK_SEARCH_PATHS"] || []
810
+ next if paths.any? { |p| p == '$(SRCROOT)' || p == '$(SRCROOT)/**' }
811
+ paths << '$(SRCROOT)'
812
+ config.build_settings["FRAMEWORK_SEARCH_PATHS"] = paths
813
+ end
814
+ end
815
+ # If it already existed, it's almost certainly already in FRAMEWORK_SEARCH_PATHS.
816
+
817
+ ConfigurationHelper.xcodeproj.save
818
+
819
+ add_change ConfigurationHelper.xcodeproj_path
820
+ add_change framework_path
821
+ `git add #{framework_path}` if options.commit
822
+
823
+ say "Done. ✅"
824
+ end
825
+
826
+ def update_podfile(options)
827
+ podfile_path = ConfigurationHelper.podfile_path
828
+ return false if podfile_path.nil?
829
+
830
+ # 1. Patch Podfile. Return if no change (Branch pod already present).
831
+ return false unless patch_podfile podfile_path
832
+
833
+ # 2. pod install
834
+ # command = "PATH='#{ENV['PATH']}' pod install"
835
+ command = 'pod install'
836
+ command += ' --repo-update' if options.pod_repo_update
837
+
838
+ Dir.chdir(File.dirname(podfile_path)) do
839
+ system command
840
+ end
841
+
842
+ # 3. Add Podfile and Podfile.lock to commit (in case :commit param specified)
843
+ add_change podfile_path
844
+ add_change "#{podfile_path}.lock"
845
+
846
+ # 4. Check if Pods folder is under SCM
847
+ pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
848
+ `git ls-files #{pods_folder_path} --error-unmatch > /dev/null 2>&1`
849
+ return true unless $?.exitstatus == 0
850
+
851
+ # 5. If so, add the Pods folder to the commit (in case :commit param specified)
852
+ add_change pods_folder_path
853
+ `git add #{pods_folder_path}` if options.commit
854
+
855
+ true
856
+ end
857
+
858
+ def update_cartfile(options, project)
859
+ cartfile_path = ConfigurationHelper.cartfile_path
860
+ return false if cartfile_path.nil?
861
+
862
+ # 1. Patch Cartfile. Return if no change (Branch already present).
863
+ return false unless patch_cartfile cartfile_path
864
+
865
+ # 2. carthage update
866
+ Dir.chdir(File.dirname(cartfile_path)) do
867
+ system "carthage update --platform ios"
868
+ end
869
+
870
+ # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
871
+ add_change cartfile_path
872
+ add_change "#{cartfile_path}.resolved"
873
+ add_change ConfigurationHelper.xcodeproj_path
874
+
875
+ # 4. Add to target dependencies
876
+ frameworks_group = project.frameworks_group
877
+ branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
878
+ target = ConfigurationHelper.target
879
+ target.frameworks_build_phase.add_file_reference branch_framework
880
+
881
+ # 5. Add to copy-frameworks build phase
882
+ carthage_build_phase = target.build_phases.find do |phase|
883
+ phase.respond_to?(:shell_script) && phase.shell_script =~ /carthage\s+copy-frameworks/
884
+ end
885
+
886
+ if carthage_build_phase
887
+ carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
888
+ carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
889
+ end
890
+
891
+ # 6. Check if Carthage folder is under SCM
892
+ carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from Pathname.pwd
893
+ `git ls-files #{carthage_folder_path} --error-unmatch > /dev/null 2>&1`
894
+ return true unless $?.exitstatus == 0
895
+
896
+ # 7. If so, add the Carthage folder to the commit (in case :commit param specified)
897
+ add_change carthage_folder_path
898
+ `git add #{carthage_folder_path}` if options.commit
899
+
900
+ true
901
+ end
902
+
903
+ def patch_source(xcodeproj)
904
+ patch_app_delegate_swift(xcodeproj) || patch_app_delegate_objc(xcodeproj)
905
+ end
682
906
  end
683
907
  end
684
908
  end
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
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.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branch
@@ -222,7 +222,10 @@ files:
222
222
  - bin/branch_io
223
223
  - lib/branch_io_cli.rb
224
224
  - lib/branch_io_cli/cli.rb
225
- - lib/branch_io_cli/command.rb
225
+ - lib/branch_io_cli/commands.rb
226
+ - lib/branch_io_cli/commands/command.rb
227
+ - lib/branch_io_cli/commands/setup_command.rb
228
+ - lib/branch_io_cli/commands/validate_command.rb
226
229
  - lib/branch_io_cli/helper.rb
227
230
  - lib/branch_io_cli/helper/android_helper.rb
228
231
  - lib/branch_io_cli/helper/branch_helper.rb
@@ -1,177 +0,0 @@
1
- require "pathname"
2
- require "xcodeproj"
3
-
4
- module BranchIOCLI
5
- class Command
6
- class << self
7
- def setup(options)
8
- config_helper.validate_setup_options options
9
-
10
- @keys = config_helper.keys
11
- @domains = config_helper.all_domains
12
- @xcodeproj_path = config_helper.xcodeproj_path
13
- xcodeproj = config_helper.xcodeproj
14
-
15
- update_podfile(options) || update_cartfile(options, xcodeproj)
16
-
17
- target_name = options.target # may be nil
18
- is_app_target = !Helper::ConfigurationHelper.target.extension_target_type?
19
-
20
- if is_app_target && !options.no_validate &&
21
- !helper.validate_team_and_bundle_ids_from_aasa_files(xcodeproj, target_name, @domains)
22
- say "Universal Link configuration failed validation."
23
- helper.errors.each { |error| say " #{error}" }
24
- return unless options.force
25
- elsif is_app_target && !options.no_validate
26
- say "Universal Link configuration passed validation. ✅"
27
- end
28
-
29
- # the following calls can all raise IOError
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
- helper.ensure_uri_scheme_in_info_plist if is_app_target # does nothing if already present
33
-
34
- new_path = helper.add_universal_links_to_project xcodeproj, target_name, @domains, false if is_app_target
35
- `git add #{new_path}` if options.commit && new_path
36
-
37
- helper.add_system_frameworks xcodeproj, target_name, options.frameworks unless options.frameworks.nil? || options.frameworks.empty?
38
-
39
- xcodeproj.save
40
-
41
- patch_source xcodeproj unless options.no_patch_source
42
-
43
- return unless options.commit
44
-
45
- changes = helper.changes.to_a.map { |c| Pathname.new(File.expand_path(c)).relative_path_from(Pathname.pwd).to_s }
46
-
47
- `git commit #{changes.join(" ")} -m '[branch_io_cli] Branch SDK integration'`
48
- end
49
-
50
- def validate(options)
51
- config_helper.validate_validation_options options
52
-
53
- # raises
54
- xcodeproj = config_helper.xcodeproj
55
-
56
- valid = true
57
-
58
- unless options.domains.nil? || options.domains.empty?
59
- domains_valid = helper.validate_project_domains(
60
- options.domains,
61
- xcodeproj,
62
- options.target
63
- )
64
-
65
- if domains_valid
66
- say "Project domains match :domains parameter: ✅"
67
- else
68
- say "Project domains do not match specified :domains"
69
- helper.errors.each { |error| say " #{error}" }
70
- end
71
-
72
- valid &&= domains_valid
73
- end
74
-
75
- configuration_valid = helper.validate_team_and_bundle_ids_from_aasa_files xcodeproj, options.target
76
- unless configuration_valid
77
- say "Universal Link configuration failed validation."
78
- helper.errors.each { |error| say " #{error}" }
79
- end
80
-
81
- valid &&= configuration_valid
82
-
83
- say "Universal Link configuration passed validation. ✅" if valid
84
-
85
- valid
86
- end
87
-
88
- def helper
89
- Helper::BranchHelper
90
- end
91
-
92
- def config_helper
93
- Helper::ConfigurationHelper
94
- end
95
-
96
- def update_podfile(options)
97
- podfile_path = config_helper.podfile_path
98
- return false if podfile_path.nil?
99
-
100
- # 1. Patch Podfile. Return if no change (Branch pod already present).
101
- return false unless helper.patch_podfile podfile_path
102
-
103
- # 2. pod install
104
- # command = "PATH='#{ENV['PATH']}' pod install"
105
- command = 'pod install'
106
- command += ' --repo-update' unless options.no_pod_repo_update
107
-
108
- Dir.chdir(File.dirname(podfile_path)) do
109
- system command
110
- end
111
-
112
- # 3. Add Podfile and Podfile.lock to commit (in case :commit param specified)
113
- helper.add_change podfile_path
114
- helper.add_change "#{podfile_path}.lock"
115
-
116
- # 4. Check if Pods folder is under SCM
117
- pods_folder_path = Pathname.new(File.expand_path("../Pods", podfile_path)).relative_path_from Pathname.pwd
118
- `git ls-files #{pods_folder_path} --error-unmatch > /dev/null 2>&1`
119
- return true unless $?.exitstatus == 0
120
-
121
- # 5. If so, add the Pods folder to the commit (in case :commit param specified)
122
- helper.add_change pods_folder_path
123
- `git add #{pods_folder_path}` if options.commit
124
-
125
- true
126
- end
127
-
128
- def update_cartfile(options, project)
129
- cartfile_path = config_helper.cartfile_path
130
- return false if cartfile_path.nil?
131
-
132
- # 1. Patch Cartfile. Return if no change (Branch already present).
133
- return false unless helper.patch_cartfile cartfile_path
134
-
135
- # 2. carthage update
136
- Dir.chdir(File.dirname(cartfile_path)) do
137
- system "carthage update --platform ios"
138
- end
139
-
140
- # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
141
- helper.add_change cartfile_path
142
- helper.add_change "#{cartfile_path}.resolved"
143
-
144
- # 4. Add to target dependencies
145
- frameworks_group = project.frameworks_group
146
- branch_framework = frameworks_group.new_file "Carthage/Build/iOS/Branch.framework"
147
- target = Helper::ConfigurationHelper.target
148
- target.frameworks_build_phase.add_file_reference branch_framework
149
-
150
- # 5. Add to copy-frameworks build phase
151
- carthage_build_phase = target.build_phases.find do |phase|
152
- phase.respond_to?(:shell_script) && phase.shell_script =~ /carthage\s+copy-frameworks/
153
- end
154
-
155
- if carthage_build_phase
156
- carthage_build_phase.input_paths << "$(SRCROOT)/Carthage/Build/iOS/Branch.framework"
157
- carthage_build_phase.output_paths << "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Branch.framework"
158
- end
159
-
160
- # 6. Check if Carthage folder is under SCM
161
- carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from Pathname.pwd
162
- `git ls-files #{carthage_folder_path} --error-unmatch > /dev/null 2>&1`
163
- return true unless $?.exitstatus == 0
164
-
165
- # 7. If so, add the Carthage folder to the commit (in case :commit param specified)
166
- helper.add_change carthage_folder_path
167
- `git add #{carthage_folder_path}` if options.commit
168
-
169
- true
170
- end
171
-
172
- def patch_source(xcodeproj)
173
- helper.patch_app_delegate_swift(xcodeproj) || helper.patch_app_delegate_objc(xcodeproj)
174
- end
175
- end
176
- end
177
- end