美文网首页iOS Developer
Private Pods(译)

Private Pods(译)

作者: Jabir_Zhang | 来源:发表于2017-03-23 17:14 被阅读28次

    官方原文地址
    CocoaPods不仅仅是一个能为你项目添加开源代码的非常棒的工具,而且也能实现多项目共享组件。你可以通过私有库来做到这点。
    只需要很少的步骤就能让你项目配置私有库;为它们创建一个私有仓库,让CocoaPods知道哪里能找到它,添加对应的podspecs到仓库中。

    1. 创建一个私有的仓库

    要用起来你们收集的私有资源库,我们建议你创建一个自己的私有代码仓库。这应该是一个本地的,对于需要使用这些资源库的人来说是可使用的。
    我们不需要复刻CocoaPods的Master仓库。保证你的团队中的每个人有权限的仓库,但是不需要对外公开。
    (官方没有细说这里面的过程,参照Using Pod Lib Create(译)

    2. 添加你的私有库到你的CocoaPods中

    $ pod repo add REPO_NAME SOURCE_URL
    

    注意:如果你打算创建本地pods,你应该推到这个资源地址上

    检查你是否成功安装

    $ cd ~/.cocoapods/repos/REPO_NAME
    $ pod repo lint .
    

    3. 添加你的Podspec到你的仓库

    确定你已经给你的代码资源打上tag和版本,然后运行

    $ pod repo push REPO_NAME SPEC_NAME.podspec
    

    这将会运行pod spec lint,注意在你私有库配置spec时所有的小细节。
    你仓库的结构应该是这样的

    .
    ├── Specs
        └── [SPEC_NAME]
            └── [VERSION]
                └── [SPEC_NAME].podspec
    

    就是这样

    你的私有Pod已经可以用于在Podfile里了。你能在你的Podfile中通过资源指令来使用私有库,比如下面的例子中展示。

    一个示例

    1. 创建一个私有的仓库

    在你的服务器上创建一个仓库。可以是在Github上或者是你自己的服务器如下

    $ cd /opt/git
    $ mkdir Specs.git
    $ cd Specs.git
    $ git init --bare
    

    (例子的余下部分使用仓库的是 https://github.com/artsy/Specs)

    2. 添加你的私有库到你的CocoaPods中

    使用你服务器上的仓库的URL,添加你的仓库使用:

    $ pod repo add artsy-specs git@github:artsy/Specs.git
    

    检查你是否安装成功使用:

    $ cd ~/.cocoapods/repos/artsy-specs
    $ pod repo lint .
    

    3. 添加你的Podspec到你的仓库

    创建你的Podspec

    cd ~/Desktop
    touch Artsy+OSSUIFonts.podspec
    

    Artsy+OSSUIFonts.podspec 应该会在你选择的文本编辑器里打开. 典型的内容应该是:

    Pod::Spec.new do |s|
      s.name             = "Artsy+OSSUIFonts"
      s.version          = "1.1.1"
      s.summary          = "The open source fonts for Artsy apps + UIFont categories."
      s.homepage         = "https://github.com/artsy/Artsy-OSSUIFonts"
      s.license          = 'Code is MIT, then custom font licenses.'
      s.author           = { "Orta" => "orta.therox@gmail.com" }
      s.source           = { :git => "https://github.com/artsy/Artsy-OSSUIFonts.git", :tag => s.version }
      s.social_media_url = 'https://twitter.com/artsy'
    
      s.platform     = :ios, '7.0'
      s.requires_arc = true
    
      s.source_files = 'Pod/Classes'
      s.resources = 'Pod/Assets/*'
    
      s.frameworks = 'UIKit', 'CoreText'
      s.module_name = 'Artsy_UIFonts'
    end
    

    保存你的Podspec,然后添加到仓库中

    pod repo push artsy-specs ~/Desktop/Artsy+OSSUIFonts.podspec
    

    如果你的Podspec是有效的,它将会被添加到仓库里。仓库将会看着像这样:

    .
    ├── Specs
        └── Artsy+OSSUIFonts
            └── 1.1.1
                └── Artsy+OSSUIFonts.podspec
    

    看这个 Podfile 是一个如何将仓库URL包含进去的示例。

    如何移除私有库

    pod repo remove [name]
    

    外部资源

    Using CocoaPods to Modularise a Big iOS App by @aroldan

    相关文章

      网友评论

        本文标题:Private Pods(译)

        本文链接:https://www.haomeiwen.com/subject/ldgznttx.html