cocoapods-meitu-bin 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +56 -0
  4. data/lib/cocoapods-meitu-bin/command/bin/archive.rb +206 -0
  5. data/lib/cocoapods-meitu-bin/command/bin/auto.rb +212 -0
  6. data/lib/cocoapods-meitu-bin/command/bin/build_all.rb +345 -0
  7. data/lib/cocoapods-meitu-bin/command/bin/header_files_specifications.rb +262 -0
  8. data/lib/cocoapods-meitu-bin/command/bin/init.rb +72 -0
  9. data/lib/cocoapods-meitu-bin/command/bin/install.rb +44 -0
  10. data/lib/cocoapods-meitu-bin/command/bin/lib/lint.rb +67 -0
  11. data/lib/cocoapods-meitu-bin/command/bin/lock/dependency.rb +89 -0
  12. data/lib/cocoapods-meitu-bin/command/bin/lock/spec_repo.rb +105 -0
  13. data/lib/cocoapods-meitu-bin/command/bin/lock/version.rb +68 -0
  14. data/lib/cocoapods-meitu-bin/command/bin/lock.rb +36 -0
  15. data/lib/cocoapods-meitu-bin/command/bin/output_source.rb +146 -0
  16. data/lib/cocoapods-meitu-bin/command/bin/repo/push.rb +88 -0
  17. data/lib/cocoapods-meitu-bin/command/bin/repo/update.rb +42 -0
  18. data/lib/cocoapods-meitu-bin/command/bin/repo.rb +14 -0
  19. data/lib/cocoapods-meitu-bin/command/bin/source/add.rb +148 -0
  20. data/lib/cocoapods-meitu-bin/command/bin/source/delete.rb +59 -0
  21. data/lib/cocoapods-meitu-bin/command/bin/source/list.rb +46 -0
  22. data/lib/cocoapods-meitu-bin/command/bin/source.rb +30 -0
  23. data/lib/cocoapods-meitu-bin/command/bin/spec/create.rb +73 -0
  24. data/lib/cocoapods-meitu-bin/command/bin/spec/lint.rb +109 -0
  25. data/lib/cocoapods-meitu-bin/command/bin/spec.rb +13 -0
  26. data/lib/cocoapods-meitu-bin/command/bin/update.rb +154 -0
  27. data/lib/cocoapods-meitu-bin/command/bin/upload.rb +175 -0
  28. data/lib/cocoapods-meitu-bin/command/bin.rb +69 -0
  29. data/lib/cocoapods-meitu-bin/command.rb +1 -0
  30. data/lib/cocoapods-meitu-bin/config/config.rb +149 -0
  31. data/lib/cocoapods-meitu-bin/config/config_asker.rb +57 -0
  32. data/lib/cocoapods-meitu-bin/config/config_builder.rb +216 -0
  33. data/lib/cocoapods-meitu-bin/gem_version.rb +9 -0
  34. data/lib/cocoapods-meitu-bin/helpers/Info.plist +0 -0
  35. data/lib/cocoapods-meitu-bin/helpers/buildAll/bin_helper.rb +97 -0
  36. data/lib/cocoapods-meitu-bin/helpers/buildAll/builder.rb +434 -0
  37. data/lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb +140 -0
  38. data/lib/cocoapods-meitu-bin/helpers/buildAll/zip_file_helper.rb +87 -0
  39. data/lib/cocoapods-meitu-bin/helpers/build_helper.rb +167 -0
  40. data/lib/cocoapods-meitu-bin/helpers/build_utils.rb +64 -0
  41. data/lib/cocoapods-meitu-bin/helpers/framework.rb +86 -0
  42. data/lib/cocoapods-meitu-bin/helpers/framework_builder.rb +551 -0
  43. data/lib/cocoapods-meitu-bin/helpers/library.rb +54 -0
  44. data/lib/cocoapods-meitu-bin/helpers/library_builder.rb +90 -0
  45. data/lib/cocoapods-meitu-bin/helpers/pod_size_helper.rb +54 -0
  46. data/lib/cocoapods-meitu-bin/helpers/sources_helper.rb +35 -0
  47. data/lib/cocoapods-meitu-bin/helpers/spec_creator.rb +170 -0
  48. data/lib/cocoapods-meitu-bin/helpers/spec_files_helper.rb +80 -0
  49. data/lib/cocoapods-meitu-bin/helpers/spec_source_creator.rb +304 -0
  50. data/lib/cocoapods-meitu-bin/helpers/upload_helper.rb +104 -0
  51. data/lib/cocoapods-meitu-bin/helpers.rb +5 -0
  52. data/lib/cocoapods-meitu-bin/native/acknowledgements.rb +27 -0
  53. data/lib/cocoapods-meitu-bin/native/analyzer.rb +109 -0
  54. data/lib/cocoapods-meitu-bin/native/file_accessor.rb +28 -0
  55. data/lib/cocoapods-meitu-bin/native/gen.rb +79 -0
  56. data/lib/cocoapods-meitu-bin/native/installation_options.rb +28 -0
  57. data/lib/cocoapods-meitu-bin/native/installer.rb +259 -0
  58. data/lib/cocoapods-meitu-bin/native/linter.rb +26 -0
  59. data/lib/cocoapods-meitu-bin/native/lockfile.rb +85 -0
  60. data/lib/cocoapods-meitu-bin/native/path_source.rb +33 -0
  61. data/lib/cocoapods-meitu-bin/native/pod_source_installer.rb +19 -0
  62. data/lib/cocoapods-meitu-bin/native/pod_target_installer.rb +87 -0
  63. data/lib/cocoapods-meitu-bin/native/podfile.rb +99 -0
  64. data/lib/cocoapods-meitu-bin/native/podfile_env.rb +38 -0
  65. data/lib/cocoapods-meitu-bin/native/podfile_generator.rb +201 -0
  66. data/lib/cocoapods-meitu-bin/native/podspec_finder.rb +25 -0
  67. data/lib/cocoapods-meitu-bin/native/resolver.rb +299 -0
  68. data/lib/cocoapods-meitu-bin/native/sandbox_analyzer.rb +34 -0
  69. data/lib/cocoapods-meitu-bin/native/source.rb +35 -0
  70. data/lib/cocoapods-meitu-bin/native/sources_manager.rb +21 -0
  71. data/lib/cocoapods-meitu-bin/native/specification.rb +31 -0
  72. data/lib/cocoapods-meitu-bin/native/target_validator.rb +41 -0
  73. data/lib/cocoapods-meitu-bin/native/validator.rb +40 -0
  74. data/lib/cocoapods-meitu-bin/native.rb +26 -0
  75. data/lib/cocoapods-meitu-bin/source_provider_hook.rb +68 -0
  76. data/lib/cocoapods-meitu-bin.rb +2 -0
  77. data/lib/cocoapods_plugin.rb +11 -0
  78. data/spec/command/bin_spec.rb +12 -0
  79. data/spec/spec_helper.rb +50 -0
  80. metadata +201 -0
@@ -0,0 +1,54 @@
1
+ module CBin
2
+ class PodSize
3
+ include Pod
4
+
5
+ # 多线程锁
6
+ @@lock = Mutex.new
7
+ # 阈值,单位MB
8
+ @@size_threshold = 500
9
+ # 存放过大Pod信息的临时文件
10
+ @@tmp_file_path = File.join(Dir.pwd, '.mtxx_big_pods.log')
11
+
12
+ # 添加超过阈值的pod
13
+ def self.add_pod(pod)
14
+ if pod[:size].to_i < @@size_threshold * 1024
15
+ return
16
+ end
17
+ @@lock.synchronize do
18
+ File.open(@@tmp_file_path, "a") do |f|
19
+ f.write(format_pod_size(pod))
20
+ end
21
+ end
22
+ end
23
+
24
+ # 格式化pod
25
+ def self.format_pod_size(pod)
26
+ unit = 'KB'
27
+ size = pod[:size].to_i
28
+ if size >= 1024 * 1024
29
+ unit = 'GB'
30
+ size = ('%.1f' % (size / 1024.0 / 1024.0)).to_f
31
+ elsif size >= 1024
32
+ unit = 'MB'
33
+ size = ('%.1f' % (size / 1024.0)).to_f
34
+ end
35
+ "#{pod[:name]}:#{size}#{unit}\n"
36
+ end
37
+
38
+ # 打印超过阈值的Pod库
39
+ def self.print_pods
40
+ unless File.exist?(@@tmp_file_path)
41
+ return
42
+ end
43
+ UI.puts "\n"
44
+ UI.puts "以下Pod库下载大小大于阈值`#{@@size_threshold}MB`:".green
45
+ File.open(@@tmp_file_path, "r") do |f|
46
+ f.readlines.map do |line|
47
+ UI.puts " - #{line.strip}".green
48
+ end
49
+ end
50
+ # 打印完成后,删除临时文件
51
+ FileUtils.rm_f(@@tmp_file_path) if File.exist?(@@tmp_file_path)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+
2
+
3
+ require 'cocoapods-meitu-bin/native/sources_manager.rb'
4
+
5
+ module CBin
6
+ module SourcesHelper
7
+ def sources_manager
8
+ Pod::Config.instance.sources_manager
9
+ end
10
+
11
+ def binary_source
12
+ sources_manager.binary_source
13
+ end
14
+
15
+ def code_source_list
16
+ sources_manager.code_source_list
17
+ end
18
+ # 优先采用对应依赖的 source
19
+ # cocoapods 内部会先匹配前面符合的 specification
20
+ # 只允许二进制的 specification subspec 比源码的 specification subspec 多
21
+ #
22
+ def valid_sources(code_dependencies = false)
23
+ sources = code_source_list
24
+ unless code_dependencies
25
+ sources << binary_source
26
+ sources.reverse!
27
+ end
28
+ sources
29
+ end
30
+
31
+ def sources_option(code_dependencies, additional_sources)
32
+ (valid_sources(code_dependencies).map(&:url) + Array(additional_sources)).join(',')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,170 @@
1
+
2
+
3
+ require 'cocoapods'
4
+ require 'cocoapods-meitu-bin/config/config'
5
+
6
+ module CBin
7
+ class Specification
8
+ class Creator
9
+ attr_reader :code_spec
10
+ attr_reader :template_spec
11
+ attr_reader :spec
12
+
13
+ def initialize(code_spec, template_spec, platforms = 'ios')
14
+ @code_spec = code_spec
15
+ @template_spec = template_spec
16
+ @platforms = Array(platforms)
17
+ validate!
18
+ end
19
+
20
+ def validate!
21
+ raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
22
+ if code_spec.subspecs.any? && template_spec.nil?
23
+ raise Pod::Informative, "不支持自动生成存在 subspec 的二进制 podspec , 需要提供模版文件 #{code_spec.name}.binary.podspec.template ."
24
+ end
25
+ end
26
+
27
+ def create
28
+ spec = template_spec ? create_from_code_spec_and_template_spec : create_from_code_spec
29
+
30
+ Pod::UI.message '生成二进制 podspec 内容: '
31
+ spec.to_pretty_json.split("\n").each do |text|
32
+ Pod::UI.message text
33
+ end
34
+
35
+ spec
36
+ end
37
+
38
+ def write_spec_file(file = filename)
39
+ create unless spec
40
+
41
+ File.open(file, 'w+') do |f|
42
+ f.write(spec.to_pretty_json)
43
+ end
44
+
45
+ @filename = file
46
+ end
47
+
48
+ def clear_spec_file
49
+ File.delete(filename) if File.exist?(filename)
50
+ end
51
+
52
+ def filename
53
+ @filename ||= "#{spec.name}.binary.podspec.json"
54
+ end
55
+
56
+ private
57
+
58
+ def create_from_code_spec
59
+ @spec = code_spec.dup
60
+ # vendored_frameworks | resources | source | source_files | public_header_files
61
+ # license | resource_bundles | vendored_libraries
62
+
63
+ # Project Linkin
64
+ @spec.vendored_frameworks = "#{code_spec.root.name}.framework"
65
+
66
+ # Resources
67
+ extnames = []
68
+ extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
69
+ if code_spec_consumer.resources.any?
70
+ extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
71
+ end
72
+ if extnames.any?
73
+ @spec.resources = framework_contents('Resources').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
74
+ end
75
+
76
+ # Source Location
77
+ @spec.source = binary_source
78
+
79
+ # Source Code
80
+ @spec.source_files = framework_contents('Headers/*')
81
+ @spec.public_header_files = framework_contents('Headers/*')
82
+
83
+ # Unused for binary
84
+ spec_hash = @spec.to_hash
85
+ # spec_hash.delete('license')
86
+ spec_hash.delete('resource_bundles')
87
+ spec_hash.delete('exclude_files')
88
+ spec_hash.delete('preserve_paths')
89
+ # 这里不确定 vendored_libraries 指定的时动态/静态库
90
+ # 如果是静态库的话,需要移除,否则就不移除
91
+ # 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
92
+ # 这里统一只对命名后缀 .a 文件做处理
93
+ # spec_hash.delete('vendored_libraries')
94
+ # libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
95
+ spec_hash.delete('vendored_libraries')
96
+ spec_hash['vendored_libraries'] = binary_vendored_libraries
97
+
98
+ # vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
99
+ # if vendored_libraries.any?
100
+ # spec_hash['vendored_libraries'] = vendored_libraries
101
+ # end
102
+
103
+ # Filter platforms
104
+ platforms = spec_hash['platforms']
105
+ selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
106
+ spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
107
+
108
+ @spec = Pod::Specification.from_hash(spec_hash)
109
+ @spec
110
+ end
111
+
112
+ def create_from_code_spec_and_template_spec
113
+ @spec = template_spec.dup
114
+
115
+ @spec.version = code_spec.version
116
+ @spec.source = binary_source
117
+
118
+ @spec.source_files = binary_source_files
119
+ @spec.public_header_files = binary_public_header_files
120
+ @spec.vendored_libraries = binary_vendored_libraries
121
+
122
+ @spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources")
123
+
124
+
125
+
126
+ @spec
127
+ end
128
+
129
+ def binary_source
130
+ { http: format(CBin.config.binary_download_url), type: CBin.config.download_file_type }
131
+ end
132
+
133
+ def code_spec_consumer(_platform = :ios)
134
+ code_spec.consumer(:ios)
135
+ end
136
+
137
+ def framework_contents(name)
138
+ ["#{code_spec.root.name}.framework"].map { |path| "#{path}/#{name}" }
139
+ end
140
+
141
+ def binary_source_files
142
+ { http: format(CBin.config.binary_download_url), type: CBin.config.download_file_type }
143
+ end
144
+
145
+ def binary_source_files
146
+ "bin_#{code_spec.name}_#{code_spec.version}/Headers/*"
147
+ end
148
+
149
+ def binary_public_header_files
150
+ "bin_#{code_spec.name}_#{code_spec.version}/Headers/*.h"
151
+ end
152
+
153
+ def binary_vendored_libraries
154
+ "bin_#{code_spec.name}_#{code_spec.version}/*.a"
155
+ end
156
+
157
+ def binary_resources
158
+ "bin_#{code_spec.name}_#{code_spec.version}/Resources/*"
159
+ end
160
+
161
+ end
162
+ end
163
+ end
164
+ #模板框架begin
165
+ # s.source_files = "bin_#{s.name}_#{s.version}/Headers/*"
166
+ # s.public_header_files = "bin_#{s.name}_#{s.version}/Headers/*.h"
167
+ # s.vendored_libraries = "bin_#{s.name}_#{s.version}/*.a"
168
+ #有图片资源的,要带上
169
+ #s.resources = 'bin_#{s.name}_#{s.version}/Resources/*.{json,png,jpg,gif,js,xib,eot,svg,ttf,woff,db,sqlite,mp3,bundle}'
170
+ #模板框架end
@@ -0,0 +1,80 @@
1
+
2
+
3
+ require 'cocoapods-meitu-bin/native/sources_manager.rb'
4
+ require 'cocoapods-meitu-bin/helpers/spec_creator'
5
+
6
+ module CBin
7
+ module SpecFilesHelper
8
+ def spec_files
9
+ @spec_files ||= Pathname.glob('*.podspec{,.json}')
10
+ end
11
+
12
+ def binary_spec_files
13
+ @binary_spec_files ||= Pathname.glob('*.binary.podspec{,.json}')
14
+ end
15
+
16
+ def binary_template_spec_files
17
+ @binary_spec_template_files ||= Pathname.glob('*.binary-template.podspec{,.json}')
18
+ end
19
+
20
+ def binary_template_spec_file
21
+ @binary_spec_template_file ||= binary_template_spec_files.first
22
+ end
23
+
24
+ def code_spec_files
25
+ @code_spec_files ||= spec_files - binary_spec_files - binary_template_spec_files
26
+ end
27
+
28
+ def code_spec
29
+ if code_spec_files.first
30
+ Pod::Specification.from_file(code_spec_files.first)
31
+ end
32
+ end
33
+
34
+ def binary_spec
35
+ if binary_spec_files.first
36
+ Pod::Specification.from_file(binary_spec_files.first)
37
+ end
38
+ end
39
+
40
+ def binary_template_spec
41
+ if binary_template_spec_file
42
+ Pod::Specification.from_file(binary_template_spec_file)
43
+ end
44
+ end
45
+
46
+ def find_spec_file(podspec)
47
+ path = Pathname(podspec)
48
+ raise Pod::Informative, "无法找到 #{podspec}" unless path.exist?
49
+
50
+ path
51
+ end
52
+
53
+ def create_binary_spec_file(code_spec, template_spec)
54
+ # 1. code spec 是否有 subpsec
55
+ # 1.1 有,查找 template spec,并生成
56
+ # 1.2 没有,是否有 template spec
57
+ # 1.2.1 有,根据 template spec 生成
58
+ # 1.2.2 没有,根据 code spec 生成
59
+
60
+ unless code_spec
61
+ raise Pod::Informative, '没有二进制 podspec 的情况下,必须要提供源码 podspec.'
62
+ end
63
+ # if code_spec.subspecs.any? && template_spec.nil?
64
+ # raise Pod::Informative, '拥有 subspec 的组件,在生成二进制 podspec 时,必须要提供模版 podspec.'
65
+ # end
66
+
67
+ Dir.chdir(CBin::Config::Builder.instance.root_dir) do
68
+ @spec_creator = CBin::SpecificationSource::Creator.new(code_spec)
69
+ # @spec_creator = CBin::Specification::Creator.new(code_spec, template_spec)
70
+ @spec_creator.create
71
+ @spec_creator.write_spec_file
72
+ @spec_creator.filename
73
+ end
74
+ end
75
+
76
+ def clear_binary_spec_file_if_needed
77
+ @spec_creator&.clear_spec_file
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,304 @@
1
+ require 'cocoapods'
2
+ require 'cocoapods-meitu-bin/config/config'
3
+
4
+ module CBin
5
+ class SpecificationSource
6
+ class Creator
7
+ attr_reader :code_spec
8
+ attr_reader :spec
9
+
10
+ def initialize(code_spec, platforms = 'ios')
11
+ @code_spec = code_spec
12
+ @platforms = Array(platforms)
13
+ validate!
14
+ end
15
+
16
+ def validate!
17
+ raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
18
+ end
19
+
20
+ # 创建二进制podspec
21
+ def create
22
+ # spec = nil
23
+ if CBin::Build::Utils.is_framework(@code_spec)
24
+ # .framework
25
+ spec = create_framework_from_code_spec
26
+ else
27
+ # .a
28
+ spec = create_from_code_spec
29
+ end
30
+
31
+ spec
32
+ end
33
+
34
+ # 将二进制podspec写入文件
35
+ def write_spec_file(file = filename)
36
+ create unless spec
37
+
38
+ FileUtils.mkdir_p(CBin::Config::Builder.instance.binary_json_dir) unless File.exist?(CBin::Config::Builder.instance.binary_json_dir)
39
+ FileUtils.rm_rf(file) if File.exist?(file)
40
+
41
+ File.open(file, 'w+') do |f|
42
+ # f.write("# MARK: converted automatically by plugin cocoapods-meitu-bin @slj \r\n")
43
+ f.write(spec.to_pretty_json)
44
+ end
45
+
46
+ @filename = file
47
+ end
48
+
49
+ def clear_spec_file
50
+ File.delete(filename) if File.exist?(filename)
51
+ end
52
+
53
+ def filename
54
+ @filename ||= "#{CBin::Config::Builder.instance.binary_json_dir_name}/#{spec.name}.binary.podspec.json"
55
+ end
56
+
57
+ private
58
+
59
+ # 创建.a的二进制podspec
60
+ def create_from_code_spec
61
+ @spec = code_spec.dup
62
+ # vendored_frameworks | resources | source | source_files | public_header_files
63
+ # license | resource_bundles | vendored_libraries
64
+
65
+ # Project Linkin
66
+ # @spec.vendored_frameworks = "#{code_spec.root.name}.framework"
67
+
68
+ # Resources
69
+ extnames = []
70
+ extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
71
+ if code_spec_consumer.resources.any?
72
+ extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
73
+ end
74
+ if extnames.any?
75
+ @spec.resources = framework_contents('').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
76
+ end
77
+
78
+ # Source Location
79
+ @spec.source = binary_source
80
+
81
+ # Source Code
82
+ @spec.source_files = framework_contents('Headers/*')
83
+ @spec.public_header_files = framework_contents('Headers/*')
84
+
85
+ # Unused for binary
86
+ spec_hash = @spec.to_hash
87
+ # spec_hash.delete('license')
88
+ spec_hash.delete('source_files')
89
+ spec_hash.delete('resource_bundles')
90
+ spec_hash.delete('exclude_files')
91
+ spec_hash.delete('preserve_paths')
92
+
93
+ spec_hash.delete('subspecs')
94
+ spec_hash.delete('default_subspecs')
95
+ spec_hash.delete('default_subspec')
96
+ spec_hash.delete('vendored_frameworks')
97
+ spec_hash.delete('vendored_framework')
98
+
99
+ # 这里不确定 vendored_libraries 指定的时动态/静态库
100
+ # 如果是静态库的话,需要移除,否则就不移除
101
+ # 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
102
+ # 这里统一只对命名后缀 .a 文件做处理
103
+ # spec_hash.delete('vendored_libraries')
104
+ # libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
105
+ spec_hash.delete('vendored_libraries')
106
+
107
+ # vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
108
+ # if vendored_libraries.any?
109
+ # spec_hash['vendored_libraries'] = vendored_libraries
110
+ # end
111
+
112
+ # Filter platforms
113
+ platforms = spec_hash['platforms']
114
+ selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
115
+ spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
116
+
117
+ @spec = Pod::Specification.from_hash(spec_hash)
118
+
119
+ #把命令 prepare_command 移除掉,如ReactiveCocoa会执行修改重命令的脚步
120
+ @spec.prepare_command = "" if @spec.prepare_command
121
+ @spec.version = code_spec.version
122
+ @spec.source = binary_source
123
+ @spec.source_files = binary_source_files
124
+ @spec.public_header_files = binary_public_header_files
125
+ @spec.vendored_libraries = binary_vendored_libraries
126
+ @spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources")
127
+ @spec.description = <<-EOF
128
+ 「converted automatically by plugin cocoapods-meitu-bin @美图 - zys」
129
+ #{@spec.description}
130
+ EOF
131
+ @spec
132
+ end
133
+
134
+ # 创建.framework的二进制podspec
135
+ def create_framework_from_code_spec
136
+ @spec = code_spec.dup
137
+ # vendored_frameworks | resources | source | source_files | public_header_files
138
+ # license | resource_bundles | vendored_libraries
139
+
140
+ # framework绝对路径
141
+ fwk_abs_path = "#{CBin::Config::Builder.instance.gen_dir}/#{code_spec.root.name}/ios/#{code_spec.module_name}.framework"
142
+
143
+ # Project Linkin
144
+ fwks_path = "#{fwk_abs_path}/fwks"
145
+ fwks = ["#{code_spec.module_name}.framework"]
146
+ if File.exist?(fwks_path)
147
+ fwks << "#{code_spec.module_name}.framework/fwks/*"
148
+ end
149
+ @spec.vendored_frameworks = fwks
150
+
151
+ libs_path = "#{fwk_abs_path}/libs"
152
+ @spec.vendored_libraries = "#{code_spec.module_name}.framework/libs/*" if File.exist?(libs_path)
153
+
154
+ # Resources
155
+ special_resource_ext_str = special_resource_exts.join(',')
156
+ special_res = Dir.glob("#{fwk_abs_path}/*.{#{special_resource_ext_str}}")
157
+ resources = []
158
+ unless special_res.empty?
159
+ resources << "#{code_spec.module_name}.framework/*.{#{special_resource_ext_str}}"
160
+ end
161
+ resources_path = "#{fwk_abs_path}/resources"
162
+ if File.exist?(resources_path)
163
+ resources << "#{code_spec.module_name}.framework/resources/*"
164
+ end
165
+ @spec.resources = resources unless resources.empty?
166
+
167
+ # Source Location
168
+ @spec.source = binary_source
169
+ # Source Code
170
+ @spec.source_files = "#{code_spec.module_name}.framework/Headers/*"
171
+ @spec.public_header_files = "#{code_spec.module_name}.framework/Headers/*"
172
+ @spec.private_header_files = "#{code_spec.module_name}.framework/PrivateHeaders/*"
173
+
174
+ # Unused for binary
175
+ spec_hash = @spec.to_hash
176
+ # spec_hash.delete('license')
177
+ # spec_hash.delete('source_files')
178
+ spec_hash.delete('project_header_files')
179
+ spec_hash.delete('resource_bundles')
180
+ spec_hash.delete('exclude_files')
181
+ spec_hash.delete('preserve_paths')
182
+ spec_hash.delete('prepare_command')
183
+ # 这里不确定 vendored_libraries 指定的时动态/静态库
184
+ # 如果是静态库的话,需要移除,否则就不移除
185
+ # 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
186
+ # 这里统一只对命名后缀 .a 文件做处理
187
+ # spec_hash.delete('vendored_libraries')
188
+ # libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
189
+ # vendored_libraries = spec_hash.delete('vendored_libraries')
190
+ # vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
191
+ # if vendored_libraries.any?
192
+ # spec_hash['vendored_libraries'] = vendored_libraries
193
+ # end
194
+
195
+ # Filter platforms
196
+ platforms = spec_hash['platforms']
197
+ selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
198
+ spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
199
+
200
+ # subspecs
201
+ if spec_hash['subspecs'] && spec_hash['subspecs'].size > 0
202
+ bin_subspec = {
203
+ 'name' => 'Binary',
204
+ 'source_files' => spec_hash['source_files'],
205
+ 'public_header_files' => spec_hash['public_header_files'],
206
+ 'private_header_files' => spec_hash['private_header_files'],
207
+ 'vendored_frameworks' => spec_hash['vendored_frameworks'],
208
+ 'vendored_libraries' => spec_hash['vendored_libraries'],
209
+ 'resources' => spec_hash['resources']
210
+ }
211
+ spec_hash['subspecs'] << bin_subspec
212
+ spec_hash['subspecs'].map do |subspec|
213
+ next if subspec['name'] == 'Binary'
214
+ # 处理单个subspec
215
+ handle_single_subspec(subspec)
216
+ # 递归处理subspec
217
+ handle_subspecs(subspec['subspecs'])
218
+ end
219
+ end
220
+
221
+ @spec = Pod::Specification.from_hash(spec_hash)
222
+ @spec.description = <<-EOF
223
+ 「converted automatically by plugin cocoapods-meitu-bin @美图 - zys」
224
+ #{@spec.description}
225
+ EOF
226
+ @spec
227
+ end
228
+
229
+ # 特殊的资源后缀
230
+ def special_resource_exts
231
+ %w[momd mom cdm nib storyboardc]
232
+ end
233
+
234
+ # 递归处理subspecs
235
+ def handle_subspecs(subspecs)
236
+ return unless subspecs && subspecs.size > 0
237
+ subspecs.map do |s|
238
+ # 处理单个subspec
239
+ handle_single_subspec(s)
240
+ # 递归处理
241
+ handle_subspecs(s['subspecs'])
242
+ end
243
+ end
244
+
245
+ # 处理单个subspec
246
+ def handle_single_subspec(subspec)
247
+ subspec.delete('source_files')
248
+ subspec.delete('public_header_files')
249
+ subspec.delete('project_header_files')
250
+ subspec.delete('private_header_files')
251
+ subspec.delete('vendored_frameworks')
252
+ subspec.delete('vendored_libraries')
253
+ subspec.delete('resource_bundles')
254
+ subspec.delete('resources')
255
+ subspec.delete('exclude_files')
256
+ subspec.delete('preserve_paths')
257
+ if subspec['dependencies']
258
+ subspec['dependencies']["#{code_spec.root.name}/Binary"] = []
259
+ else
260
+ subspec['dependencies'] = {"#{code_spec.root.name}/Binary": []}
261
+ end
262
+ end
263
+
264
+ # "source"字段
265
+ def binary_source
266
+ url = "#{CBin.config.binary_download_url_str}/#{code_spec.root.module_name}/#{code_spec.version}/#{code_spec.root.module_name}.framework_#{code_spec.version}.zip"
267
+ { http: url, type: CBin.config.download_file_type }
268
+ end
269
+
270
+ def code_spec_consumer(_platform = :ios)
271
+ code_spec.consumer(:ios)
272
+ end
273
+
274
+ def framework_contents(name)
275
+ # ["#{code_spec.root.name}.framework", "#{code_spec.root.name}.framework/Versions/A"].map { |path| "#{path}/#{name}" }
276
+ ["#{code_spec.module_name}.framework"]
277
+ end
278
+
279
+ def binary_source_files
280
+ "bin_#{code_spec.name}_#{code_spec.version}/Headers/*"
281
+ end
282
+
283
+ def binary_public_header_files
284
+ "bin_#{code_spec.name}_#{code_spec.version}/Headers/*.h"
285
+ end
286
+
287
+ def binary_vendored_libraries
288
+ "bin_#{code_spec.name}_#{code_spec.version}/*.a"
289
+ end
290
+
291
+ def binary_resources
292
+ "bin_#{code_spec.name}_#{code_spec.version}/Resources/*"
293
+ end
294
+
295
+ end
296
+ end
297
+ end
298
+ #模板框架begin
299
+ # s.source_files = "bin_#{s.name}_#{s.version}/Headers/*"
300
+ # s.public_header_files = "bin_#{s.name}_#{s.version}/Headers/*.h"
301
+ # s.vendored_libraries = "bin_#{s.name}_#{s.version}/*.a"
302
+ #有图片资源的,要带上
303
+ #s.resources = 'bin_#{s.name}_#{s.version}/Resources/*.{json,png,jpg,gif,js,xib,eot,svg,ttf,woff,db,sqlite,mp3,bundle}'
304
+ #模板框架end