利用shell脚本自动化搭建cocoapod私有库

1,首先你得有自己的框架工程,接着,才创建一个模版podspec文件及其相关文件夹,

命令:

      pod lib create  私有库名B

大概目录如下:

具体目录结构

    进入到该私有库项目路径中,将framework动态组件库的代码文件 拷贝到 Classes文件夹中;


2,根据你的框架需要,修改.podspec文件 的内容:

Pod::Spec.new do |s|

  s.name            = 'EKUIBaseKitSpec'

  s.version          = '0.2.6'

  s.summary          = 'A short description of EKUIBaseKitSpec.'

# This description is used to generate tags and improve search results.

  s.description      = <<-DESC

TODO: Add long description of the pod here.

                       DESC

  s.homepage        = 'https://github.com/tianlunyuche/EKUIBaseKitSpec'

  # s.screenshots    = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'

  s.license          = { :type => 'MIT', :file => 'LICENSE' }

  s.author          = { 'tianlunyuche' => '[email protected]' }

  s.source          = { :git => '[email protected]:/home/ios/toollib/EKUIBaseKitSpec.git',

                         :tag => s.version.to_s,

                         :submodules => true

  }

  s.ios.deployment_target = '8.0'


  s.requires_arc = true  #是否支持arc


  #s.public_header_files = 'EKUIBaseKitSpec/Classes/**/*.h'

  #全局文件

  #s.prefix_header_contents = '#import "Masonry.h"', '#import "NSString+Helper.h"'

  s.prefix_header_file = 'EKUIBaseKitSpec/Classes/EKWHeader.h'


  # s.resource_bundles = {

  #  'EKWUIBase' => ['EKWUIBase/Assets/*.png']

  # }


  s.frameworks = 'UIKit', 'Foundation'

  # s.dependency 'AFNetworking', '~> 2.3'

  s.dependency 'Masonry'

  s.source_files = 'EKUIBaseKitSpec/Classes/**/*'

  s.subspec 'Category' do |a|

      a.source_files = 'EKUIBaseKitSpec/Classes/Category/**/*'

  end


  s.subspec 'EKWTextField' do |b|

      b.source_files = 'EKUIBaseKitSpec/Classes/EKWTextField/**/*'

      b.dependency 'EKUIBaseKitSpec/Category'

  end


  s.subspec 'EKWUnitField' do |c|

      c.source_files = 'EKUIBaseKitSpec/Classes/EKWUnitField/**/*'

      c.dependency 'EKUIBaseKitSpec/Category'

  end

end


3,然后创建一个shell脚本文件,取名0.0.1.sh,0.0.1是tag的版本号,跟podspec文件里的tag版本号一致,每次版本更新都要修改。

执行脚本:./0.0.1sh (第一次需要修改权限,输入linux命令:chmod 755 0.0.1.sh)

脚本具体内容如下:

#!/bin/sh

read -p "是否已用版本号重命名脚本名?[y/n]" input

case$inputin

[yY]*)

echo "命名版本号finished"

;;

[nN]*)

echo "改名字去!"

exit

;;

*)

echo "Just enter y or n, please."

exit

;;

esac

my_name=${0##*/}

tag_name="${my_name%.*}"

your_lib_pash=$(cd'dirname $0'; pwd)

echo ${your_lib_pash}

your_lib_name="${your_lib_pash##*/}"

if [ ! -d "/Users/${USER}/.cocoapods/repos/ekw" ]

then

pod repo add ekw  [email protected]:/home/ios/toollib/EkwSpecs.git

fi

cd /Users/${USER}/.cocoapods/repos/ekw

git add .

git commit -m"避免前置冲突"

git pull

git push

if [ ! -d "/Users/${USER}/.cocoapods/repos/ekw/${your_lib_name}" ]

then

mkdir ${your_lib_name}

fi

if[[ $? !=0]]

then

echo "新建索引父级目录失败,打印文件名是${your_lib_name}"

exit

fi

if [ -d "/Users/${USER}/.cocoapods/repos/ekw/${your_lib_name}/${tag_name}" ]

then

echo "${tag_name} 版本已存在!"

exit

fi

cd ${your_lib_name}

mkdir ${tag_name}

cp "${your_lib_pash}/${your_lib_name}.podspec" "/Users/${USER}/.cocoapods/repos/ekw/${your_lib_name}/${tag_name}/${your_lib_name}.podspec"

git add .

git commit -m "版本 ${tag_name} 索引提交"

# git pull

git push

if[[ $? !=0]]

then

echo "版本索引push失败"

else

echo "版本索引push成功"

fi

cd ${your_lib_pash}

git add .

git commit -m "版本 ${tag_name}: 新代码提交"

#git pull

git push origin master

git tag ${tag_name}

git push --tags

pod repo update /Users/${USER}/.cocoapods/repos/ekw

if[[ $? !=0]]

then

echo "repo更新失败"

else

echo "repo更新成功"

fi


4,最后就是验证安装过程了,在自己工程的podfile文件中:

引入自己的私有库路径所在的源:

source '[email protected]:/home/ios/toollib/EkwSpecs.git'

    pod'EKUIBaseKitSpec/EKWTextField'

    pod'EKUIBaseKitSpec/EKWUnitField'


在终端输入命令,安装:

pod install



5,下次修改了这个框架的代码,要升级了,就修改脚本文件为0.0.2.sh,podspec文件里的tag版本号也为0.0.2,再次执行脚本:

./0.0.2.sh

返回更新成功了

输入git fetch --tag

和git tag 也返回对应的tag了

接下来,就是更新本地的缓存库了,pod update  EKUIBaseKitSpec


最后!!!!!就是祝贺大家成功接入了哈哈,是不是用shell脚本后 特别简单了,每次更新库,再也不用写哪那么多命令行了。



给个可能用到的命令:
删除远程标签:

git push origin :refs/tags/标签名

再重新打:

git tag‘0.1.0‘

git push —tags

你可能感兴趣的:(利用shell脚本自动化搭建cocoapod私有库)