微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

项目需要,shell脚本自动化替换文档内容,并提交代码

项目需要,shell脚本自动化替换文档内容,并提交代码

#!/bin/bash

if [ ! $commitTag ]; then
echo "commitTag IS NULL"
exit
fi

echo ".........................push code start ..............................."
#root根目录
#rootPath=/Users/user/git/myelong
rootPath=/home/hudson/workspace
#前端最后一次提交commit,参入传入
#commitTag=316cb08031dc96c185d35d934d0264374255d95b
#后端项目空壳分支,由CI系统传入
#branch=b171102

#定义文件模版路径,即各个需要替换前端资源的模版文件路径
templatePath=$rootPath'/h5-hotelwxqb-web/src/main/resources/template'
#定义文件产出路径,即最终提交git的文件路径
outputPath=$rootPath'/h5-hotelwxqb-web/src/main/resources/config'

#从git上拉项目到本地,前端项目和后端项目都需要拉下来
cd $rootPath
#拉前端项目
git clone http://code.corp.elong.com/xy-team/hotelfx-static-resource-reference.git
cd hotelfx-static-resource-reference
git init
git checkout $commitTag

#前端首页js代码文本
indexJSTxt=$(cat index.js)
#前端列表页js代码文本
listJsTxt=$(cat list.js)
#前端快速预定列表页js代码文本
flistJsTxt=$(cat flist.js)
#前端详情页js代码文本
detailJsTxt=$(cat detail.js)
#前端订单填写页js代码文本
createOderJsTxt=$(cat createorder.js)

#拉后端项目
cd $rootPath
git clone git@code.corp.elong.com:h5-website/h5-hotelwxqb-web.git
cd h5-hotelwxqb-web
git init
git checkout $branch
git pull

#替换首页前端资源
replace_index(){
#定义本地文件路径
sourceFile=$templatePath/index.txt
destFile=$outputPath/spamvtbody2_alpha.txt
destFile2=$outputPath/spamvtbody2_beta.txt
#复制本地文件模版文件修改目标文件内容
cat $sourceFile > $destFile
echo $indexJSTxt >> $destFile
cp $destFile $destFile2
}

#替换列表页前端资源
replace_list(){
#从本地列表页模版文件替换前端资源路径,生成列表页配置文件
sourceFile=$templatePath/list.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-list.xml
#复制本地文件模版文件修改目标文件内容
cat $sourceFile > $destFile
echo $listJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换快速预定前端资源
replace_flist(){
#从本地列表页模版文件替换前端资源路径,生成列表页配置文件
sourceFile=$templatePath/flist.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-flist.xml
#复制本地文件模版文件修改目标文件内容
cat $sourceFile > $destFile
echo $flistJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换详情页前端资源
replace_detail(){
#从本地详情页模版文件替换前端资源路径,生成新详情页配置文件
sourceFile=$templatePath/detail.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-detail.xml
#复制本地文件模版文件修改目标文件内容
cat $sourceFile > $destFile
echo $detailJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换订单填写页前端资源
replace_createorder(){
#从本地订单填写页模版文件替换前端资源路径,生成新订单填写页配置文件
sourceFile=$templatePath/createorder.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-createorder.xml
#复制本地文件模版文件修改目标文件内容
cat $sourceFile > $destFile
echo $createOderJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换程序里的各个页面前端资源代码
replace_index
replace_list
replace_flist
replace_detail
replace_createorder

#代码提交到git上
git add -A
git commit -am 'update web script '$branch
#git pull
git push origin $branch
echo ".........................push code end ..............................."

#删除前端资源项目 cd $rootPath rm -rf H5_JAVA_GIT_HOTELWXQB_WEB mv h5-hotelwxqb-web H5_JAVA_GIT_HOTELWXQB_WEB rm -rf hotelfx-static-resource-reference

原文地址:https://www.jb51.cc/bash/389907.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐