组织介绍

组件化项目创建:

1.远程索引库

每创建一个组件都会带有一个 xxx.podspec的索引文件。专门用来存放这些索引文件的库就叫做索引库。我们需要将这些索引文件上传到远程索引库才能保证其他的人能够拿来用。私有和开源的创建方式一样。

2.远程代码库 (代码实际存放的远程仓库)

如:https://gitee.com/component-practice/main.git

3.索引库关联本地

cd ~/.cocoapods/repos
pod repo add BYPodspecs https://gitee.com/component-practice/bypodspecs.git

输入gitee账号密码后就会在本地生成,可以git pull拉取或者push一下确保可正常提交代码

4.本地创建文件夹

在本地创建一个文件夹BYH_Components用来存放组件代码,并进入到该路径

cd ~/Desktop/BYH_Components

5.创建本地组件模板 BYHCommon

pod lib create BYHCommon

What platform do you want to use?? [ iOS / macOS ]

iOS

What language do you want to use?? [ Swift / ObjC ]

ObjC

Would you like to include a demo application with your library? [ Yes / No ]

yes

Which testing frameworks will you use? [ Specta / Kiwi / None ]

none

Would you like to do view based testing? [ Yes / No ]

no

What is your class prefix?

BY

Running pod install on your new library.
创建好后会自动打开一个工程,配置xx.podspec文件如下

Pod::Spec.new do |s|
  s.name             = 'BYHCommon'
  s.version          = '0.1.0'
  s.summary          = 'A short description of BYHCommon.'

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://gitee.com/Gary0726/lbnetwork'
  s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'LuckyBlue' => 'xxxxxxx@qq.com' }
  s.source           = { :git => 'https://gitee.com/Gary0726/lbnetwork.git', :tag => s.version.to_s }

 s.ios.deployment_target = '9.0'

  s.source_files = 'BYLogin/Classes/**/*.{h,m}'
  
  s.resource_bundles = {
    'BYLogin' => ['BYLogin/Assets/*']
  }
  
  s.public_header_files = 'BYLogin/Classes/**/**/*.h'
  
  # 子目录
#  s.subspec 'Modules' do |ss|
#      ss.source_files = 'BYLogin/Classes/Modules/Controllers/*'
#  end
  s.static_framework = true
  # s.frameworks = 'UIKit', 'MapKit'
  s.dependency 'BYHCommon'
  # 友盟分享 登录
#  s.dependency 'UMCommon'
  s.dependency 'UMShare/Social/WeChat'
  s.dependency 'YYText'
end

6.添加远端组件仓库

cd /Users/BYH_Components/BYHCommon
git remote add origin https://gitee.com/component-practice/BYHCommon.git

7.本地组件库代码提交

git push -u origin master //第一次可能会报错可尝试用 git push -u origin master -f 可能会覆盖远程的修改
git add . //记得后面一定要有 .
git commit -m "first commit"
git push -u origin master
git tag '0.1.0' //注意:这里的tag号必须和.podSpec文件的版本号一致
git push --tags

8.组件库验证

本地验证(组件中引用了私有组件,需要加上--sources,再加上--skip-import-validation)

pod lib lint BYH_SFJH.podspec --verbose --allow-warnings --skip-import-validation --sources='https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git,https://gitee.com/component-practice/bypodspecs.git'

远端验证

pod spec lint BYH_SFJH.podspec --verbose --allow-warnings --skip-import-validation --sources='https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git,https://gitee.com/component-practice/bypodspecs.git'

验证时如有遇到fatal: The remote end hung up unexpectedly那可能是网络有问题,自己起初用的github一直试都报这个错,尽管用了git config http.postBuffer 524288000
常见报错:加上 --verbose 可显示详细报错信息

9.将xxx.spec 文件提交到本地的私有仓库,然后再push到远程仓库

cd到组件目录:
pod repo push BYPodspecs BYHCommon.podspec --use-libraries --allow-warnings --skip-import-validation

BYPodspecs: ~/.cocoapods/repos/BYPodspecs
BYHCommon.podspec: 组件的podspec文件

如果报错需要查看 ~/.cocoapods/repos 中的podsec文件是否成功关联远程库,是否能push/pull远程库 查看步骤:3.索引库关联本地 是否正确

10.检查私有库是否成功

pod search BYHCommon

注:发布完成之后使用pod search组件名称却搜不到相关的信息,这个时候需要将cocoaPods的搜索缓存文件清理一下,然后重新使用pod search,就能得到最新的结果。

//进入搜索CocoaPods缓存目录
cd ~/Library/Caches/CocoaPods

 //查看缓存文件search_index.json
ls

 //删除搜索缓存文件
rm -f search_index.json

可能会用到的命令:

//删除本地tag
git tag -d 0.1.0
//删除远程tag
git push origin :refs/tags/0.1.0
//查看本地添加了哪些远程地址
git remote -v
//删除本地指定的远程地址
git remote rm origin

如果公司内部其他成员要使用需要执行下面命令,将私有的远程索引库copy到本地,然后就可以正常使用了。

pod repo add BYPodspecs https://gitee.com/component-practice/bypodspecs.git

相关报错:

参考此链接,包含所有报错:
https://www.jianshu.com/p/87d6034d3878

成就
0
Star
0
Fork
成员(1)
桐人

搜索帮助