我们先在第 一 点讲一下基于github创建库。第 二 点讲一下怎么用。最后在第三点说一下在公司内部gitlab创建私有库的不同的地方。
一、以github为远程仓库创建。
1.在github创建项目JSKlineChart
2.clone远程到本地
cd ~/Desktop
git clone https://github.com/zzyyd6316/JSKlineChart.git
3.查看一下当前有哪些本地索引库
pod repo
4.创建本地索引库并和远程索引库做关联
pod repo add JSKlineChart https://github.com/zzyyd6316/JSKlineChart.git
5.再次查看pod repo。多了一个索引。路径为:
~/.cocoapods/repos/
6.在桌面随便建一个Test文件夹,创建本地代码组件模版库,组建名可以和远程代码库一致
cd /Users/zzy/Desktop/Test
pod lib create JSKlineChart
7.回答问题:
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?
> FF
你会发现自动生成了一个项目。如下。

上图中可以看到,里面有一个Example文件夹,作为例子使用,可以在本地导入库使用。这篇文章就不讲解它,可以去网上搜搜。。。你也可以把它删了。
8.删除ReplaceMe.m文件,接着把自己封装好的组件化代码的文件夹拖入到classes路径下。

9.编辑JSKlineChart.podspec文件,下图红色标记的地方需要修改

10.把Test/JSKlineChart文件夹下面的除去 .git 文件夹外的所有文件拷贝到/Users/zzy/Desktop/JSKlineChart,提交到远程代码库并打tag.
cd /Users/zzy/Desktop/JSKlineChart
git add .
git commit -m "initpod"
git remote add origin https://github.com/zzyyd6316/JSKlineChart.git
git push origin master
git tag "0.1.0"
git tag (查看版本号是否提交成功)
git push --tags
~~注意:一定要提交tag,一定要提交tag。不然会报" warning: Could not find remote branch 0.1.0 to clone.
fatal: Remote branch 0.1.0 not found in upstream origin "的错误。我这里是把整个所有的文件提交到了远程仓库,如下

11.通过pod spec lint --allow-warnings 命令验证podspec索引文件(注:pod lib lint是检索本地索引文件,pod spec lint 是本地和远程库同时检索)
pod spec lint --allow-warnings
验证通过结果如下:
-> JSKlineChart (0.1.0)
Analyzed 1 podspec.
JSKlineChart.podspec passed validation.
12.验证通过后,pod repo push <本地索引库> <索引文件名> - -allow-warnings 提交索引文件到远程索引库。注意cd 到正确的push路径。
pod repo push JSKlineChart JSKlineChart.podspec
正确输出如下:
Validating spec
-> JSKlineChart (0.1.0)
Updating the `JSKlineChart' repo
From https://github.com/zzyyd6316/JSKlineChart
* [new branch] master -> origin/master
* [new tag] 0.1.0 -> 0.1.0
Adding the spec to the `JSKlineChart' repo
- [Update] JSKlineChart (0.1.0)
Pushing the `JSKlineChart' repo
To https://github.com/zzyyd6316/JSKlineChart.git
8306a85..58890d7 master -> master
13.Over。。。在本地查看已成功

二、现在我们新建一个项目MyPodTest导入库试一试
1.进入MyPodTest项目创建Podfile
cd /Users/zzy/Desktop/MyPodTest
pod init
2.用vim Podfile命令或者用其他工具编辑生成的Podfile文件,我用的是xcode编辑的,编辑后内容如下:
# platform :ios, '9.0'
target 'MyPodTest' do
pod 'JSKlineChart', :git => 'https://github.com/zzyyd6316/JSKlineChart.git', :tag => '0.1.0'
end
3.执行pod install,你会发现JSKlineChart已经导入了你的项目里面

4.现在我们就可以导入库头文件进行使用了.

5.注意一点:每次你修改了组件库代码,想提交新的版本到远程仓库时,记得带上新的tag。
git add --a
git commit -m "XXX"
git pull
git tag "0.1.1"
git push --tags (把本地的tag push到远端)
git push
这样还有一个好处就是,当你想把库退回到之前的某个版本时。你就可以把Podfile文件里面pod 'JSKlineChart', :git => 'https://github.com/zzyyd6316/JSKlineChart.git', :tag => '0.1.0'。这句的tag修改为你想要的版本号。然后pod install。
不建议把Podfile文件里面的这句pod 'JSKlineChart', :git => 'https://github.com/zzyyd6316/JSKlineChart.git', :tag => '0.1.0'后面的tag去掉。
三、在公司内部的gitlab创建私有库,其实总的来说相关的步骤就把链接换一下就可以了。比如我公司对应的仓库链接是: git@192.0.0.0:liudehua/JSKlineChart.git 下面我只列出不相同的步骤。
4.创建本地索引库并和远程索引库做关联
pod repo add JSKlineChart git@192.0.0.0:liudehua/JSKlineChart.git
9.编辑JSKlineChart.podspec文件,红线标注的地方不同

*在用的时候Podfile这么写:
# platform :ios, '9.0'
target 'XXXXX' do
pod 'JSKlineChart', :git => 'git@192.0.0.0:liudehua/JSKlineChart.git', :tag => '0.1.1'
end
补充:tag的管理
git tag //查看tag
git tag test_tag c809ddbf83939a89659e51dc2a5fe183af384233 //在某个commit 上打tag
git tag
git push origin test_tag //!!!本地tag推送到线上
git tag -d test_tag //本地删除tag
git push origin :refs/tags/test_tag //本地tag删除了,再执行该句,删除线上tag
网友评论