Class: LgPodPlugin::Installer
- Inherits:
-
Object
- Object
- LgPodPlugin::Installer
- Defined in:
- lib/lg_pod_plugin/install.rb
Class Method Summary collapse
-
.run(command, options = {}) ⇒ Object
执行lg install/update命令.
-
.run_pod_install(update, libs, options = {}) ⇒ Object
执行pod install/update命令.
Instance Method Summary collapse
-
#initialize(profile, name, requirements) ⇒ Installer
constructor
A new instance of Installer.
- #install_remote_pod(name, options = {}) ⇒ Object
Constructor Details
#initialize(profile, name, requirements) ⇒ Installer
Returns a new instance of Installer.
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 |
# File 'lib/lg_pod_plugin/install.rb', line 18 def initialize(profile, name, requirements) unless name raise StandardError, 'A dependency requires a name.' end if name.include?("/") self.name = name.split("/").first else self.name = name end self.real_name = name self.workspace = profile.send(:defined_in_file).dirname self.target = profile.send(:current_target_definition) unless requirements && requirements.is_a?(Hash) LRequest.shared.libs.delete(name) LgPodPlugin.log_red "pod `#{name}`, 缺少必要的 [git|commit|tag|branch] 参数" return end hash_map = requirements hash_map.delete(:path) git = hash_map[:git] if git tag = hash_map[:tag] branch = hash_map[:branch] commit = hash_map[:commit] if tag hash_map.delete(:branch) hash_map.delete(:commit) elsif commit hash_map.delete(:tag) hash_map.delete(:branch) elsif branch hash_map.delete(:tag) hash_map.delete(:commit) else hash_map.delete(:tag) hash_map.delete(:branch) hash_map.delete(:commit) end end self. = hash_map LRequest.shared.setup_pod_info(self.name, self.workspace, hash_map) self.install_remote_pod(name, hash_map) end |
Class Method Details
.run(command, options = {}) ⇒ Object
执行lg install/update命令
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/lg_pod_plugin/install.rb', line 95 def self.run(command, = {}) work_space = Pathname(Dir.pwd) LgPodPlugin.log_green "当前工作目录 #{work_space}" podfile_path = work_space.join("Podfile") unless podfile_path.exist? LgPodPlugin.log_red "no such file `Podfile`" return end podfile = Pod::Podfile.from_file(podfile_path) # LgPodPlugin.log_red "podfile => #{podfile} podfile_path => #{podfile_path}" target = podfile.send(:current_target_definition) children = target.children install_hash_map = {} children.each do |s| internal_hash = s.send(:internal_hash) dependencies = internal_hash["dependencies"] next unless dependencies dependencies.each { |e| next unless e.is_a?(Hash) next if (key = e.keys.first) == nil next if (val = e[key].last) == nil next unless val.is_a?(Hash) install_hash_map[key] = val } end LRequest.shared.libs = install_hash_map LgPodPlugin.log_red "预下载Pod" install_hash_map.each do |key, val| Installer.new(podfile, key, val) end LgPodPlugin.log_red "开始安装pod" #切换工作目录到当前工程下, 开始执行pod install FileUtils.chdir(podfile_path.dirname) libs = LRequest.shared.libs.keys ||= [] # 执行pod install/ update 方法入口 update_pod = (command == "update") run_pod_install(update_pod, libs, ) end |
.run_pod_install(update, libs, options = {}) ⇒ Object
执行pod install/update命令
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lg_pod_plugin/install.rb', line 74 def self.run_pod_install(update, libs, = {}) verbose = [:verbose] repo_update = [:repo_update] if update if libs.empty? LgPodPlugin.log_red "no external pod update, you can use `pod update` to update --all pods" # LgPodPlugin.log_green "bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} " # system("bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} ") else pod_names = libs.join(" ") LgPodPlugin.log_green libs.join("\n") LgPodPlugin.log_green "bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} " system("bundle exec arch -x86_64 pod update #{pod_names} #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} ") end else LgPodPlugin.log_green "bundle exec arch -x86_64 pod install #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""}" system("bundle exec arch -x86_64 pod install #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""}") end end |
Instance Method Details
#install_remote_pod(name, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/lg_pod_plugin/install.rb', line 63 def install_remote_pod(name, = {}) if [:git] LRequest.shared.downloader.pre_download_pod else LRequest.shared.libs.delete(name) LgPodPlugin.log_red "pod `#{name}`, 缺少必要的 [git|commit|tag|branch] 参数" end end |