Class: CBin::BuildAll::PodspecUtil

Inherits:
Object
  • Object
show all
Includes:
Pod
Defined in:
lib/cocoapods-mtxx-bin/helpers/buildAll/podspec_util.rb

Instance Method Summary collapse

Methods included from Pod

match_version?

Constructor Details

#initialize(pod_target, version, build_as_framework = false, configuration = 'Debug') ⇒ PodspecUtil

Returns a new instance of PodspecUtil.

[View source]

7
8
9
10
11
12
# File 'lib/cocoapods-mtxx-bin/helpers/buildAll/podspec_util.rb', line 7

def initialize(pod_target, version, build_as_framework = false, configuration = 'Debug')
  @pod_target = pod_target
  @version = version
  @build_as_framework = build_as_framework
  @configuration = configuration
end

Instance Method Details

#create_binary_podspecObject

创建二进制podspec

[View source]

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cocoapods-mtxx-bin/helpers/buildAll/podspec_util.rb', line 15

def create_binary_podspec
  UI.info "创建二进制podspec:`#{@pod_target}`".yellow
  spec = @pod_target.root_spec.to_hash
  root_dir = @pod_target.framework_name
  # 处理版本号
  spec['version'] = version
  # 处理source
  spec['source'] = source
  # 处理头文件
  spec['source_files'] = "#{root_dir}/Headers/*.h"
  spec['public_header_files'] = "#{root_dir}/Headers/*.h"
  spec['private_header_files'] = "#{root_dir}/PrivateHeaders/*.h"
  # 处理vendored_libraries和vendored_frameworks
  spec['vendored_libraries'] = "#{root_dir}/libs/*.a"
  spec['vendored_frameworks'] = %W[#{root_dir} #{root_dir}/fwks/*.framework]
  # 处理资源
  resources = %W[#{root_dir}/*.{#{special_resource_exts.join(',')}} #{root_dir}/resources/*]
  spec['resources'] = resources
  # 删除无用的字段
  delete_unused(spec)
  # 处理subspecs
  handle_subspecs(spec)
  # 生成二进制podspec
  bin_spec = Pod::Specification.from_hash(spec)
  bin_spec.description = <<-EOF
   「converted automatically by plugin cocoapods-mtxx-bin @美图 - zys」
    #{bin_spec.description}
  EOF
  bin_spec
  # puts bin_spec.to_json
end

#push_binary_podspec(binary_podsepc_json) ⇒ Object

上传二进制podspec

[View source]

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cocoapods-mtxx-bin/helpers/buildAll/podspec_util.rb', line 62

def push_binary_podspec(binary_podsepc_json)
  UI.info "推送podspec:`#{@pod_target}`".yellow
  return unless File.exist?(binary_podsepc_json)
  repo_name = Pod::Config.instance.sources_manager.binary_source.name
  # repo_name = 'example-private-spec-bin'
  argvs = %W[#{repo_name} #{binary_podsepc_json} --skip-import-validation --use-libraries --allow-warnings --verbose]

  begin
    push = Pod::Command::Repo::Push.new(CLAide::ARGV.new(argvs))
    push.validate!
    push.run
    return true
  rescue Pod::StandardError => e
    UI.info "推送podspec:`#{@pod_target}`失败,#{e.to_s}".red
    return false
  end
end

#write_binary_podspec(spec) ⇒ Object

podspec写入文件

[View source]

48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cocoapods-mtxx-bin/helpers/buildAll/podspec_util.rb', line 48

def write_binary_podspec(spec)
  UI.info "写入podspec:`#{@pod_target}`".yellow
  podspec_dir = "#{Pathname.pwd}/build_pods/#{@pod_target}/Products/podspec"
  FileUtils.mkdir(podspec_dir) unless File.exist?(podspec_dir)
  file = "#{podspec_dir}/#{@pod_target.pod_name}.podspec.json"
  FileUtils.rm_rf(file) if File.exist?(file)

  File.open(file, "w+") do |f|
    f.write(spec.to_pretty_json)
  end
  file
end