iOS组件化搭建流程
2020-09-03 本文已影响0人
Alazyz
- 私有库准备
首先先准备三个git仓库(其中组件库可以是多个组件)
分别是 主工程、组件库、组件版本管理仓库
组件库(用于写业务相关代码)

组件版本管理仓库(用于组件库相关代码版本管理)

主工程(用于将组件库pod到当前工程运行)

- 私有库准备
首先先准备三个git仓库(其中组件库可以是多个组件)
分别是 主工程、组件库、组件版本管理仓库
组件库(用于写业务相关代码)

组件版本管理仓库(用于组件库相关代码版本管理)

主工程(用于将组件库pod到当前工程运行)

- 在终端上移动到你想创建pod库工程的路径,并执行pod库的创建。命令如下
cd desktop
pod lib create PrivateHelloWorld
之后
# 选择编程语言
What language do you want to use?? [ Swift / ObjC ]
> Objc
# 在你的项目中是否创建一个demo工程,为了方便测试,我选择了Yes
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 ]
> Yes
# 类前缀名
What is your class prefix?
> ZYH
Pod私有库创建成功。一般来说创建成功会自动打开项目
- 找到刚才创建的PrivateHelloWorld文件夹,点击入去,里面的目录如下

未安装pod需要安装,已安装请忽略
# 移到Example目录下
cd /Users/better/Desktop/PrivateHelloWorld/Example
# 安装CocoaPods项目
pod install --no-repo-update
- 编辑CocoaPods的配置文件(后缀名为podspec)

文件内容说明:
s.version我习惯是0.0.1开始
s.summary需要改改,不然待会提交会报错
s.homepage没问题,在提交之前,我们需要验证一下用终端移到我们的项目路径
pod lib lint --allow-warnings
- 项目d lib lint --allow-warnings发项目发布,tag 0.0.1
终端移到该项目文件下执行git的相关命令,关联仓库
# 添加远程地址,即上面创建码云项目的地址
git remote add origin https://gitee.com/Better_Y/PrintHelloWorld.git
# 添加文件
git add .
# 提交本地,并写描述
git commit -a -m "第一次提交 版本为0.0.1"
# --allow-unrelated-histories
# git pull origin maste会失败 ,提示:fatal: refusing to merge unrelated histories
# 原因是远程仓库origin上的分支master和本地分支master被Git认为是不同的仓库,所以不能直接合并,需要添加 --allow-unrelated-histories
git pull origin master --allow-unrelated-histories
# 推送到码云的PrintHelloWolrd项目的master分支上
git push origin master
# 提交版本号
git tag 0.0.1
# push到远程分支
git push origin 0.0.1
- 创建Sepc管理库
创建步骤跟上面码云创建的git私有库同理在
终端执行Specs创建命令
pod repo add PrintSpecs https://gitee.com/Better_Y/PrintSpecs.git
# PrintSpecs是刚才上面添加的管理库名字
# PrivateHelloWorld.podspec是PrintHelloWorld项目里面后缀为podspec的文件名
pod repo push TYMetro-Specs TYMetro-ByBus.podspec --allow-warnings
查看我们本地的Specs库:
直接Findle ->右键 -> 前往文件夹 -> 输入:~/.cocoapods/repos ->点击前往
- ,tag 0.0.1
终端移到该项目文件下执行git的相关命令,关联仓库
# 添加远程地址,即上面创建码云项目的地址
git remote add origin https://gitee.com/Better_Y/PrintHelloWorld.git
# 添加文件
git add .
# 提交本地,并写描述
git commit -a -m "第一次提交 版本为0.0.1"
# --allow-unrelated-histories
# git pull origin maste会失败 ,提示:fatal: refusing to merge unrelated histories
# 原因是远程仓库origin上的分支master和本地分支master被Git认为是不同的仓库,所以不能直接合并,需要添加 --allow-unrelated-histories
git pull origin master --allow-unrelated-histories
# 推送到码云的PrintHelloWolrd项目的master分支上
git push origin master
# 提交版本号
git tag 0.0.1
# push到远程分支
git push origin 0.0.1
- 创建Sepc管理库
创建步骤跟上面码云创建的git私有库同理在
终端执行Specs创建命令
pod repo add PrintSpecs https://gitee.com/Better_Y/PrintSpecs.git
# PrintSpecs是刚才上面添加的管理库名字
# PrivateHelloWorld.podspec是PrintHelloWorld项目里面后缀为podspec的文件名
pod repo push TYMetro-Specs TYMetro-ByBus.podspec --allow-warnings
查看我们本地的Specs库:
直接Findle ->右键 -> 前往文件夹 -> 输入:~/.cocoapods/repos ->点击前往