利用shell腳本自動(dòng)化搭建cocoapod私有庫

1,首先你得有自己的框架工程,接著,才創(chuàng)建一個(gè)模版podspec文件及其相關(guān)文件夾,

命令:

? ? ? pod lib create? 私有庫名B

大概目錄如下:

具體目錄結(jié)構(gòu)

????進(jìn)入到該私有庫項(xiàng)目路徑中,將framework動(dòng)態(tài)組件庫的代碼文件?拷貝到?Classes文件夾中;


2,根據(jù)你的框架需要,修改.podspec文件?的內(nèi)容:

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' => 'xin@moy.com' }

? s.source? ? ? ? ? = { :git => 'root@172.0.0.0:/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,然后創(chuàng)建一個(gè)shell腳本文件,取名0.0.1.sh,0.0.1是tag的版本號(hào),跟podspec文件里的tag版本號(hào)一致,每次版本更新都要修改。

執(zhí)行腳本:./0.0.1sh (第一次需要修改權(quán)限,輸入linux命令:chmod 755 0.0.1.sh)

腳本具體內(nèi)容如下:

#!/bin/sh

read -p "是否已用版本號(hào)重命名腳本名?[y/n]" input

case$inputin

[yY]*)

echo "命名版本號(hào)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? root@172.17.0.0:/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 "新建索引父級(jí)目錄失敗,打印文件名是${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,最后就是驗(yàn)證安裝過程了,在自己工程的podfile文件中:

引入自己的私有庫路徑所在的源:

source 'root@172.0.0.0:/home/ios/toollib/EkwSpecs.git'

? ? pod'EKUIBaseKitSpec/EKWTextField'

? ? pod'EKUIBaseKitSpec/EKWUnitField'


在終端輸入命令,安裝:

pod install



5,下次修改了這個(gè)框架的代碼,要升級(jí)了,就修改腳本文件為0.0.2.sh,podspec文件里的tag版本號(hào)也為0.0.2,再次執(zhí)行腳本:

./0.0.2.sh

返回更新成功了

輸入git fetch --tag

和git tag 也返回對(duì)應(yīng)的tag了

接下來,就是更新本地的緩存庫了,pod update??EKUIBaseKitSpec


最后?。。。?!就是祝賀大家成功接入了哈哈,是不是用shell腳本后 特別簡(jiǎn)單了,每次更新庫,再也不用寫哪那么多命令行了。



給個(gè)可能用到的命令:
刪除遠(yuǎn)程標(biāo)簽:

git push origin :refs/tags/標(biāo)簽名

再重新打:

git tag‘0.1.0‘

git push —tags

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容