Class: Pod::Command::Bin::LocalPush

Inherits:
Pod::Command::Bin show all
Defined in:
lib/cocoapods-bb-bin/command/bin/localPush.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CBin::SpecFilesHelper

#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files

Methods included from CBin::SourcesHelper

#binary_source, #code_source, #sources_manager, #sources_option, #sources_optionV2, #valid_sources, #valid_sourcesV2

Constructor Details

#initialize(argv) ⇒ LocalPush

Returns a new instance of LocalPush.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cocoapods-bb-bin/command/bin/localPush.rb', line 27

def initialize(argv)
  @help = argv.flag?('help', false )
  if @help
  else
    @env = argv.option('env') || 'dev'
    CBin.config.set_configuration_env(@env)
  
    @podspec = argv.shift_argument || find_podspec
    @sources = argv.option('sources') || []
    @localPath = argv.option('path') || nil
    @vendored_framework_name = argv.option('vendored_framework_name') || nil
    @is_dylib = argv.flag?('dylib', false )
  end
  super
end

Class Method Details

.optionsObject



18
19
20
21
22
23
24
25
# File 'lib/cocoapods-bb-bin/command/bin/localPush.rb', line 18

def self.options
  [
    ['--sources', '私有源地址,多个用分号区分'],
    ['--path', '(必传)需要上传文件路径'],
    ['--vendored_framework_name', '(可选)组件库依赖framework名称,默认组件名称'],
    ['--dylib', '(可选)是否动态库,默认静态库'],
  ].concat(Pod::Command::Gen.options).concat(super).uniq
end

Instance Method Details

#find_podspecObject

Dir.glob 可替代

Raises:

  • (Informative)


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/cocoapods-bb-bin/command/bin/localPush.rb', line 97

def find_podspec
    name = nil
    Pathname.pwd.children.each do |child|
      # puts child
      if File.file?(child)
        if child.extname == '.podspec' || child.basename.to_s.include?('.podspec.json')
          name = File.basename(child)
          unless name.include?("binary-template")
            return name
          end
        end
      end
    end
    raise Informative,  "podspec File no exist, please check" unless name
    return name
end

#runObject



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
# File 'lib/cocoapods-bb-bin/command/bin/localPush.rb', line 48

def run
    # 配置二进制库环境,需要区分静态库还是动态库
    isGenDylib = @is_dylib
    sources_manager = Pod::Config.instance.sources_manager
    sources_manager.initLibEnv(isGenDylib)
    # 清除之前的缓存
    CBin::Config::Builder.instance.clean
    @spec = Specification.from_file(@podspec)
    # 上传文件
    localPath = update_uploadpath unless !@localPath
    if File.file?(localPath)
        # 生成podspec
        sources_sepc = Array.new
        sources_sepc << @spec

        fail_push_specs = []
        sources_sepc.uniq.each do |spec|
            begin
                fail_push_specs << spec unless CBin::Upload::Helper.new(spec,true,@sources,true).upload_binary_file(localPath, @is_dylib, @vendored_framework_name)
            rescue  Object => exception
                UI.puts exception
                fail_push_specs << spec
            end
        end
    
        if fail_push_specs.any?
            fail_push_specs.uniq.each do |spec|
                UI.warn "#{spec.name} | #{spec.version}】组件spec push失败 ."
            end
        end
    
        success_specs = sources_sepc - fail_push_specs
        if success_specs.any?
            auto_success = ""
            success_specs.uniq.each do |spec|
                auto_success += "#{spec.name} | #{spec.version}\n"
                UI.warn "===【 #{spec.name} | #{spec.version} 】二进制组件制作完成 !!! "
            end
            puts auto_success
            ENV['auto_success'] = auto_success
        end
        #pod repo update
        UI.section("\nUpdating Spec Repositories\n".yellow) do
            Pod::Command::Bin::Repo::Update.new(CLAide::ARGV.new([])).run
        end
    end
end

#update_uploadpathObject



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cocoapods-bb-bin/command/bin/localPush.rb', line 114

def update_uploadpath
    worksppace_path = Dir.pwd
    path = File.join(worksppace_path, @localPath)
    if File.file?(path)
        return path
    end
    path = @localPath
    if File.file?(path) # 判断文件绝对路径absolute_path 2x版本不支持
        return path
    end
    return nil
end

#validate!Object



43
44
45
46
# File 'lib/cocoapods-bb-bin/command/bin/localPush.rb', line 43

def validate!
  help! "未找到 podspec文件" unless @podspec
  super
end