将Flutter Module作为私有库使用的脚本如下
path="../iOS_Flutter_Framework/FlutterLibrary/Frameworks"
libPath="../iOS_Flutter_Framework"
currentDate=$(date "+%Y%m%d%H%M%S")
pre_version=${Build_pre_version}
libTag="${pre_version}.${currentDate}"
echo "$libTag"
#判断输入的Tag_Version 不为空
if [ -z $libTag ];then
#输入的是空
echo "\n输入格式错误,请重新运行脚本,输入正确格式的sdk tag版本号\n"
else
#不是空
# release的正则
reg='^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,14}$'
echo "Tag_Version》》》》》》 "$libTag
if [[ "$libTag" =~ $reg ]];then
echo "恭喜你,输入的版本号,格式验证通过"
else
echo "\n输入格式错误,请重新运行脚本,输入正确格式的sdk tag版本号\n"
exit 1
fi
fi
rm -rf $path
mkdir $path
out=$path
outLib=$libPath
echo "准备输出所有文件到目录:$out"
echo "清除所有已编译文件"
find . -d -name build | xargs rm -rf
flutter clean
rm -rf build
flutter pub get
addFlag(){
cat .ios/Podfile > tmp1.txt
echo "use_frameworks!" >> tmp2.txt
cat tmp1.txt >> tmp2.txt
cat tmp2.txt > .ios/Podfile
rm tmp1.txt tmp2.txt
}
echo "检查 .ios/Podfile文件状态"
a=$(cat .ios/Podfile)
if [[ $a == use* ]]; then
echo '已经添加use_frameworks, 不再添加'
else
echo '未添加use_frameworks,准备添加'
addFlag
echo "添加use_frameworks 完成"
fi
echo "编译flutter"
BuildMode=${BuildType}
if [ ${BuildMode} = "Debug" ]; then
flutter build ios --debug --no-codesign
else
flutter build ios --release --no-codesign
fi
echo "编译flutter完成"
if [ ${BuildMode} = "Debug" ]; then
cp -r build/ios/Debug-iphoneos/*/*.framework $out
cp -r build/ios/Debug-iphoneos/App.framework $out
cp -r build/ios/Debug-iphoneos/Flutter.framework $out
else
cp -r build/ios/Release-iphoneos/*/*.framework $out
cp -r build/ios/Release-iphoneos/App.framework $out
cp -r build/ios/Release-iphoneos/Flutter.framework $out
fi
echo "复制framework库到文件夹: $out"
cd $outLib
sh ./auto.sh $libTag
#! /bin/sh
# 只需要修改这个内容就行,其他的内容不需要改动
git_commit_des="update framework"
echo "\n ****** begin ****** \n"
echo "\n ---- 获取podspec文件 begin ---- \n"
tag_version=$1
echo "tag_version 是 $1"
# 获取到的文件路径
file_path=""
file_name=""
# 文件后缀名
file_extension="podspec"
# 文件夹路径,pwd表示当前文件夹
directory="$(pwd)"
# 参数1: 路径;参数2: 文件后缀名
function getFileAtDirectory(){
for element in `ls $1`
do
dir_or_file=$1"/"$element
# echo "$dir_or_file"
if [ -d $dir_or_file ]
then
getFileAtDirectory $dir_or_file
else
file_extension=${dir_or_file##*.}
if [[ $file_extension == $2 ]]; then
echo "$dir_or_file 是 $2 文件"
file_path=$dir_or_file
file_name=$element
fi
fi
done
}
getFileAtDirectory $directory $file_extension
echo "\n -------------"
echo "\n file_path: ${file_path}"
echo "\n file_name: ${file_name}"
echo "\n ---- 获取podspec文件 end ---- \n"
# 定义pod文件名称
pod_file_name=${file_name}
# 查找 podspec 的版本
search_str="s.version"
# 读取podspec的版本
podspec_version=$tag_version
podspec_prev_version=""
function changeSpecVersion() {
echo ${pod_file_name}
while read line
do
zhengze="^s.version"
if [[ "$line" =~ $zhengze ]];then
echo "File:${line}"
sed -i "" "s/${line}/s.version = \"$tag_version\"/g" $file_path
fi
done < $file_path
# cat $pod_file_name
}
echo "\n ---- 读取原始podspec文件内容 start ---- \n"
#定义了要读取文件的路径
my_file="${pod_file_name}"
while read my_line
do
#输出读到的每一行的结果
# echo $my_line
# 查找到包含的内容,正则表达式获取以 ${search_str} 开头的内容
result=$(echo ${my_line} | grep "^${search_str}")
if [[ "$result" != "" ]]
then
echo "\n ${my_line} 包含 ${search_str}"
# 分割字符串,是变量名称,不是变量的值; 前面的空格表示分割的字符,后面的空格不可省略
array=(${result// / })
# 数组长度
count=${#array[@]}
# 获取最后一个元素内容
version=${array[count - 1]}
# 去掉 '
version=${version//\'/}
podspec_prev_version=$version
#else
# echo "\n ${my_line} 不包含 ${search_str}"
fi
done < $my_file
echo "\n ---- 读取原始podspec文件内容 end ---- \n"
echo "\n podspec_prev_version: ${podspec_prev_version}"
echo "\n ---- 修改podspec文件内容 start ---- \n"
changeSpecVersion
echo "\n ---- 修改podspec文件内容 end ---- \n"
pod_spec_name=${file_name}
pod_spec_version=${podspec_version}
echo "\n****** ${pod_spec_name} ${pod_spec_version} begin ****** \n"
echo "\n ------ 执行 pod install ------ \n"
echo "cd Example"
cd Example
echo "pod install"
pod install
# 回到上级目录
echo "cd .."
cd ..
echo "\n ------ 执行 git 本地提交代码操作 ------ \n"
# git 操作
echo "git add ."
git add .
echo "git status"
git status
echo "git commit -m ${git_commit_des}"
git commit -m 'update framework'
git pull origin master
git push -u origin master
echo "\n ------ 执行 pod 本地校验 ------ \n"
# pod 本地校验
echo "pod lib lint --allow-warnings --verbose"
pod lib lint --allow-warnings --verbose
echo "\n ------ 执行 git 打标签tag,并推送到远端 ------ \n"
# git推送到远端
echo "git tag ${pod_spec_version}"
git tag ${pod_spec_version}
echo "git push origin master --tags"
git push origin master --tags
echo "\n ------ 执行 pod 远端校验 ------ \n"
# pod 远端校验
echo "pod spec lint --allow-warnings --verbose"
pod spec lint --allow-warnings --verbose
echo "\n ------ 执行 pod 发布 ------ \n"
# 发布
echo "pod repo push --allow-warnings"
#pod trunk push --allow-warnings
pod spec lint --sources="https://github.com/CocoaPods/Specs.git,http://gitlab.xxx.com/App/iOS/PrivateCocoapodsSpec" --use-libraries --allow-warnings
pod repo push PrivateCocoapodsSpec $file_name --allow-warnings
echo "\n****** ${pod_spec_name} ${pod_spec_version} end ****** \n"
echo "****** end ******"
容易混淆巩固
#!/bin/bash
#
#1.反引号与$()用于命令替换
echo `date '--date=1 hour ago' +%Y-%m-%d-%H`
#或者
echo $(date '--date=1 hour ago' +%Y-%m-%d-%H)
#在编写Shell脚本时建议使用$(),原因主要有:
#(1)反引号与单引号外形相似,容易混淆;
#(2)在多层次的复合替换中,里层的反引号需要转义处理(\`) ,而$()则比较直观。例如下面的命令格式是错的:
# (3)反引号中对于反斜杠有特殊的处理,使用反协议对Shell特殊字符进行转义时需要两个反斜杠,而$()中只需要使用一个反斜杠。
#比如下面的脚本,需要输出$HOME,而不是环境变量HOME的内容,在反引号中需要对$符使用双反斜杠进行转义,$()中只需要使用一个反斜杠。
var1=`echo \$HOME` #使用一个反斜杠无法完成对$符的转义
var2=`echo \\$HOME`
var3=$(echo \$HOME)
echo $var1
echo $var2
echo $var3
#2.1直接变量替换
A="dablelv"
echo ${A}B
#2.2特殊变量替换
file="/dir1/dir2/dir3/my.file.txt"
echo ${file:1}
variable="'(]\\{}\$\""
echo "${variable}"
echo $variable
num=1
echo "hello world,$num"
echo 'hello world,$num'
echo hello world,$num
echo $(date)
name="str.tar.gz"
echo ${name}
name11='runoob'
str1="Hello, I know you are \"$name11\"!"
str2="Hello, I know you are "$name11"!"
str3='Hello, I know you are \"$name11\"!'
str4="Hello, I know you are \'$name11\'!"
#str5='Hello, I know you are \'$name11\'!' 错误的
echo $str1
echo $str2
echo $str3
echo $str4
:<<!
'(]\{}$"
'(]\{}$"
hello world,1
hello world,$num
hello world,1
Hello, I know you are "runoob"!
Hello, I know you are runoob!
Hello, I know you are \"$name11\"!
Hello, I know you are \'runoob\'!
!
可以参考,将私有库自动化
https://github.com/casatwy/ConfigPrivatePod
Shell 手把手教你入门
链接: https://pan.baidu.com/s/17SjZYjWxpDQqMeY8wjXsOg 密码: kg4n
推荐博客:
https://github.com/dunwu/blog/blob/master/source/_posts/coding/shell.md
网友评论