1、首先在Git的几个平台上(GitHub、GitLee、gitlab)选一个平台创建两个远程库,一个是远程索引库,一个是远程组件代码库。这里拿GitLee为例


2、创建本地索引库
2.1、打开终端,通过命令pod repo
可以查看本地已经有哪些本地索引库

2.2、创建本地索引库并与远程索引库关联(注:本地索引库的名字建议和远程索引库起的名字一样)
通过 pod repo add 本地索引库的名字 远程索引库的地址
命令 创建本地索引库并和远程索引库做关联,例如TemplateTestSpecs是本地索引库的名字:pod repo add TemplateTestSpecs https://gitlee.com/**

索引库到这个阶段先放下,我们接着来建远程代码库
3、创建远程组件代码库
用来存放准备组件化的代码,创建的方式和远程索引库方式一样,比如我们创建一个组件库,名字叫TemplateTest
创建方式见上图创建索引库方式
4、创建本地代码库
注意这里创建本地代码库的路径是可以选择的,想创建在哪里都可以,决定之后,(cd 到该路径下)进行随后的创建操作
pod lib create TemplateTest

之后在该目录下就会创建一个工程、并且会自动打开

此时TemplateTest里面是一个replaceme的文件,我们要把我们自己整理的组件化相关的代码把那个文件替换掉,如下图

classes文件中的内容被修改之后,我们进到Example路径下进行
pod install
,然后刚才添加到classes中的文件就pod进这个工程了

5、如果到此还顺利,我们开始修改podspec文件


总结一下:
- 修改版本号(随后每次更改组件代码上传是都该更换新的版本号)
- 修改项目的简单概述和详细概述(建议)
- 修改 homepage 和 source 地址
- 添加依赖库,例如
s.dependency 'MBProgressHUD'
6、编译通过后,提交组件代码到远程代码库 并且打tag
git add .
git commit -m "描述文案"
git remote add origin $远程代码仓库地址
git push origin master (注:初次上传代码可能会报错,使用git push -f origin master 强制上传)
git tag '0.0.1' (这里的版本号要与上面的文件中一样)
git push --tags
7、验证podspec索引文件
通过pod spec lint --verbose --allow-warnings --use-libraries
命令验证 podspec 索引文件
8、提交索引文件到远程索引库
验证通过之后, pod repo push 本地索引库 索引文件名 --verbose --allow-warnings --use-libraries
提交索引文件到远程索引库。
pod repo push TemplateTestSpecs TemplateTest.podspec --verbose --allow-warnings --use-libraries
在 Finder 中可以查看是否成功

到此创建的操作完成
9、使用
使用的话和通过 cocoapods 引入第三方一样, 在需要引入改组件的工程(DemoTest)里创建并修改 Podfile。

然后
pod install
之后项目中就把这个组件pod到项目中了

网友评论