創(chuàng)建本地私有庫
1 創(chuàng)建空目錄
$ mkdir FFTest
$ cd FFTest
2 創(chuàng)建子工程
$ pod lib create FFTest
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- https://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and click links to open in a browser. )
// 組件平臺(tái),輸入iOS
What platform do you want to use?? [ iOS / macOS ]
> iOS
// 組件語言,輸入ObjC
What language do you want to use?? [ Swift / ObjC ]
> ObjC
// 是否包含一個(gè)Demo程序,輸入Yes
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
// 測(cè)試框架,輸入Kiwi
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> Kiwi
// 是否包含界面測(cè)試,輸入Yes
Would you like to do view based testing? [ Yes / No ]
> Yes
// 類名前綴,這里輸入FF
What is your class prefix?
> FF
3 之后等待CocoaPods建立demo工程,最后CocoaPod會(huì)幫你打開Xcode,這時(shí)候我們先關(guān)掉,因?yàn)檫@個(gè)demo工程幫助我們建立了git文件,這里會(huì)跟一會(huì)需要clone到本地的git倉庫沖突至耻,需要先刪除 .git 文件夾。
4 打開項(xiàng)目選中podspec后綴名的文件镊叁,去掉注釋保留以下內(nèi)容
Pod::Spec.new do |s|
# 項(xiàng)目名
s.name = 'FFTest'
# 版本號(hào)
s.version = '0.1.0'
# 簡單描述
s.summary = 'A short description of FFTest.'
# 詳細(xì)描述
s.description = ''
# 項(xiàng)目的主頁
s.homepage = 'https://github.com/******/FFTest'
# 項(xiàng)目遵守的協(xié)議
s.license = { :type => 'MIT', :file => 'LICENSE' }
# 作者的郵箱
s.author = { '郵箱' => '***' }
# git倉庫地址
s.source = { :git => 'https://github.com/******/FFTest.git', :tag => s.version.to_s }
# 項(xiàng)目的最低版本支持
s.ios.deployment_target = '8.0'
# 表示源文件的路徑尘颓,這個(gè)路徑是相對(duì)podspec文件而言的。
s.source_files = 'FFTest/Classes/**/*'
end
首先修改s.source晦譬,把:git中的地址改為你新建git倉庫的地址疤苹,例如這樣:
s.source = { :git => 'https://github.com/******/FFTest.git', :tag => s.version.to_s }
s.source_files是組件中的源代碼,可以指定為一個(gè)目錄敛腌、或者數(shù)組表示多個(gè)目錄卧土、或者指定文件:
# 多個(gè)目錄
s.source_files = 'FFTest/Classes/*.{h,m}', 'FFTest/UI/*.{h,m}'
# Classes以及的Classes的子文件夾下的所有文件
s.source_files = 'FFTest/Classes/**/*'
# 只是Classes目錄
s.source_files = 'FFTest/Classes/*'
感興趣的同學(xué)可以去cocopods關(guān)于podspec的介紹 進(jìn)一步了解
5 在Example文件夾下執(zhí)行命令pod install就可以了,這樣這個(gè)Demo組件工程的準(zhǔn)備工作就結(jié)束了
6 項(xiàng)目結(jié)構(gòu)
Example:demo項(xiàng)目工程像樊,用來編寫和測(cè)試子工程
FFTest:子工程尤莺,給宿主工程用
創(chuàng)建遠(yuǎn)程私有庫
1 驗(yàn)證本地podspec文件
$ pod lib lint --allow-warnings
如果有error 就得先解決error
2 本地校驗(yàn)成功后,推送至遠(yuǎn)端
$ git remote add origin git@******/FFTest.git
$ git pull origin master
3 打tag
$ git tag -m '0.1.0標(biāo)簽' -a 0.1.0
$ git push --tags
tag要和podspec文件里面的s.version對(duì)應(yīng)起來生棍。
4 驗(yàn)證遠(yuǎn)程podspec文件
$ pod spec lint
pod lib lint和pod spec lint的區(qū)別是前者只會(huì)檢驗(yàn)本地的pod,后者是本地和遠(yuǎn)端都會(huì)檢驗(yàn)
5 創(chuàng)建本地索引
進(jìn)入~/.cocoapods/repos
目錄颤霎,創(chuàng)建自己私有的Spec Repo
$ pod repo add FFSpecs git@github.com:******/FFSpec.git
6 推送至索引庫
遠(yuǎn)端和本地都校驗(yàn)通過后就要將FFTest.podspec推送至FFSpec倉庫中
$ pod repo push FFSpecs FFTest.podspec
7 驗(yàn)證一下
$ pod search FFTest