Mac shell笔记
用来自动执行一些前端发布的操作。
脚本:
# webReleasePath用来发布的目录,webRevisionPath是开发的目录 webReleasePath='/Users/lufeng/Documents/project/pc-link/web-release' webRevisionPath='/Users/lufeng/Documents/project/pc-link/web-revision/project' # build Vue 工程 echo '1.编译Vue工程......' cd $webRevisionPath npm run build # 清空release目录,除了.git echo '2.清空release目录' cd $webReleasePath files=`ls -A` for fileName in $files; do if [[ $fileName == '.git' ]]; then echo '......' else rm -rf $fileName fi done # 复制发布内容过去 echo '3.发布到release目录' cd $webRevisionPath'/dist' files=`ls -A` for fileName in $files; do cp -R $fileName $webReleasePath done echo '4.提交Git' cd $webReleasePath git add -A git commit -m '机器人提交' git push origin HEAD:develop echo '完成!'
注意:
1. 保存文件后,给脚本添加执行(x)权限, chmod +x youname.sh