cocoapods-lhj-bin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +11 -0
- data/lib/cocoapods-lhj-bin.rb +2 -0
- data/lib/cocoapods-lhj-bin/command.rb +1 -0
- data/lib/cocoapods-lhj-bin/command/bin.rb +59 -0
- data/lib/cocoapods-lhj-bin/command/bin/archive.rb +233 -0
- data/lib/cocoapods-lhj-bin/command/bin/auto.rb +198 -0
- data/lib/cocoapods-lhj-bin/command/bin/code.rb +232 -0
- data/lib/cocoapods-lhj-bin/command/bin/dup.rb +78 -0
- data/lib/cocoapods-lhj-bin/command/bin/init.rb +69 -0
- data/lib/cocoapods-lhj-bin/command/bin/initHotKey.rb +70 -0
- data/lib/cocoapods-lhj-bin/command/bin/install.rb +44 -0
- data/lib/cocoapods-lhj-bin/command/bin/lhj.rb +46 -0
- data/lib/cocoapods-lhj-bin/command/bin/lib/lint.rb +69 -0
- data/lib/cocoapods-lhj-bin/command/bin/repo/update.rb +43 -0
- data/lib/cocoapods-lhj-bin/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-lhj-bin/command/bin/spec/push.rb +115 -0
- data/lib/cocoapods-lhj-bin/command/bin/update.rb +153 -0
- data/lib/cocoapods-lhj-bin/config/config.rb +137 -0
- data/lib/cocoapods-lhj-bin/config/config_asker.rb +57 -0
- data/lib/cocoapods-lhj-bin/config/config_builder.rb +216 -0
- data/lib/cocoapods-lhj-bin/config/config_hot_key.rb +103 -0
- data/lib/cocoapods-lhj-bin/config/config_hot_key_asker.rb +57 -0
- data/lib/cocoapods-lhj-bin/gem_version.rb +9 -0
- data/lib/cocoapods-lhj-bin/helpers.rb +5 -0
- data/lib/cocoapods-lhj-bin/helpers/Info.plist +0 -0
- data/lib/cocoapods-lhj-bin/helpers/build_helper.rb +158 -0
- data/lib/cocoapods-lhj-bin/helpers/build_utils.rb +93 -0
- data/lib/cocoapods-lhj-bin/helpers/framework.rb +85 -0
- data/lib/cocoapods-lhj-bin/helpers/framework_builder.rb +444 -0
- data/lib/cocoapods-lhj-bin/helpers/library.rb +54 -0
- data/lib/cocoapods-lhj-bin/helpers/library_builder.rb +90 -0
- data/lib/cocoapods-lhj-bin/helpers/sources_helper.rb +36 -0
- data/lib/cocoapods-lhj-bin/helpers/spec_creator.rb +168 -0
- data/lib/cocoapods-lhj-bin/helpers/spec_files_helper.rb +75 -0
- data/lib/cocoapods-lhj-bin/helpers/spec_source_creator.rb +227 -0
- data/lib/cocoapods-lhj-bin/helpers/upload_helper.rb +87 -0
- data/lib/cocoapods-lhj-bin/native.rb +19 -0
- data/lib/cocoapods-lhj-bin/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-lhj-bin/native/analyzer.rb +55 -0
- data/lib/cocoapods-lhj-bin/native/file_accessor.rb +28 -0
- data/lib/cocoapods-lhj-bin/native/installation_options.rb +25 -0
- data/lib/cocoapods-lhj-bin/native/installer.rb +135 -0
- data/lib/cocoapods-lhj-bin/native/linter.rb +26 -0
- data/lib/cocoapods-lhj-bin/native/path_source.rb +33 -0
- data/lib/cocoapods-lhj-bin/native/pod_source_installer.rb +19 -0
- data/lib/cocoapods-lhj-bin/native/pod_target_installer.rb +94 -0
- data/lib/cocoapods-lhj-bin/native/podfile.rb +91 -0
- data/lib/cocoapods-lhj-bin/native/podfile_env.rb +37 -0
- data/lib/cocoapods-lhj-bin/native/podfile_generator.rb +199 -0
- data/lib/cocoapods-lhj-bin/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-lhj-bin/native/resolver.rb +230 -0
- data/lib/cocoapods-lhj-bin/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-lhj-bin/native/source.rb +35 -0
- data/lib/cocoapods-lhj-bin/native/sources_manager.rb +20 -0
- data/lib/cocoapods-lhj-bin/native/specification.rb +31 -0
- data/lib/cocoapods-lhj-bin/native/target_validator.rb +41 -0
- data/lib/cocoapods-lhj-bin/native/validator.rb +40 -0
- data/lib/cocoapods-lhj-bin/source_provider_hook.rb +66 -0
- data/lib/cocoapods_plugin.rb +2 -0
- data/spec/command/bin_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +177 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
module CBin
|
4
|
+
class Library
|
5
|
+
attr_reader :headers_path
|
6
|
+
attr_reader :resources_path
|
7
|
+
attr_reader :root_path
|
8
|
+
attr_reader :versions_path
|
9
|
+
attr_reader :name_path
|
10
|
+
|
11
|
+
def initialize(name, platform, version)
|
12
|
+
@name = name
|
13
|
+
@platform = platform
|
14
|
+
@version = version
|
15
|
+
end
|
16
|
+
|
17
|
+
def make
|
18
|
+
make_root
|
19
|
+
make_library
|
20
|
+
make_headers
|
21
|
+
make_resources
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_resources
|
25
|
+
Pathname.new(@resources_path).rmtree
|
26
|
+
(Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def make_library
|
32
|
+
@name_path = CBin::Config::Builder.instance.library_name_version(@name,@version)
|
33
|
+
@fwk_path = @root_path + Pathname.new(@name_path)
|
34
|
+
@fwk_path.mkdir unless @fwk_path.exist?
|
35
|
+
|
36
|
+
@versions_path = @fwk_path
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_headers
|
40
|
+
@headers_path = @versions_path + Pathname.new('Headers')
|
41
|
+
@headers_path.mkpath unless @headers_path.exist?
|
42
|
+
end
|
43
|
+
|
44
|
+
def make_resources
|
45
|
+
@resources_path = @versions_path + Pathname.new('Resources')
|
46
|
+
@resources_path.mkpath unless @resources_path.exist?
|
47
|
+
end
|
48
|
+
|
49
|
+
def make_root
|
50
|
+
@root_path = Pathname.new(@platform)
|
51
|
+
@root_path.mkpath unless @root_path.exist?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
3
|
+
|
4
|
+
require 'cocoapods-lhj-bin/helpers/framework.rb'
|
5
|
+
require 'cocoapods-lhj-bin/helpers/library.rb'
|
6
|
+
|
7
|
+
require 'English'
|
8
|
+
|
9
|
+
module CBin
|
10
|
+
class Library
|
11
|
+
class Builder
|
12
|
+
include Pod
|
13
|
+
|
14
|
+
def initialize(spec, file_accessor, platform, source_dir,framework_path)
|
15
|
+
@spec = spec
|
16
|
+
@source_dir = source_dir
|
17
|
+
@file_accessor = file_accessor
|
18
|
+
@platform = platform
|
19
|
+
@framework = framework_path
|
20
|
+
@source_files = "#{@source_dir}/#{library.name_path}"
|
21
|
+
@source_zip_file = "#{@source_files}.zip"
|
22
|
+
end
|
23
|
+
|
24
|
+
def build
|
25
|
+
UI.section("Building static library #{@spec}") do
|
26
|
+
|
27
|
+
clean_source_dir
|
28
|
+
|
29
|
+
copy_headers
|
30
|
+
copy_library
|
31
|
+
copy_resources
|
32
|
+
|
33
|
+
cp_to_source_dir
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def clean_source_dir
|
40
|
+
FileUtils.rm_rf(@source_files) if File.exist?(@source_files)
|
41
|
+
FileUtils.rm_rf(@source_zip_file) if File.exist?(@source_zip_file)
|
42
|
+
end
|
43
|
+
|
44
|
+
def cp_to_source_dir
|
45
|
+
target_dir = library.versions_path
|
46
|
+
dest_file = "#{@source_dir}/#{library.name_path}"
|
47
|
+
FileUtils.rm_rf(dest_file) if File.exist?(dest_file)
|
48
|
+
|
49
|
+
`cp -fa #{target_dir} #{dest_file}/`
|
50
|
+
end
|
51
|
+
|
52
|
+
def copy_headers
|
53
|
+
FileUtils.cp_r(framework.headers_path,library.versions_path) if File.exist?(framework.headers_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def copy_library
|
57
|
+
src_file = "#{framework.versions_path}/#{@spec.name}"
|
58
|
+
unless File.exist?(src_file)
|
59
|
+
raise Informative, "framework没有文件:#{src_file}"
|
60
|
+
end
|
61
|
+
|
62
|
+
dest_file = "#{library.versions_path}/#{@spec.name}"
|
63
|
+
rename_dest_file = "#{library.versions_path}/lib#{@spec.name}.a"
|
64
|
+
FileUtils.cp_r(src_file,dest_file)
|
65
|
+
File.rename(dest_file, rename_dest_file ) if File.exist?(dest_file)
|
66
|
+
end
|
67
|
+
|
68
|
+
def copy_resources
|
69
|
+
FileUtils.cp_r(framework.resources_path,library.versions_path) if File.exist?(framework.resources_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def framework
|
74
|
+
@framework ||= begin
|
75
|
+
framework = Framework.new(@spec.name, @platform.name.to_s)
|
76
|
+
framework.make
|
77
|
+
framework
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def library
|
82
|
+
@library ||= begin
|
83
|
+
library = Library.new(@spec.name, @platform.name.to_s,@spec.version)
|
84
|
+
library.make
|
85
|
+
library
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'cocoapods-lhj-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
|
16
|
+
sources_manager.code_source
|
17
|
+
end
|
18
|
+
|
19
|
+
# 优先采用对应依赖的 source
|
20
|
+
# cocoapods 内部会先匹配前面符合的 specification
|
21
|
+
# 只允许二进制的 specification subspec 比源码的 specification subspec 多
|
22
|
+
#
|
23
|
+
def valid_sources(code_dependencies = false)
|
24
|
+
sources = [code_source]
|
25
|
+
unless code_dependencies
|
26
|
+
sources << binary_source
|
27
|
+
sources.reverse!
|
28
|
+
end
|
29
|
+
sources
|
30
|
+
end
|
31
|
+
|
32
|
+
def sources_option(code_dependencies, additional_sources)
|
33
|
+
(valid_sources(code_dependencies).map(&:url) + Array(additional_sources)).join(',')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'cocoapods'
|
2
|
+
require 'cocoapods-lhj-bin/config/config'
|
3
|
+
|
4
|
+
module CBin
|
5
|
+
class Specification
|
6
|
+
class Creator
|
7
|
+
attr_reader :code_spec
|
8
|
+
attr_reader :template_spec
|
9
|
+
attr_reader :spec
|
10
|
+
|
11
|
+
def initialize(code_spec, template_spec, platforms = 'ios')
|
12
|
+
@code_spec = code_spec
|
13
|
+
@template_spec = template_spec
|
14
|
+
@platforms = Array(platforms)
|
15
|
+
validate!
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate!
|
19
|
+
raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
|
20
|
+
if code_spec.subspecs.any? && template_spec.nil?
|
21
|
+
raise Pod::Informative, "不支持自动生成存在 subspec 的二进制 podspec , 需要提供模版文件 #{code_spec.name}.binary.podspec.template ."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def create
|
26
|
+
spec = template_spec ? create_from_code_spec_and_template_spec : create_from_code_spec
|
27
|
+
|
28
|
+
Pod::UI.message '生成二进制 podspec 内容: '
|
29
|
+
spec.to_pretty_json.split("\n").each do |text|
|
30
|
+
Pod::UI.message text
|
31
|
+
end
|
32
|
+
|
33
|
+
spec
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_spec_file(file = filename)
|
37
|
+
create unless spec
|
38
|
+
|
39
|
+
File.open(file, 'w+') do |f|
|
40
|
+
f.write(spec.to_pretty_json)
|
41
|
+
end
|
42
|
+
|
43
|
+
@filename = file
|
44
|
+
end
|
45
|
+
|
46
|
+
def clear_spec_file
|
47
|
+
File.delete(filename) if File.exist?(filename)
|
48
|
+
end
|
49
|
+
|
50
|
+
def filename
|
51
|
+
@filename ||= "#{spec.name}.binary.podspec.json"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def create_from_code_spec
|
57
|
+
@spec = code_spec.dup
|
58
|
+
# vendored_frameworks | resources | source | source_files | public_header_files
|
59
|
+
# license | resource_bundles | vendored_libraries
|
60
|
+
|
61
|
+
# Project Linkin
|
62
|
+
@spec.vendored_frameworks = "#{code_spec.root.name}.framework"
|
63
|
+
|
64
|
+
# Resources
|
65
|
+
extnames = []
|
66
|
+
extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
|
67
|
+
if code_spec_consumer.resources.any?
|
68
|
+
extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
|
69
|
+
end
|
70
|
+
if extnames.any?
|
71
|
+
@spec.resources = framework_contents('Resources').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
|
72
|
+
end
|
73
|
+
|
74
|
+
# Source Location
|
75
|
+
@spec.source = binary_source
|
76
|
+
|
77
|
+
# Source Code
|
78
|
+
@spec.source_files = framework_contents('Headers/*')
|
79
|
+
@spec.public_header_files = framework_contents('Headers/*')
|
80
|
+
|
81
|
+
# Unused for binary
|
82
|
+
spec_hash = @spec.to_hash
|
83
|
+
# spec_hash.delete('license')
|
84
|
+
spec_hash.delete('resource_bundles')
|
85
|
+
spec_hash.delete('exclude_files')
|
86
|
+
spec_hash.delete('preserve_paths')
|
87
|
+
# 这里不确定 vendored_libraries 指定的时动态/静态库
|
88
|
+
# 如果是静态库的话,需要移除,否则就不移除
|
89
|
+
# 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
|
90
|
+
# 这里统一只对命名后缀 .a 文件做处理
|
91
|
+
# spec_hash.delete('vendored_libraries')
|
92
|
+
# libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
|
93
|
+
spec_hash.delete('vendored_libraries')
|
94
|
+
spec_hash['vendored_libraries'] = binary_vendored_libraries
|
95
|
+
|
96
|
+
# vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
|
97
|
+
# if vendored_libraries.any?
|
98
|
+
# spec_hash['vendored_libraries'] = vendored_libraries
|
99
|
+
# end
|
100
|
+
|
101
|
+
# Filter platforms
|
102
|
+
platforms = spec_hash['platforms']
|
103
|
+
selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
|
104
|
+
spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
|
105
|
+
|
106
|
+
@spec = Pod::Specification.from_hash(spec_hash)
|
107
|
+
@spec
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_from_code_spec_and_template_spec
|
111
|
+
@spec = template_spec.dup
|
112
|
+
|
113
|
+
@spec.version = code_spec.version
|
114
|
+
@spec.source = binary_source
|
115
|
+
|
116
|
+
@spec.source_files = binary_source_files
|
117
|
+
@spec.public_header_files = binary_public_header_files
|
118
|
+
@spec.vendored_libraries = binary_vendored_libraries
|
119
|
+
|
120
|
+
@spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources")
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
@spec
|
125
|
+
end
|
126
|
+
|
127
|
+
def binary_source
|
128
|
+
{ http: format(CBin.config.binary_download_url, code_spec.root.name, code_spec.version), type: CBin.config.download_file_type }
|
129
|
+
end
|
130
|
+
|
131
|
+
def code_spec_consumer(_platform = :ios)
|
132
|
+
code_spec.consumer(:ios)
|
133
|
+
end
|
134
|
+
|
135
|
+
def framework_contents(name)
|
136
|
+
["#{code_spec.root.name}.framework", "#{code_spec.root.name}.framework/Versions/A"].map { |path| "#{path}/#{name}" }
|
137
|
+
end
|
138
|
+
|
139
|
+
def binary_source_files
|
140
|
+
{ http: format(CBin.config.binary_download_url, code_spec.root.name, code_spec.version), type: CBin.config.download_file_type }
|
141
|
+
end
|
142
|
+
|
143
|
+
def binary_source_files
|
144
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*"
|
145
|
+
end
|
146
|
+
|
147
|
+
def binary_public_header_files
|
148
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*.h"
|
149
|
+
end
|
150
|
+
|
151
|
+
def binary_vendored_libraries
|
152
|
+
"bin_#{code_spec.name}_#{code_spec.version}/*.a"
|
153
|
+
end
|
154
|
+
|
155
|
+
def binary_resources
|
156
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Resources/*"
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
#模板框架begin
|
163
|
+
# s.source_files = "bin_#{s.name}_#{s.version}/Headers/*"
|
164
|
+
# s.public_header_files = "bin_#{s.name}_#{s.version}/Headers/*.h"
|
165
|
+
# s.vendored_libraries = "bin_#{s.name}_#{s.version}/*.a"
|
166
|
+
#有图片资源的,要带上
|
167
|
+
#s.resources = 'bin_#{s.name}_#{s.version}/Resources/*.{json,png,jpg,gif,js,xib,eot,svg,ttf,woff,db,sqlite,mp3,bundle}'
|
168
|
+
#模板框架end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'cocoapods-lhj-bin/native/sources_manager'
|
2
|
+
require 'cocoapods-lhj-bin/helpers/spec_creator'
|
3
|
+
|
4
|
+
module CBin
|
5
|
+
module SpecFilesHelper
|
6
|
+
def spec_files
|
7
|
+
@spec_files ||= Pathname.glob('*.podspec{,.json}')
|
8
|
+
end
|
9
|
+
|
10
|
+
def binary_spec_files
|
11
|
+
@binary_spec_files ||= Pathname.glob('*.binary.podspec{,.json}')
|
12
|
+
end
|
13
|
+
|
14
|
+
def binary_template_spec_files
|
15
|
+
@binary_spec_template_files ||= Pathname.glob('*.binary-template.podspec{,.json}')
|
16
|
+
end
|
17
|
+
|
18
|
+
def binary_template_spec_file
|
19
|
+
@binary_spec_template_file ||= binary_template_spec_files.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def code_spec_files
|
23
|
+
@code_spec_files ||= spec_files - binary_spec_files - binary_template_spec_files
|
24
|
+
end
|
25
|
+
|
26
|
+
def code_spec
|
27
|
+
if code_spec_files.first
|
28
|
+
Pod::Specification.from_file(code_spec_files.first)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def binary_spec
|
33
|
+
if binary_spec_files.first
|
34
|
+
Pod::Specification.from_file(binary_spec_files.first)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def binary_template_spec
|
39
|
+
if binary_template_spec_file
|
40
|
+
Pod::Specification.from_file(binary_template_spec_file)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_spec_file(podspec)
|
45
|
+
path = Pathname(podspec)
|
46
|
+
raise Pod::Informative, "无法找到 #{podspec}" unless path.exist?
|
47
|
+
|
48
|
+
path
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_binary_spec_file(code_spec, template_spec)
|
52
|
+
# 1. code spec 是否有 subpsec
|
53
|
+
# 1.1 有,查找 template spec,并生成
|
54
|
+
# 1.2 没有,是否有 template spec
|
55
|
+
# 1.2.1 有,根据 template spec 生成
|
56
|
+
# 1.2.2 没有,根据 code spec 生成
|
57
|
+
|
58
|
+
unless code_spec
|
59
|
+
raise Pod::Informative, '没有二进制 podspec 的情况下,必须要提供源码 podspec.'
|
60
|
+
end
|
61
|
+
if code_spec.subspecs.any? && template_spec.nil?
|
62
|
+
raise Pod::Informative, '拥有 subspec 的组件,在生成二进制 podspec 时,必须要提供模版 podspec.'
|
63
|
+
end
|
64
|
+
|
65
|
+
@spec_creator = CBin::Specification::Creator.new(code_spec, template_spec)
|
66
|
+
@spec_creator.create
|
67
|
+
@spec_creator.write_spec_file
|
68
|
+
@spec_creator.filename
|
69
|
+
end
|
70
|
+
|
71
|
+
def clear_binary_spec_file_if_needed
|
72
|
+
@spec_creator&.clear_spec_file
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'cocoapods'
|
4
|
+
require 'cocoapods-lhj-bin/config/config'
|
5
|
+
|
6
|
+
module CBin
|
7
|
+
class SpecificationSource
|
8
|
+
class Creator
|
9
|
+
attr_reader :code_spec
|
10
|
+
attr_reader :spec
|
11
|
+
|
12
|
+
def initialize(code_spec, platforms = 'ios')
|
13
|
+
@code_spec = code_spec
|
14
|
+
@platforms = Array(platforms)
|
15
|
+
validate!
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate!
|
19
|
+
raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
# spec = nil
|
24
|
+
if CBin::Build::Utils.is_framework(@code_spec)
|
25
|
+
spec = create_framework_from_code_spec
|
26
|
+
else
|
27
|
+
spec = create_from_code_spec
|
28
|
+
end
|
29
|
+
|
30
|
+
spec
|
31
|
+
end
|
32
|
+
|
33
|
+
def write_spec_file(file = filename)
|
34
|
+
create unless spec
|
35
|
+
|
36
|
+
FileUtils.mkdir_p(CBin::Config::Builder.instance.binary_json_dir) unless File.exist?(CBin::Config::Builder.instance.binary_json_dir)
|
37
|
+
FileUtils.rm_rf(file) if File.exist?(file)
|
38
|
+
|
39
|
+
File.open(file, 'w+') do |f|
|
40
|
+
f.write(spec.to_pretty_json)
|
41
|
+
end
|
42
|
+
|
43
|
+
@filename = file
|
44
|
+
end
|
45
|
+
|
46
|
+
def clear_spec_file
|
47
|
+
File.delete(filename) if File.exist?(filename)
|
48
|
+
end
|
49
|
+
|
50
|
+
def filename
|
51
|
+
@filename ||= "#{CBin::Config::Builder.instance.binary_json_dir_name}/#{spec.name}.binary.podspec.json"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def create_from_code_spec
|
57
|
+
@spec = code_spec.dup
|
58
|
+
# vendored_frameworks | resources | source | source_files | public_header_files
|
59
|
+
# license | resource_bundles | vendored_libraries
|
60
|
+
|
61
|
+
# Project Linkin
|
62
|
+
# @spec.vendored_frameworks = "#{code_spec.root.name}.framework"
|
63
|
+
|
64
|
+
# Resources
|
65
|
+
extnames = []
|
66
|
+
extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
|
67
|
+
if code_spec_consumer.resources.any?
|
68
|
+
extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
|
69
|
+
end
|
70
|
+
if extnames.any?
|
71
|
+
@spec.resources = framework_contents('Resources').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
|
72
|
+
end
|
73
|
+
|
74
|
+
# Source Location
|
75
|
+
@spec.source = binary_source
|
76
|
+
|
77
|
+
# Source Code
|
78
|
+
# @spec.source_files = framework_contents('Headers/*')
|
79
|
+
# @spec.public_header_files = framework_contents('Headers/*')
|
80
|
+
|
81
|
+
# Unused for binary
|
82
|
+
spec_hash = @spec.to_hash
|
83
|
+
# spec_hash.delete('license')
|
84
|
+
spec_hash.delete('resource_bundles')
|
85
|
+
spec_hash.delete('exclude_files')
|
86
|
+
spec_hash.delete('preserve_paths')
|
87
|
+
|
88
|
+
spec_hash.delete('subspecs')
|
89
|
+
spec_hash.delete('default_subspecs')
|
90
|
+
spec_hash.delete('default_subspec')
|
91
|
+
spec_hash.delete('vendored_frameworks')
|
92
|
+
spec_hash.delete('vendored_framework')
|
93
|
+
|
94
|
+
# 这里不确定 vendored_libraries 指定的时动态/静态库
|
95
|
+
# 如果是静态库的话,需要移除,否则就不移除
|
96
|
+
# 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
|
97
|
+
# 这里统一只对命名后缀 .a 文件做处理
|
98
|
+
# spec_hash.delete('vendored_libraries')
|
99
|
+
# libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
|
100
|
+
spec_hash.delete('vendored_libraries')
|
101
|
+
|
102
|
+
# vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
|
103
|
+
# if vendored_libraries.any?
|
104
|
+
# spec_hash['vendored_libraries'] = vendored_libraries
|
105
|
+
# end
|
106
|
+
|
107
|
+
# Filter platforms
|
108
|
+
platforms = spec_hash['platforms']
|
109
|
+
selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
|
110
|
+
spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
|
111
|
+
|
112
|
+
@spec = Pod::Specification.from_hash(spec_hash)
|
113
|
+
|
114
|
+
#把命令 prepare_command 移除掉,如ReactiveCocoa会执行修改重命令的脚步
|
115
|
+
@spec.prepare_command = "" if @spec.prepare_command
|
116
|
+
@spec.version = code_spec.version
|
117
|
+
@spec.source = binary_source
|
118
|
+
@spec.source_files = binary_source_files
|
119
|
+
@spec.public_header_files = binary_public_header_files
|
120
|
+
@spec.vendored_libraries = binary_vendored_libraries
|
121
|
+
@spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources")
|
122
|
+
@spec.description = <<-EOF
|
123
|
+
「 converted automatically by plugin cocoapods-lhj-bin 」
|
124
|
+
#{@spec.description}
|
125
|
+
EOF
|
126
|
+
@spec
|
127
|
+
end
|
128
|
+
|
129
|
+
def create_framework_from_code_spec
|
130
|
+
@spec = code_spec.dup
|
131
|
+
# vendored_frameworks | resources | source | source_files | public_header_files
|
132
|
+
# license | resource_bundles | vendored_libraries
|
133
|
+
|
134
|
+
# Project Linkin
|
135
|
+
@spec.vendored_frameworks = "#{code_spec.root.name}.framework"
|
136
|
+
|
137
|
+
# Resources
|
138
|
+
extnames = []
|
139
|
+
extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
|
140
|
+
if code_spec_consumer.resources.any?
|
141
|
+
extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
|
142
|
+
end
|
143
|
+
if extnames.any?
|
144
|
+
@spec.resources = framework_contents('Resources').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
|
145
|
+
end
|
146
|
+
|
147
|
+
# Source Location
|
148
|
+
@spec.source = binary_source
|
149
|
+
|
150
|
+
# Source Code
|
151
|
+
# @spec.source_files = framework_contents('Headers/*')
|
152
|
+
# @spec.public_header_files = framework_contents('Headers/*')
|
153
|
+
|
154
|
+
# Unused for binary
|
155
|
+
spec_hash = @spec.to_hash
|
156
|
+
# spec_hash.delete('license')
|
157
|
+
spec_hash.delete('resource_bundles')
|
158
|
+
spec_hash.delete('exclude_files')
|
159
|
+
spec_hash.delete('preserve_paths')
|
160
|
+
# 这里不确定 vendored_libraries 指定的时动态/静态库
|
161
|
+
# 如果是静态库的话,需要移除,否则就不移除
|
162
|
+
# 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
|
163
|
+
# 这里统一只对命名后缀 .a 文件做处理
|
164
|
+
# spec_hash.delete('vendored_libraries')
|
165
|
+
# libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
|
166
|
+
vendored_libraries = spec_hash.delete('vendored_libraries')
|
167
|
+
vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
|
168
|
+
if vendored_libraries.any?
|
169
|
+
spec_hash['vendored_libraries'] = vendored_libraries
|
170
|
+
end
|
171
|
+
|
172
|
+
# Filter platforms
|
173
|
+
platforms = spec_hash['platforms']
|
174
|
+
selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
|
175
|
+
spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
|
176
|
+
|
177
|
+
@spec = Pod::Specification.from_hash(spec_hash)
|
178
|
+
@spec.description = <<-EOF
|
179
|
+
「 converted automatically by plugin cocoapods-lhj-bin 」
|
180
|
+
#{@spec.description}
|
181
|
+
EOF
|
182
|
+
@spec
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
def binary_source
|
187
|
+
{ http: format(CBin.config.binary_download_url, code_spec.root.name, code_spec.version), type: CBin.config.download_file_type }
|
188
|
+
end
|
189
|
+
|
190
|
+
def code_spec_consumer(_platform = :ios)
|
191
|
+
code_spec.consumer(:ios)
|
192
|
+
end
|
193
|
+
|
194
|
+
def framework_contents(name)
|
195
|
+
["#{code_spec.root.name}.framework", "#{code_spec.root.name}.framework/Versions/A"].map { |path| "#{path}/#{name}" }
|
196
|
+
end
|
197
|
+
|
198
|
+
def binary_source_files
|
199
|
+
{ http: format(CBin.config.binary_download_url, code_spec.root.name, code_spec.version), type: CBin.config.download_file_type }
|
200
|
+
end
|
201
|
+
|
202
|
+
def binary_source_files
|
203
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*"
|
204
|
+
end
|
205
|
+
|
206
|
+
def binary_public_header_files
|
207
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*.h"
|
208
|
+
end
|
209
|
+
|
210
|
+
def binary_vendored_libraries
|
211
|
+
"bin_#{code_spec.name}_#{code_spec.version}/*.a"
|
212
|
+
end
|
213
|
+
|
214
|
+
def binary_resources
|
215
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Resources/*"
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
#模板框架begin
|
222
|
+
# s.source_files = "bin_#{s.name}_#{s.version}/Headers/*"
|
223
|
+
# s.public_header_files = "bin_#{s.name}_#{s.version}/Headers/*.h"
|
224
|
+
# s.vendored_libraries = "bin_#{s.name}_#{s.version}/*.a"
|
225
|
+
#有图片资源的,要带上
|
226
|
+
#s.resources = 'bin_#{s.name}_#{s.version}/Resources/*.{json,png,jpg,gif,js,xib,eot,svg,ttf,woff,db,sqlite,mp3,bundle}'
|
227
|
+
#模板框架end
|