今天特別開心,終于將pod私有化組件弄會了~
前提條件:我們進行組件化開發(fā),需要使用cocospod管理,那么我們怎么將自己的代碼模塊pod上去肚菠,以供自己和別人使用?
這里我使用的是碼云托管代碼署鸡。項目名稱ModuleA
1.在碼云上創(chuàng)建遠程倉庫地址案糙,如下圖
2.然后在本地創(chuàng)建包,名為ModuleA靴庆,使用sourceTree git clone?https://gitee.com/*****/ModuleA.git
3.然后終端操作
cd 進入ModuleA文件夾下
輸入?pod spec create?ModuleA
4.你就會在ModuleA文件夾下發(fā)現(xiàn)多了一個ModuleA.podspec文件
5.打開ModuleA.podspec文件配置
這里先看一我的目錄截圖:目標(pod ?Category下的文件)
現(xiàn)在看一下ModuleA.podspec文件的配置
Pod::Spec.new do |s|
? s.name? ? ? ? = "ModuleA"
? s.version? ? ? = "0.0.1"
? s.summary? ? ? = "ModuleA 測試私用庫"
? ?s.description? = "A long description of HttpManager."
? s.homepage? ? = "https://www.baidu.com"
? ?s.license? ? ? = "MIT"
? s.source? ? ? = { :git => "https://gitee.com/******/ModuleA.git", :tag => "#{s.version}" }
? s.source_files? = "Category", "Category/**/*.{h,m}"
重要說明一下:
? s.source_files? = "Category", "Category/**/*.{h,m}" ? ?這里的"Category"和上傳的包名一致
?s.description? = "A long description of HttpManager." ? ?描述隨便寫时捌,但一定要有
?s.license? ? ? = "MIT" ?按照這樣寫就可以了
弄完之后,利用sourceTree將代碼push到碼云上去
接下來就是驗證了
podfile 書寫
platform :ios ,'9.0'
target'Test'do
pod'AFNetworking'
pod 'ModuleA', :git => 'https://gitee.com/******/ModuleA.git'
end
然后pod install就OK了
這里說明一下炉抒,如果你建的ModuleA是私有的
以上是私有組件奢讨,別人pod install 需要你的碼云的姓名和密碼,當然使用 pod search 'ModuleA'是無法訪問到的焰薄,那么我們要是想公開自己的組件代碼該如何做呢拿诸?(這里有很多的雷)
1.首先,緊接在昨天的基礎(chǔ)上做改動塞茅,昨天我將組件化代碼放在碼云上亩码,并且這個庫是私有的,接著我在github上新建了了一個ZJModuleB的庫地址野瘦,這里全程用終端去操作具體指令如下:
git clone?https://github.com/successflowers/ZJModuleB.git
cd ZJModuleB
pod spec create?ZJModuleB
配置ZJModuleB.podspec文件
Pod::Spec.new do |s|
? s.name? ? ? ? = "ZJModuleB"
? s.version? ? ? = "1.0"
? s.summary? ? ? = "xxxxx"
s.description? = <<-DESC
? ? ? ? ? ? ? ? ? ? rqwerqwefqewfwfgqwdgfqwegewgrgeeergqeregqergee
?? ? ? ? ? ? ? ? ? DESC
? s.homepage? ? = "https://github.com/successflowers/ZJModuleB.git"
? s.license? ? ? = "MIT"
? s.author? ? ? ? ? ? = { "張敬" => "success_flower@sina.com" }
? # s.platform? ? = :ios
?? s.ios.deployment_target = "9.0"
? s.source_files? = "Classes", "Classes/**/*.{h,m}"
? s.exclude_files = "Classes/Exclude"
發(fā)布公開的庫描沟,需要注冊trunk
具體指令如下
$pod trunk register [Your-Email]'[Your-Name]'--description='[Your-Desc]'
> [Your-Email]: 任意郵件,但是我比較推薦你使用github上的Email
> [Your-Name]: 推薦使用github上使用的Name
> [Your-Desc]: 一個簡單的描述鞭光,往往這個時候我們使用的是自己電腦的一個描述
比如我的
$pod trunk register 1579589762@qq.com "yetongxue" --description= "這是一個測試"
如果發(fā)送成功
你就去郵箱點擊鏈接
然后 $pod trunk me?
輸出如下表示注冊成功
繼續(xù)輸入指令
// 添加所有文件
$ git add .
?// 提交
$git commit -m"Initial AKExtension"
// push到你的遠程倉庫
$ git push
// 接下來就是需要使用到的一個Tag吏廉,這個在你的.podspec中需要配置
$git tag -m"Initial Tag"0.0.1
// 將tag添加至你的遠程倉庫
$ git push --tags
// 進入到.podspec所在目錄
$ pod spec lint
// 如果出現(xiàn)錯誤,需要修改到提示無誤后方可執(zhí)行下一步
$ pod trunk push [NAME].podspec
如果出現(xiàn)惰许,代表成功
??? Congrats
???? ZJModuleB (1.0) successfully published
???? January 9th, 20:55
???? https://cocoapods.org/pods/ZJModuleB
???? Tell your friends!
// 先更新一下repo$ pod repo update
// 查找一下你提交的pod
$pod search'ZJModuleB'
剛提交后項目用pod search命令會搜不到席覆,因為本地的索引沒有更新,使用下面命令刪除索引文件
rm ~/Library/Caches/CocoaPods/search_index.json
-> ZJModuleB (1.0)
?? xxxxx
?? pod 'ZJModuleB', '~> 1.0'
?? - Homepage:https://github.com/successflowers/ZJModuleB.git
?? - Source:? https://github.com/successflowers/ZJModuleB.git
?? - Versions: 1.0 [master repo]
最后汹买,筆者文筆粗糙佩伤,思想深度比較淺聊倔,莫見笑,有問題可留言探討畦戒,我會第一時間回復(fù)
~