前端Windwos解包Bat脚本

时间:2022-10-20 10:57:57

由于公司前端升级过程繁琐,需要将zip包解包后放到idera里在进行注释和解注释操作,通过idera做成jar包后,在上传到服务器,所以为了不做这些麻烦的操作就有了如下windows的bat脚本。像这么麻烦的升级过程用到的人应该不多,如有需要自行更换路径。

::由于前端zip包需要通过打成jar包后通过dockerfile做成镜像后通过k8s运行,所以,下载前端zip包解压之后要复制到idera目录下重新打包,为了提升工作效率也就有了这个windows-bat脚本

::删除static目录下的文件

rd /s /q D:\code\wenwen\src\main\resources\static\

::这一步是删除目录,因为需要删除文件之后所以才能删除目录

md D:\code\wenwen\src\main\resources\static\

::通过bandzip工具进行解压缩,前面是目标目录,后面是要解压的文件

bz x -o D:\code\wenwen\src\main\resources\static\ E:\下载包\前端\*.zip

::因为很多项目,所以前端包有些不同,有的包里有static有的没有,需要把包里有static的进行一下判断,将static目录里面的文件复制出来到上一个目录,包里没有static的直接执行下一步

if exist D:\code\wenwen\src\main\resources\static\static\ (

echo 复制static文件

xcopy D:\code\wenwen\src\main\resources\static\static\* D:\code\wenwen\src\main\resources\static\ /e

rd /s /q D:\code\wenwen\src\main\resources\static\static\

) else(

echo 没有static文件继续执行

)

::因为idera里要根据服务名进行打jar包以及将服务名写到包里,所以要注释旧服务名解开要打包的新服务名所以这一步直接将文件删掉,然后将注释好的包copy过去

del /f /s /q /a D:\code\wenwen\pom.xml


xcopy E:\wenwen\opm.xml D:\code\wenwen\


del /f /s /q /a D:\code\wenwen\src\main\resources\application.yml


xcopy E:\wenwen\application.yml D:\code\wenwen\src\main\resources\


del /f /s /q /a E:\下载包\前端\*.zip

::这一步就是将已经全部注释的服务名进行解注释

powershell -executionpolicy remotesigned -file E:\tihuan\test.ps1


#引用输入的字符串

$ID = Read-Host "请输入服务名"

#将注释的内容替换为非注释内容

powershell.exe -Command "(gc D:\code\wenwen\pom.xml) -replace '<!--<finalName>%{ID}</finalName>-->','<finalName>%{ID}</finalName>' | Out-File -encoding ASCII D:\code\wenwen\pom.xml"


powershell.exe -Command "(gc D:\code\wenwen\src\main\resources\application.yml)" -replace '#context-path: /${ID}','context-path: /${ID}' | Out-File -encoding ASCII D:\code\wenwen\src\main\resources\application.yml"


powershell.exe -Command "(gc D:\code\wenwen\src\main\resources\application.yml)" -replace '#name: /${ID}','name: /${ID}' | Out-File -encoding ASCII D:\code\wenwen\src\main\resources\application.yml"