Module: Pod::Podfile::DSL
- Defined in:
- lib/cocoapods-binary-flutter/hook/podfile.rb
Constant Summary collapse
- @@enable_fix_flutter_post_install =
false
Class Method Summary collapse
Instance Method Summary collapse
- #enable_fix_flutter_post_install! ⇒ Object
-
#install_all_lzflutter_pods(flutter_binary_path) ⇒ Object
安装.
-
#install_lzflutter_application_pod(flutter_binary_path) ⇒ Object
Install Flutter application pod.
-
#install_lzflutter_engine_pod(flutter_binary_path) ⇒ Object
安装flutter引擎.
-
#install_lzflutter_plugin_pods(flutter_binary_path) ⇒ Object
Install Flutter plugin pods.
-
#install_remote_flutter_binary(url = nil) ⇒ Object
下载.
Class Method Details
.enable_fix_flutter_post_install ⇒ Object
17 18 19 |
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 17 def self.enable_fix_flutter_post_install @@enable_fix_flutter_post_install end |
Instance Method Details
#enable_fix_flutter_post_install! ⇒ Object
21 22 23 |
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 21 def enable_fix_flutter_post_install! @@enable_fix_flutter_post_install = true end |
#install_all_lzflutter_pods(flutter_binary_path) ⇒ Object
安装
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 103 def install_all_lzflutter_pods(flutter_binary_path) # defined_in_file is a Pathname to the Podfile set by CocoaPods. pod_contents = File.read(defined_in_file) if pod_contents.include? 'flutter_post_install(installer)' unless pod_contents.include? 'flutter_post_install(installer) if defined?(flutter_post_install)' raise "产物依赖需要修改 flutter_post_install(installer) 增加define判断` in Podfile `post_install` block flutter_post_install(installer) if defined?(flutter_post_install) " end end install_lzflutter_engine_pod(flutter_binary_path) install_lzflutter_plugin_pods(flutter_binary_path) install_lzflutter_application_pod(flutter_binary_path) end |
#install_lzflutter_application_pod(flutter_binary_path) ⇒ Object
Install Flutter application pod.
150 151 152 |
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 150 def install_lzflutter_application_pod(flutter_binary_path) pod 'App', :path => File.join(flutter_binary_path, 'flutter'), :inhibit_warnings => true end |
#install_lzflutter_engine_pod(flutter_binary_path) ⇒ Object
安装flutter引擎
124 125 126 |
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 124 def install_lzflutter_engine_pod(flutter_binary_path) pod 'Flutter', :podspec => File.join(flutter_binary_path, 'flutter', 'Flutter.podspec'), :inhibit_warnings => true end |
#install_lzflutter_plugin_pods(flutter_binary_path) ⇒ Object
Install Flutter plugin pods.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 129 def install_lzflutter_plugin_pods(flutter_binary_path) # Keep pod path relative so it can be checked into Podfile.lock. # Process will be run from project directory. registrantPath = File.join(flutter_binary_path, 'flutter', 'FlutterPluginRegistrant') if File.exist?(registrantPath) pod 'FlutterPluginRegistrant', :path => registrantPath, :inhibit_warnings => true end #插件目录 ios_plugins_directory_pathname = File.join(flutter_binary_path, 'plugins') #plugins遍历 Dir.foreach(ios_plugins_directory_pathname) do |item| next if item == '.' or item == '..' or File::directory?(File.join(ios_plugins_directory_pathname, item)) == false # do work on real items pod item, :path => File.join(ios_plugins_directory_pathname, item, 'ios'), :inhibit_warnings => true end end |
#install_remote_flutter_binary(url = nil) ⇒ Object
下载
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 27 def install_remote_flutter_binary(url = nil) #md5 md5 = Digest::MD5.new # =>#<Digest::MD5> md5 << url md5value = md5.hexdigest # => "78e73102..." flutter_f_home = Dir.home+'/Library/Caches/CocoaPods/Flutter/' flutter_binary_home = flutter_f_home+md5value flutter_binary_path = flutter_binary_home+'/binary' #创建目录 FileUtils.mkdir_p(flutter_binary_home) #清除超过30天的缓存 Dir.foreach(flutter_f_home) do |item| next if item == '.' or item == '..' or item == '.DS_Store' # do work on real items dirpath = flutter_f_home+item if File.directory?(dirpath) a = File.mtime(dirpath) t = Time.new if (t-a).round/60/60/24 > 30 FileUtils.remove_dir(dirpath) end end end #下载解压 if File.directory?(flutter_binary_path) == false # 获取文件大小 uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == 'https' response = http.head(uri.request_uri) expected_size = response['Content-Length'].to_i # 下载文件 puts "开始下载 " + url download_file = open(File.join(flutter_binary_home, "binary.zip"), "wb") Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http| request = Net::HTTP::Get.new uri.request_uri request.basic_auth 'zhiya_official', '202525631b169f4446103671d4ff0661' begin http.request(request) do |resp| resp.read_body { |segment| download_file.write(segment) } end ensure download_file.close end end # 校验文件大小 actual_size = File.size(File.join(flutter_binary_home, "binary.zip")) if actual_size != expected_size puts "文件大小和预期不匹配" raise "文件大小和预期不匹配" end # 解压文件 puts "开始解压 " + flutter_binary_home begin system("unzip", "-n", File.join(flutter_binary_home, "binary.zip"), "-d", flutter_binary_home) rescue => exception puts "解压失败: " + exception. raise "解压失败" end end #集成 install_all_lzflutter_pods(flutter_binary_path) end |