现在前端大多都是mono repo项目。在对mono repo项目进行打包部署的时候其实并不需要对所有package都进行编译和打包,如果需要对单个package进行打包编译时,可以使用sparse-checkout命令进行过滤后下载。
详细代码如下所示:
# 支持shell语言代码的多行输入
gitLink=${globalParams.application.APP_CODE_URL}
packageInfo=${globalParams.user.PACKAGE}
branch=${globalParams.user.BRANCH}
dir="frameless"
rm -rf "$dir"
git init ${dir}
cd ${dir}
git remote add origin ${gitLink}
git config core.sparsecheckout true
git sparse-checkout init
git sparse-checkout set --no-cone '/*' '!packages/*' 'packages/common/*'
pkgArr=(${packageInfo//,/ })
for pkg in ${pkgArr[*]}
do
if [ ${pkg} != "deploy" ];then
echo "packages/${pkg}/*" >> .git/info/sparse-checkout
fi
done
# down code
git fetch origin
git pull origin ${branch}
FAQ
+ git config core.sparsecheckout true
+ git sparse-checkout init
git:'sparse-checkout' 不是一个 git 命令。参见 'git --help'。
解决办法:
git升级到1.7以上版本