美文网首页
cocoapods配合svn创建私有库

cocoapods配合svn创建私有库

作者: Kira丶陈 | 来源:发表于2018-08-14 09:51 被阅读0次

    新入职一家公司,使用内网svn管理代码,正好有机会,学习下cocoapods管理内网svn的私有库。
    1.准备工作
    关于cocoapods的安装网上有很多,具体命令如下:

    //更换ruby 源
     gem sources --remove https://rubygems.org/
    gem sources -a https://gems.ruby-china.org/
    gem sources -l
    sudo gem update --system
    //安装
    sudo gem install cocoapods
    //更新pod库信息
    pod setup
    

    如果pod setup 总是执行失败,一般是因为没办法从github上下载https://github.com/CocoaPods/Specs项目。这里推荐下清华大学的开源软件镜像站--https://mirrors.tuna.tsinghua.edu.cn/。在里面找到cocoapods的镜像,会有下载说明,操作如下:

    cd ~/.cocoapods/repos 
    pod repo remove master
    git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
    

    cocoapods是基于git管理的,如果想要支持svn,首先要安装cocoapods-repo-svn插件,才可以使用repo-svn来代替原来的repo命令,实现svn库的添加和操作:

    gem install cocoapods-repo-svn
    

    2.cocoapods创建私有repo
    在svn上创建两个目录,一个用来存放cocoapods私有库的索引,一个用来存放私有库的实际代码。

    //clone svn目录
    svn co svn://xxx.xx.xxx.xxx/xx/xx  本地目录
    //创建目录,并上传svn,你也可以用工具实现这一步
    mkdir xxxxx_repos
    mkdir xxxxx_libs
    svn add * --force  
    svn commit -m "xxxxx"
    

    目录创建好后,将repos的路径添加cocoapods的本地索引中。第一步里 pod setup下载的项目就是用来存放索引的。系统默认会创建 ~/.cocoapods/repos/目录,并将公共的索引存放在mater目录下。我们要搭建私有库,所以要在repos中添加一个新的repo:

    //查看已有repo
    pod repo list
    pod repo-svn add xxxx_repos svn: //xxx.xx.xxx.xxx/xx/xxxxx_repos
    //添加完后,会多一个本地的repo,名字为xxxxx_repos
    pod repo list
    

    3.创建私有库
    在xxxxx_libs中创建私有库文件夹,并加入源码和LISENSE文件。LICENSE文件是开源的软件的协议,你可以在github创建一个项目,创建时记得选择一种LICENSE,拷贝这个文件的内容到你的LICENSE文件里:

    cd xxxxx_libs
    mkdir xxx_test
    //拷贝代码
    cp -r /xxx/xx xxx_test/Sourecs
    //创建LICENSE文件
    touch LICENSE
    

    此时svn目录如下:

    LICENSE     Sources     README.md       
    

    创建cocoapods的私有库索引文件:

    pod spec create xxx_test
    

    spec文件设置很多,本次没有太详细研究,只做了基础的配置,以后有机会深入研究下。打开文件,修改以下部分:

    s.name         = "taindy_test" 
    s.version      = "0.0.1" //库版本号,等下用
    s.summary      = "xxxx" //概要
    
    s.description  = <<-DESC
        yasdofjasidfojasdifjasdflasdfjasdflj       //库的详细描述
                       DESC
    s.license      = "MIT (xxxx)"   //遵守的开源协议
    s.author             = { "xxxx" => "xxxxx@qq.com" } //作者信息
    s.platform     = :ios     //使用平台
    
    //最重要的源码配置,source指向 spec在的目录
    s.source       = { :svn => "svn://xxx.xx.xxx.xxx/xx/xxx_libs/xxx_test", :tag => "#{s.version}" }
    //源码文件的目录
    s.source_files  = "Sources", "Sources/**/*.{h,m}"
    s.exclude_files = "Sources/Exclude"
    

    现在可以建立版本控制文件夹,在xxx_test目录下,创建tags文件夹,之后创建版本号0.0.1文件夹,并把xxxx_test目录下除tags之外的文件和文件夹都拷贝到该目录下:

    //在xxx_test下建立tags文件
    mkdir tags
    mkdir tags/0.0.1  //这个地方的版本号是刚才设置的s.version = "0.0.1"
    cp xx/xxx_test/xx  tags/0.0.1/ 
    

    此时xxx_test的目录如下:

    LICENSE         Sources         xxxx_test.podspec
    README.md       tags
    

    将文件上传至svn,执行lint,检测下spec文件,看到xxx_test.podspec passed validation.就通过了:

    pod spec lint xxxxx_test.podspec
    

    4.上传xxx_test的索引到svn的repos索引文件夹:

    cd xxx_test
    pod repo-svn push xxxx_repos xxxx_test.podspec
    //上传成功后,应该能在pod中搜索到
    pod search xxx_test
    
    /*
    -> xxx_test (0.0.1)
       xxxxxx.
       pod 'xxxx_test', '~> 0.0.1'
       - Homepage: http://www.baidu.com
       - Source:  
       svn://xxx.xxx.xxx.xxx/xxxx_libs/xxxxx_test
       - Versions: 0.0.1 [tiandy_repos repo]
    */
    

    5.创建测试项目,通过podfile 引用svn的私有库,podfile设置如下:

    platform :ios, '8.0'
    
    #inhibit_all_warnings!
    
    target 'PersionalDemo' do
        plugin 'cocoapods-repo-svn', :sources => [
        'svn://xxx.xxx.xxx.xxx/xxxx_repos' # 添加 svn 服务器中私有库 spec 的 repo
        ]
        use_frameworks!
        pod 'xxx_test', '~> 0.0.1'
    end
    

    执行pod install后,如果没有问题,那么恭喜你,现在可以运行项目,并且使用你的svn私有库了。
    补充,如果需要更新本地私有库索引,可以执行:

    pod repo-svn update xxxx_repos
    

    如果需要打包cocoapods 的私有库,可以使用cocoapods-packager,具体信息请参考http://www.cnblogs.com/brycezhang/p/4117180.html.

    相关文章

      网友评论

          本文标题:cocoapods配合svn创建私有库

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