Class: BranchIOCLI::Command::SetupCommand
Instance Attribute Summary
Attributes inherited from Command
#config, #options
Instance Method Summary
collapse
#clear, #confirm, #sh
Methods inherited from Command
available_options, command_name, configuration_class, #env, examples, #helper, #patch_helper, return_value, #tool_helper
Constructor Details
Returns a new instance of SetupCommand.
8
9
10
11
12
|
# File 'lib/branch_io_cli/command/setup_command.rb', line 8
def initialize(options)
super
@keys = config.keys
@domains = config.all_domains
end
|
Instance Method Details
#add_sdk ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/branch_io_cli/command/setup_command.rb', line 65
def add_sdk
say "\nMaking sure Branch dependency is available.\n\n"
case config.sdk_integration_mode
when :cocoapods
if File.exist? config.podfile_path
tool_helper.update_podfile config
else
tool_helper.add_cocoapods config
end
when :carthage
if File.exist? config.cartfile_path
tool_helper.update_cartfile config, config.xcodeproj
else
tool_helper.add_carthage config
end
when :direct
tool_helper.add_direct config
end
end
|
#check_repo_status ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/branch_io_cli/command/setup_command.rb', line 112
def check_repo_status
return true if `which git`.empty? || !config.confirm
unless Dir.exist? ".git"
`git rev-parse --git-dir > /dev/null 2>&1`
return true unless $?.success?
end
`git diff-index --quiet HEAD --`
return true if $?.success?
sh "git status"
choice = choose do ||
. = "There are uncommitted changes in this repo. It's best to stash or commit them before continuing."
.readline = true
.choice "Stash"
.choice "Commit (You will be prompted for a commit message.)"
.choice "Quit"
.choice "Ignore and continue"
.prompt = "Please enter one of the options above: "
end
case choice
when /^Stash/
sh %w(git stash -q)
when /^Commit/
message = ask "Please enter a commit message: "
sh "git", "commit", "-aqm", message
when /^Quit/
say "Please stash or commit your changes before continuing."
return false
end
true
end
|
#commit_changes ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/branch_io_cli/command/setup_command.rb', line 103
def commit_changes
changes = helper.changes.to_a.map { |c| Pathname.new(File.expand_path(c)).relative_path_from(Pathname.pwd).to_s }
commit_message = config.commit if config.commit.kind_of?(String)
commit_message ||= "[branch_io_cli] Branch SDK integration #{config.relative_path(config.xcodeproj_path)} (#{config.target.name})"
sh "git", "commit", "-qm", commit_message, *changes
end
|
#run! ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/branch_io_cli/command/setup_command.rb', line 14
def run!
return 1 unless check_repo_status
if config.validate && config.target.symbol_type == :application
valid = validate_universal_links
return 1 unless valid || config.force
end
return false unless tool_helper.pod_install_if_required
update_project_settings
add_sdk
patch_helper.patch_source config.xcodeproj if config.patch_source
commit_changes if config.commit
say "\nDone ✅"
0
end
|
#update_project_settings ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/branch_io_cli/command/setup_command.rb', line 85
def update_project_settings
say "Updating project settings.\n\n"
helper.add_custom_build_setting if config.setting
helper.add_keys_to_info_plist @keys
config.target.add_system_frameworks config.frameworks unless config.frameworks.blank?
return unless config.target.symbol_type == :application
helper.add_branch_universal_link_domains_to_info_plist @domains
helper.ensure_uri_scheme_in_info_plist
config.xcodeproj.build_configurations.each do |c|
new_path = helper.add_universal_links_to_project @domains, false, c.name
sh "git", "add", new_path if config.commit && new_path
end
ensure
config.xcodeproj.save
end
|
#validate_universal_links ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/branch_io_cli/command/setup_command.rb', line 44
def validate_universal_links
say "Validating new Universal Link configuration before making any changes."
valid = true
config.xcodeproj.build_configurations.each do |c|
message = "Validating #{c.name} configuration"
say "\n<%= color('#{message}', [BOLD, CYAN]) %>\n\n"
configuration_valid = helper.validate_team_and_bundle_ids_from_aasa_files @domains, false, c.name
if configuration_valid
say "Universal Link configuration passed validation for #{c.name} configuration. ✅\n\n"
else
say "Universal Link configuration failed validation for #{c.name} configuration.\n\n"
helper.errors.each { |error| say " #{error}" }
end
valid &&= configuration_valid
end
valid
end
|