优化cocoapods-imy-bin插件

2021-06-26  本文已影响0人  jackyshan

背景

使用二进制组件需要业务方安装插件

业务方比较多,对二进制的需求参差不齐,都要安装插件不太,侵入性太强,不利于业务方自由使用。

image

二进制打包会忽略subspec的源文件以及依赖库

忽略subspec的打包,需要手动一个个添加进去比较麻烦,这一步可以实现自动化。

image

解决

业务方不需要安装cocoapods-imy-bin插件

image

gem install cocoapods-prefer --user-install

plugin 'cocoapods-prefer'
prefer_source("xxx-spec_bin_dev","git@code.xxx.cn:gz/iOS/common/spec_bin_dev.git")

自动打包所有的subspec

@code_spec = Pod::Specification.from_file(@podspec)
@spec = code_spec.dup
spec_hash = @spec.to_hash

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

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)

@spec = Pod::Specification.from_hash(spec_hash)

image

优化的代码

https://github.com/jackyshan/cocoapods-imy-bin

参考

上一篇下一篇

猜你喜欢

热点阅读