class Pod::Command::Bin::Archive

Public Class Methods

new(argv) click to toggle source
Calls superclass method Pod::Command::Bin::new
# File lib/cocoapods-bin/command/bin/archive.rb, line 31
def initialize(argv)
  @code_dependencies = argv.flag?('code-dependencies')
  @allow_prerelease = argv.flag?('allow-prerelease')
  @clean = argv.flag?('clean', true)
  @zip = argv.flag?('zip', true)
  @sources = argv.option('sources') || []
  @platform = Platform.new(:ios)
  @podspec = argv.shift_argument
  super

  @additional_args = argv.remainder!
end
options() click to toggle source
Calls superclass method
# File lib/cocoapods-bin/command/bin/archive.rb, line 18
def self.options
  [
    ['--code-dependencies', '使用源码依赖'],
    ['--allow-prerelease', '允许使用 prerelease 的版本'],
    ['--no-clean', '保留构建中间产物'],
    ['--no-zip', '不压缩静态 framework 为 zip']
  ].concat(Pod::Command::Gen.options).concat(super).uniq
end

Public Instance Methods

run() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 44
def run
  @spec = Specification.from_file(spec_file)
  generate_project
  build_static_framework
  zip_static_framework if @zip
  clean_workspace if @clean
end

Private Instance Methods

build_static_framework() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 87
def build_static_framework
  source_dir = Dir.pwd
  file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
  Dir.chdir(workspace_directory) do
    builder = CBin::Framework::Builder.new(@spec, file_accessor, @platform, source_dir)
    builder.build
  end
end
clean_workspace() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 96
def clean_workspace
  UI.puts 'Cleaning workspace'

  FileUtils.rm_rf(gen_name)
  FileUtils.rm_rf(framework_name) if @zip
end
framework_name() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 107
def framework_name
  "#{@spec.name}.framework"
end
gen_name() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 103
def gen_name
  'bin-archive'
end
generate_project() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 54
def generate_project
  Podfile.execute_with_bin_plugin do
    Podfile.execute_with_allow_prerelease(@allow_prerelease) do
      Podfile.execute_with_use_binaries(!@code_dependencies) do
        argvs = [
          "--sources=#{sources_option(@code_dependencies, @sources)}",
          "--gen-directory=#{gen_name}",
          '--clean',
          '--use-libraries',
          *@additional_args
        ]

        argvs << spec_file if spec_file

        gen = Pod::Command::Gen.new(CLAide::ARGV.new(argvs))
        gen.validate!
        gen.run
      end
    end
  end
end
spec_file() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 115
def spec_file
  @spec_file ||= begin
    if @podspec
      find_spec_file(@podspec)
    else
      if code_spec_files.empty?
        raise Informative, '当前目录下没有找到可用源码 podspec.'
      end

      spec_file = code_spec_files.first
      spec_file
    end
  end
end
workspace_directory() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 111
def workspace_directory
  File.expand_path("./#{gen_name}/#{@spec.name}")
end
zip_static_framework() click to toggle source
# File lib/cocoapods-bin/command/bin/archive.rb, line 76
def zip_static_framework
  output_name = "#{framework_name}.zip"
  unless File.exist?(framework_name)
    raise Informative, "没有需要压缩的 framework 文件:#{framework_name}"
  end

  UI.puts "Compressing #{framework_name} into #{output_name}"

  `zip --symlinks -r #{output_name} #{framework_name}`
end