require 'cocoapods' require 'zip' require_relative '../util/sh_util' module OrmDev class RunHelper attr_reader :spec def initialize(path) @spec = Pod::Specification.from_file(path) end def setup() task_start_time = Time.now time_info_logs = ["开始运行:#{task_start_time}"] start_time = task_start_time # check_environment # current_time = Time.new # time_info_logs << "检查运行环境:#{current_time - start_time}秒" # start_time = current_time # # pod_package_framwork # current_time = Time.new # time_info_logs << "打包静态库:#{current_time - start_time}秒" # start_time = current_time upload_zip_framwork current_time = Time.new time_info_logs << "上传静态framework:#{current_time - start_time}秒" time_info_logs << "#{@spec.name}总耗时:#{Time.new - task_start_time}秒" puts time_info_logs end private # 检测运行环境 def check_environment OrmDev::SHUtil.run_command('bundle install','检测配置运行环境',false) end # 静态化 def pod_package_framwork pod_package_command = "#{@spec.name}_SOURCE=1 pod package #{@spec.name}.podspec --exclude-deps --no-mangle --force --spec-sources=git@gitee.com:mvn/ios.git,https://github.com/CocoaPods/Specs.git" OrmDev::SHUtil.run_command(pod_package_command,'静态化插件') destination_path = "#{@spec.name}/lib" source_path = "#{@spec.name}-#{@spec.version}" FileUtils.rm_rf(destination_path) if Dir.exist?(destination_path) FileUtils.cp_r("#{source_path}/ios", destination_path) FileUtils.rm_rf(source_path) # 去除.a armv7s i386的架构 Dir.chdir(destination_path) do lopo_remove_command = "lipo #{@spec.name}.framework/#{@spec.name} -remove armv7s -remove i386 -output #{@spec.name}.framework/#{@spec.name}" lopo_info_command = "lipo -info #{@spec.name}.framework/#{@spec.name}" OrmDev::SHUtil.run_command(lopo_remove_command,'移除framework armv7s i386的架构', false) OrmDev::SHUtil.run_command(lopo_info_command,'framework支持架构') end end # 压缩上传 def upload_zip_framwork zip_path = "#{@spec.name}.zip" FileUtils.rm_rf(zip_path) if File::exist?(zip_path) Zip::File.open(zip_path, Zip::File::CREATE) do |zipfile| [ "#{@spec.name}.podspec", 'LICENSE', 'README.md', 'Dependencies', "#{@spec.name}/lib", ].each do |filename| add_file_to_zip(filename, zipfile) end end zip_path OrmDev::LogUtil.print_success "运行成功,#{zip_path}" end def add_file_to_zip(file_path, zip) p file_path if File.directory?(file_path) Dir.foreach(file_path) do |sub_file_name| add_file_to_zip("#{file_path}/#{sub_file_name}", zip) unless sub_file_name == '.' or sub_file_name == '..' end else zip.add(file_path, file_path) end end end end