class OrmDev::RunHelper

Attributes

podspec_path[R]
spec[R]

Public Class Methods

new(path) click to toggle source
# File lib/ormdev/source/core/run_helper.rb, line 11
def initialize(path)
  @podspec_path = path;
  @spec = Pod::Specification.from_file(path)
end

Public Instance Methods

setup(no_version_control) click to toggle source
# File lib/ormdev/source/core/run_helper.rb, line 16
def setup(no_version_control)
  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

  if no_version_control then
    archive_zip_source
    current_time = Time.new
    time_info_logs << "源码没有版本控制,归档到本机WebServer:#{current_time - start_time}秒"
    start_time = current_time
  end

  pod_package_framwork
  current_time = Time.new
  time_info_logs << "打包静态库:#{current_time - start_time}秒"
  start_time = current_time

  result = archive_zip_framwork
  current_time = Time.new
  time_info_logs << "压缩静态framework:#{current_time - start_time}秒"
  start_time = current_time

  # lint_zip_framwork
  # current_time = Time.new
  # time_info_logs << "验证静态framework:#{current_time - start_time}秒"
  # start_time = current_time

  time_info_logs << "#{@spec.name}总耗时:#{Time.new - task_start_time}秒"
  puts time_info_logs
  result
end

Private Instance Methods

add_file_to_zip(file_path, zip) click to toggle source
# File lib/ormdev/source/core/run_helper.rb, line 141
def add_file_to_zip(file_path, zip)
  return unless File::exist?(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
archive_zip_framwork() click to toggle source

压缩上传

# File lib/ormdev/source/core/run_helper.rb, line 123
def archive_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
  OrmDev::LogUtil.print_success "运行成功,#{zip_path}"
  zip_path
end
archive_zip_source() click to toggle source

归档源码

# File lib/ormdev/source/core/run_helper.rb, line 60
def archive_zip_source
  OrmDev::LogUtil.print_command '启动系统Apache服务,请求获取root权限,请输入root密码:'
  OrmDev::SHUtil.run_command('sudo apachectl restart','启动系统Apache服务', true)
  source_path = "#{@spec.name}.zip"
  FileUtils.rm_rf(source_path) if File::exist?(source_path)
  Zip::File.open(source_path, Zip::File::CREATE) do |zipfile|
    [
        "#{@spec.name}.podspec",
        'LICENSE',
        'README.md',
        'Dependencies',
        "#{@spec.name}/Assets",
        "#{@spec.name}/Classes",
    ].each do |filename|
      add_file_to_zip(filename, zipfile)
    end
  end
  OrmDev::LogUtil.print_success "归档压缩完成,#{source_path}"
  zip_root_path = '/Library/WebServer/Documents/OrmPlugins'
  unless Dir.exist?(zip_root_path) then
    OrmDev::LogUtil.print_command '创建插件根目录,请输入root密码:'
    OrmDev::SHUtil.run_command("sudo mkdir -p #{zip_root_path}",'创建插件根目录', true)
    OrmDev::SHUtil.run_command("sudo chown #{ENV["USER"]} #{zip_root_path}",'初始化插件根目录权限', true)
  end
  destination_path = File.join(zip_root_path, "#{@spec.name}.zip")
  FileUtils.rm_rf(destination_path) if File.exist?(destination_path)
  FileUtils.cp_r(source_path, destination_path)
  FileUtils.rm_rf(source_path)
  zip_http_path = "http://localhost/OrmPlugins/#{@spec.name}.zip"
  # 替换配置文件
  version_text = File.read(@podspec_path).sub(/^( )*orm_sdk_source(.*)\n/, "    orm_sdk_source = { :http => '#{zip_http_path}'}\n")
  File.open(@podspec_path, "w") { |file| file.puts version_text }
end
check_environment() click to toggle source

检测运行环境

# File lib/ormdev/source/core/run_helper.rb, line 55
def check_environment
  OrmDev::SHUtil.run_command('bundle install','检测配置运行环境',false)
end
pod_package_framwork() click to toggle source

静态化

# File lib/ormdev/source/core/run_helper.rb, line 95
def pod_package_framwork
  pod_package_command = "#{@spec.name}_SOURCE=1 pod package #{@spec.name}.podspec --exclude-deps --no-mangle --force --spec-sources=https://gitee.com/mvn/ios.git,https://github.com/CocoaPods/Specs.git --verbose"
  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