branch_io_cli 0.3.2 → 0.4.0
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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/branch_io_cli/cli.rb +1 -0
- data/lib/branch_io_cli/command.rb +2 -0
- data/lib/branch_io_cli/helper/configuration_helper.rb +14 -0
- data/lib/branch_io_cli/helper/ios_helper.rb +149 -0
- data/lib/branch_io_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df2700adf827fe4870ef19d9125cedf54970f134
|
4
|
+
data.tar.gz: eb840f83b956602b89b0ec30770bc3fe251c7845
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 458c06211c2619714678d29a1986e060dd3437a25b16a50aa4b5500b6c7a9dd95d38e98b577924e6cc3ae6a169b1a82c5aa3c851b775218b9cc2fddb541d98c2
|
7
|
+
data.tar.gz: 6485a940ce0a27f302007d54dfe141fe8b20543b7866e57c8124e2fd892f52dd5bd29d005d01ea1345ebe3d36e81c465dab8cb32d7066b1cbc867988ba1a13b7
|
data/README.md
CHANGED
@@ -90,6 +90,7 @@ command, respectively, available in your path.
|
|
90
90
|
|--test_key key_test_yyyy|Branch test key|
|
91
91
|
|--app_link_subdomain myapp|Branch app.link subdomain, e.g. myapp for myapp.app.link|
|
92
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|
|
93
94
|
|--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
|
94
95
|
|--target MyAppTarget|Name of a target to modify in the Xcode project|
|
95
96
|
|--podfile /path/to/Podfile|Path to the Podfile for the project|
|
data/lib/branch_io_cli/cli.rb
CHANGED
@@ -76,6 +76,7 @@ EOF
|
|
76
76
|
c.option "--test_key key_test_yyyy", String, "Branch test key"
|
77
77
|
c.option "--app_link_subdomain myapp", String, "Branch app.link subdomain, e.g. myapp for myapp.app.link"
|
78
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"
|
79
80
|
|
80
81
|
c.option "--xcodeproj MyProject.xcodeproj", String, "Path to an Xcode project to update"
|
81
82
|
c.option "--target MyAppTarget", String, "Name of a target to modify in the Xcode project"
|
@@ -29,6 +29,8 @@ module BranchIOCLI
|
|
29
29
|
# the following calls can all raise IOError
|
30
30
|
helper.add_keys_to_info_plist xcodeproj, target_name, @keys
|
31
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
|
+
|
32
34
|
new_path = helper.add_universal_links_to_project xcodeproj, target_name, @domains, false if is_app_target
|
33
35
|
`git add #{new_path}` if options.commit && new_path
|
34
36
|
|
@@ -18,6 +18,7 @@ module BranchIOCLI
|
|
18
18
|
attr_accessor :podfile_path
|
19
19
|
attr_accessor :cartfile_path
|
20
20
|
attr_accessor :target
|
21
|
+
attr_accessor :uri_scheme
|
21
22
|
|
22
23
|
def validate_setup_options(options)
|
23
24
|
print_identification "setup"
|
@@ -28,6 +29,7 @@ module BranchIOCLI
|
|
28
29
|
validate_target options
|
29
30
|
validate_keys_from_setup_options options
|
30
31
|
validate_all_domains options, !@target.extension_target_type?
|
32
|
+
validate_uri_scheme options
|
31
33
|
validate_buildfile_path options, "Podfile"
|
32
34
|
validate_buildfile_path options, "Cartfile"
|
33
35
|
|
@@ -63,6 +65,7 @@ EOF
|
|
63
65
|
<%= color('Live key:', BOLD) %> #{@keys[:live] || '(none)'}
|
64
66
|
<%= color('Test key:', BOLD) %> #{@keys[:test] || '(none)'}
|
65
67
|
<%= color('Domains:', BOLD) %> #{@all_domains}
|
68
|
+
<%= color('URI scheme:', BOLD) %> #{@uri_scheme || '(none)'}
|
66
69
|
<%= color('Podfile:', BOLD) %> #{@podfile_path || '(none)'}
|
67
70
|
<%= color('Cartfile:', BOLD) %> #{@cartfile_path || '(none)'}
|
68
71
|
|
@@ -119,6 +122,11 @@ EOF
|
|
119
122
|
end
|
120
123
|
end
|
121
124
|
|
125
|
+
def validate_uri_scheme(options)
|
126
|
+
# No validation at the moment. Just strips off any trailing ://
|
127
|
+
@uri_scheme = uri_scheme_without_suffix options.uri_scheme
|
128
|
+
end
|
129
|
+
|
122
130
|
# 1. Look for options.xcodeproj.
|
123
131
|
# 2. If not specified, look for projects under . (excluding anything in Pods or Carthage folder).
|
124
132
|
# 3. If none or more than one found, prompt the user.
|
@@ -229,6 +237,12 @@ EOF
|
|
229
237
|
custom_domains + app_link_subdomains
|
230
238
|
end
|
231
239
|
|
240
|
+
# Removes any trailing :// from the argument and returns a copy
|
241
|
+
def uri_scheme_without_suffix(scheme)
|
242
|
+
return nil if scheme.nil?
|
243
|
+
scheme.sub %r{://$}, ""
|
244
|
+
end
|
245
|
+
|
232
246
|
def validate_buildfile_path(options, filename)
|
233
247
|
# Disable Podfile/Cartfile update if --no_add_sdk is present
|
234
248
|
return if options.no_add_sdk
|
@@ -35,6 +35,43 @@ module BranchIOCLI
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def ensure_uri_scheme_in_info_plist
|
39
|
+
uri_scheme = ConfigurationHelper.uri_scheme
|
40
|
+
|
41
|
+
# No URI scheme specified. Do nothing.
|
42
|
+
return if uri_scheme.nil?
|
43
|
+
|
44
|
+
update_info_plist_setting ConfigurationHelper.xcodeproj,
|
45
|
+
ConfigurationHelper.target.name,
|
46
|
+
RELEASE_CONFIGURATION do |info_plist|
|
47
|
+
url_types = info_plist["CFBundleURLTypes"] || []
|
48
|
+
uri_schemes = url_types.inject([]) { |schemes, t| schemes + t["CFBundleURLSchemes"] }
|
49
|
+
|
50
|
+
if uri_schemes.empty?
|
51
|
+
say "No URI scheme currently defined in project."
|
52
|
+
else
|
53
|
+
say "Existing URI schemes found in project:"
|
54
|
+
uri_schemes.each do |scheme|
|
55
|
+
say " #{scheme}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Already present. Don't mess with the identifier.
|
60
|
+
return if uri_schemes.include? uri_scheme
|
61
|
+
|
62
|
+
# Not found. Add. Don't worry about the CFBundleURLName (reverse-DNS identifier)
|
63
|
+
# TODO: Should we prompt here to add or let them change the Dashboard? If there's already
|
64
|
+
# a URI scheme in the app, seems likely they'd want to use it. They may have just made
|
65
|
+
# a typo at the CLI or in the Dashboard.
|
66
|
+
url_types << {
|
67
|
+
"CFBundleURLSchemes" => [uri_scheme]
|
68
|
+
}
|
69
|
+
info_plist["CFBundleURLTypes"] = url_types
|
70
|
+
|
71
|
+
say "Added URI scheme #{uri_scheme} to project."
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
38
75
|
def update_info_plist_setting(project, target_name, configuration = RELEASE_CONFIGURATION, &b)
|
39
76
|
# raises
|
40
77
|
target = target_from_project project, target_name
|
@@ -413,6 +450,8 @@ EOF
|
|
413
450
|
)
|
414
451
|
end
|
415
452
|
|
453
|
+
patch_open_url_method_swift app_delegate_swift_path
|
454
|
+
|
416
455
|
add_change app_delegate_swift_path
|
417
456
|
true
|
418
457
|
end
|
@@ -490,10 +529,120 @@ EOF
|
|
490
529
|
)
|
491
530
|
end
|
492
531
|
|
532
|
+
patch_open_url_method_objc app_delegate_objc_path
|
533
|
+
|
493
534
|
add_change app_delegate_objc_path
|
494
535
|
true
|
495
536
|
end
|
496
537
|
|
538
|
+
def patch_open_url_method_swift(app_delegate_swift_path)
|
539
|
+
app_delegate_swift = File.open app_delegate_swift_path, &:read
|
540
|
+
if app_delegate_swift =~ /application.*open\s+url.*options/
|
541
|
+
# Has application:openURL:options:
|
542
|
+
open_url_text = <<-EOF
|
543
|
+
// TODO: Adjust your method as you see fit.
|
544
|
+
if Branch.getInstance().application(app, open: url, options: options) {
|
545
|
+
return true
|
546
|
+
}
|
547
|
+
|
548
|
+
EOF
|
549
|
+
|
550
|
+
apply_patch(
|
551
|
+
files: app_delegate_swift_path,
|
552
|
+
regexp: /application.*open\s+url.*options:.*?\{.*?\n/m,
|
553
|
+
text: open_url_text,
|
554
|
+
mode: :append
|
555
|
+
)
|
556
|
+
elsif app_delegate_swift =~ /application.*open\s+url.*sourceApplication/
|
557
|
+
# Has application:openURL:sourceApplication:annotation:
|
558
|
+
# TODO: This method is deprecated.
|
559
|
+
open_url_text = <<-EOF
|
560
|
+
// TODO: Adjust your method as you see fit.
|
561
|
+
if Branch.getInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation) {
|
562
|
+
return true
|
563
|
+
}
|
564
|
+
|
565
|
+
EOF
|
566
|
+
|
567
|
+
apply_patch(
|
568
|
+
files: app_delegate_swift_path,
|
569
|
+
regexp: /application.*open\s+url.*sourceApplication:.*?\{.*?\n/m,
|
570
|
+
text: open_url_text,
|
571
|
+
mode: :append
|
572
|
+
)
|
573
|
+
else
|
574
|
+
# Has neither
|
575
|
+
open_url_text = <<EOF
|
576
|
+
|
577
|
+
|
578
|
+
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
|
579
|
+
return Branch.getInstance().application(app, open: url, options: options)
|
580
|
+
}
|
581
|
+
EOF
|
582
|
+
|
583
|
+
apply_patch(
|
584
|
+
files: app_delegate_swift_path,
|
585
|
+
regexp: /\n\s*\}[^{}]*\Z/m,
|
586
|
+
text: open_url_text,
|
587
|
+
mode: :prepend
|
588
|
+
)
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
def patch_open_url_method_objc(app_delegate_objc_path)
|
593
|
+
app_delegate_objc = File.open app_delegate_objc_path, &:read
|
594
|
+
if app_delegate_objc =~ /application:.*openURL:.*options/
|
595
|
+
# Has application:openURL:options:
|
596
|
+
open_url_text = <<-EOF
|
597
|
+
// TODO: Adjust your method as you see fit.
|
598
|
+
if ([[Branch getInstance] application:app openURL:url options:options]) {
|
599
|
+
return YES;
|
600
|
+
}
|
601
|
+
|
602
|
+
EOF
|
603
|
+
|
604
|
+
apply_patch(
|
605
|
+
files: app_delegate_objc_path,
|
606
|
+
regexp: /application:.*openURL:.*options:.*?\{.*?\n/m,
|
607
|
+
text: open_url_text,
|
608
|
+
mode: :append
|
609
|
+
)
|
610
|
+
elsif app_delegate_objc =~ /application:.*openURL:.*sourceApplication/
|
611
|
+
# Has application:openURL:sourceApplication:annotation:
|
612
|
+
open_url_text = <<-EOF
|
613
|
+
// TODO: Adjust your method as you see fit.
|
614
|
+
if ([[Branch getInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]) {
|
615
|
+
return YES;
|
616
|
+
}
|
617
|
+
|
618
|
+
EOF
|
619
|
+
|
620
|
+
apply_patch(
|
621
|
+
files: app_delegate_objc_path,
|
622
|
+
regexp: /application:.*openURL:.*sourceApplication:.*?\{.*?\n/m,
|
623
|
+
text: open_url_text,
|
624
|
+
mode: :append
|
625
|
+
)
|
626
|
+
else
|
627
|
+
# Has neither
|
628
|
+
open_url_text = <<-EOF
|
629
|
+
|
630
|
+
|
631
|
+
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
|
632
|
+
{
|
633
|
+
return [[Branch getInstance] application:app openURL:url options:options];
|
634
|
+
}
|
635
|
+
EOF
|
636
|
+
|
637
|
+
apply_patch(
|
638
|
+
files: app_delegate_objc_path,
|
639
|
+
regexp: /\n\s*@end[^@]*\Z/m,
|
640
|
+
text: open_url_text,
|
641
|
+
mode: :prepend
|
642
|
+
)
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
497
646
|
def patch_podfile(podfile_path)
|
498
647
|
podfile = File.open(podfile_path, &:read)
|
499
648
|
|
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
|
+
version: 0.4.0
|
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-
|
12
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: commander
|