module Pod class Command class JxedtCommand < Command class Binary < JxedtCommand class Build < Binary self.summary = '组件编译成二进制' self.description = <<-DESC 统计二进制组件 DESC self.command = 'build' self.arguments = [ ] def self.options [ ['--name', '编译的组件name,多个以,分隔'], ['--output-path', '编译的二进制文件输出路径'], ['--push', 'prebuild frameworks push origin.'], ['--force-push', 'force push generated frameworks'] ] end def initialize(argv) @names = argv.option('name', '').split(',') @output_path = argv.option('output-path') @force_push = argv.flag?('force-push', false) @should_push = argv.flag?('push', false) || @force_push super end def validate! super end def run podfile = Pod::Config.instance.podfile lockfile = Pod::Config.instance.lockfile sandbox = Pod::Config.instance.sandbox help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil? || lockfile.nil? || sandbox.nil? # 修改config配置 options = { :keep_source_project => true, # 保留源码工程 } Jxedt.config.dsl_config.merge!(options) require 'cocoapods-jxedt/binary/helper/target_definition' require 'cocoapods-jxedt/binary/helper/prebuild_sandbox' require 'cocoapods-jxedt/binary/helper/podfile_post_install_hook' require 'cocoapods-jxedt/binary/helper/prebuild_installer' # 获取原始的installer对象,必须先获取对象 prebuild_sandbox = Pod::JxedtPrebuildSandbox.from_standard_sandbox(sandbox) source_installer = Pod::JxedtPrebuildInstaller.new(prebuild_sandbox, podfile, lockfile) # 执行install source_installer.install! # 保存首次`pod install`的lockfile结果,用来验证二进制文件和后面做结果校验 sandbox.source_lockfile = prebuild_sandbox.source_lockfile = source_installer.lockfile require 'cocoapods-jxedt/binary/helper/podfile_options' require 'cocoapods-jxedt/binary/prebuild' # prebuild_job log_section "🚀 Prebuild frameworks" # 默认放在Pods源码工程同级目录下 @output_path = prebuild_sandbox.project_path.parent + '.command_build' if @output_path.nil? build_targets = Jxedt::Prebuild.new(source_installer).build_targets :names => @names, :binary_output => @output_path if @should_push && Jxedt.config.cache_repo_enabled? require 'cocoapods-jxedt/git_helper/cache_pucher' output_dir = Pathname.new(@output_path) Jxedt::CachePucher.push(output_dir, build_targets, @force_push) end prebuild_sandbox.clean_source_project! end def log_section(message) Pod::UI.puts "-----------------------------------------" Pod::UI.puts message Pod::UI.puts "-----------------------------------------" end end end end end end