背景
使用二進制組件需要業(yè)務方安裝插件
業(yè)務方比較多,對二進制的需求參差不齊,都要安裝插件不太,侵入性太強,不利于業(yè)務方自由使用。
image
二進制打包會忽略subspec的源文件以及依賴庫
忽略subspec的打包,需要手動一個個添加進去比較麻煩,這一步可以實現(xiàn)自動化。
image
解決
業(yè)務方不需要安裝cocoapods-imy-bin插件
- 修改插件,對生成bin私有庫的文件重命名,去除binary字段,實現(xiàn)能夠原生pod解析。
image
- 安裝cocoapods-prefer插件
gem install cocoapods-prefer --user-install
- 編輯podfile添加二進制source,優(yōu)先使用二進制source源。
plugin 'cocoapods-prefer'
prefer_source("xxx-spec_bin_dev","git@code.xxx.cn:gz/iOS/common/spec_bin_dev.git")
自動打包所有的subspec
- 解析Specification,生成hashmap
@code_spec = Pod::Specification.from_file(@podspec)
@spec = code_spec.dup
spec_hash = @spec.to_hash
- 取出subspecs,遍歷subspec的依賴,集合到最上層
dps_hash = Hash[]
subdps = subspecs.each do |sub|
sub.delete('exclude_files')
dps_hash = dps_hash.merge(Hash(sub['dependencies']))
end
dps_hash = dps_hash.reject { |key, value| key.include?(spec_hash['name'])}
spec_hash['dependencies'] = dps_hash
- 遍歷subspec的name,集合到新的default_subspecs
subnames = subspecs.map { |sub| sub['name']}
spec_hash['default_subspecs'] = 'xxxBin'
bin = Hash["name" => 'InkeBin']
dependencies = Hash[]
subnames.each { |name|
dependencies["#{spec_hash['name']}/#{name}"] = Array.new
}
bin['dependencies'] = dependencies
subspecs.insert(0, bin)
- 把hashmap轉換成Specification
@spec = Pod::Specification.from_hash(spec_hash)
- 修改插件,添加轉換Specification的代碼,編譯gem,測試成功打包subspecs
image
優(yōu)化的代碼
https://github.com/jackyshan/cocoapods-imy-bin