-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathpost-link-ios.rb
More file actions
executable file
·70 lines (57 loc) · 2.07 KB
/
post-link-ios.rb
File metadata and controls
executable file
·70 lines (57 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
require 'xcodeproj'
require 'tempfile'
require 'fileutils'
Dir.chdir('ios')
@podfile_path = Pathname.pwd + 'Podfile'
@pod_dep_arr = ['GooglePlaces', 'GoogleMaps', 'GooglePlacePicker']
@pod_dep = @pod_dep_arr.map{|dep| " pod '#{dep}'\n"}.join("")
@project_paths= Pathname.pwd.children.select { |pn| pn.extname == '.xcodeproj' }
raise 'No Xcode project found' unless @project_paths.length > 0
raise 'Multiple Xcode projects found' unless @project_paths.length == 1
project_path = @project_paths.first
project = Xcodeproj::Project.open(project_path)
main_target = project.targets.first
puts "Checking Podfile in iOS project #{@podfile_path}"
if File.exist? @podfile_path
puts 'Found an existing Podfile'
puts "Adding the following pod to Podfile\n#{@pod_dep}"
temp_file = Tempfile.new('Podfile_temp')
File.readlines(@podfile_path).each do |line|
if line =~ /pod\s'GooglePlaces'/
@pod_dep_arr.delete('GooglePlaces')
puts 'GooglePlaces pod is already added'
elsif line =~ /pod\s'GoogleMaps'/
@pod_dep_arr.delete('GoogleMaps')
puts 'GoogleMaps pod is already added'
elsif line =~ /pod\s'GooglePlacePicker'/
@pod_dep_arr.delete('GooglePlacePicker')
puts 'GooglePlacePicker pod is already added'
end
end
begin
escaped_target_name = main_target.name.gsub(/'/, "\\\\\'")
File.readlines(@podfile_path).each do |line|
temp_file.puts(line)
@pod_dep_arr.each do |dep|
temp_file.puts(" pod '#{dep}'") if line =~ /target\s+'#{escaped_target_name}'\s+do/
end
end
temp_file.close
FileUtils.mv(temp_file.path, @podfile_path)
ensure
temp_file.delete
end
else
puts 'Adding Podfile to iOS project'
podfile = ''
podfile << "# Uncomment the next line to define a global platform for your project\n# platform :ios, '9.0'\n"
podfile << "\ntarget '#{main_target.name.gsub(/'/, "\\\\\'")}' do\n"
podfile << @pod_dep
podfile << " inherit! :search_paths\n"
podfile << "end\n"
puts podfile
File.write(@podfile_path, podfile)
end
puts 'Installing Pods'
system 'pod install'