组件化开发 : pod私有化组件

今天特别开心,终于将pod私有化组件弄会了~


前提条件:我们进行组件化开发,需要使用cocospod管理,那么我们怎么将自己的代码模块pod上去,以供自己和别人使用?

这里我使用的是码云托管代码。项目名称ModuleA

1.在码云上创建远程仓库地址,如下图

2.然后在本地创建包,名为ModuleA,使用sourceTree git clone https://gitee.com/*****/ModuleA.git

3.然后终端操作

cd 进入ModuleA文件夹下

输入 pod spec create ModuleA

4.你就会在ModuleA文件夹下发现多了一个ModuleA.podspec文件

5.打开ModuleA.podspec文件配置

这里先看一我的目录截图:目标(pod  Category下的文件)

现在看一下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.首先,紧接在昨天的基础上做改动,昨天我将组件化代码放在码云上,并且这个库是私有的,接着我在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            = { "张敬" => "[email protected]" }

  # s.platform    = :ios

   s.ios.deployment_target = "9.0"

  s.source_files  = "Classes", "Classes/**/*.{h,m}"

  s.exclude_files = "Classes/Exclude"

发布公开的库,需要注册trunk

具体指令如下

$pod trunk register [Your-Email]'[Your-Name]'--description='[Your-Desc]'

> [Your-Email]: 任意邮件,但是我比较推荐你使用github上的Email

> [Your-Name]: 推荐使用github上使用的Name

> [Your-Desc]: 一个简单的描述,往往这个时候我们使用的是自己电脑的一个描述

比如我的

$pod trunk register [email protected] "yetongxue" --description= "这是一个测试"

如果发送成功

你就去邮箱点击链接

然后 $pod trunk me 

输出如下表示注册成功

继续输入指令

// 添加所有文件

$ 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

// 如果出现错误,需要修改到提示无误后方可执行下一步

$ pod trunk push [NAME].podspec

如果出现,代表成功

  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]

最后,笔者文笔粗糙,思想深度比较浅,莫见笑,有问题可留言探讨,我会第一时间回复

你可能感兴趣的:(组件化开发 : pod私有化组件)