简易的powershell前端部署脚本
一个很简易的前端部署脚本
因为服务器是window server
,所以很尴尬的就是之前已经有的gulp脚本是不能用的,于是想到能不能模仿一个linux的shell脚本来写一个简单的移动,复制,备份的power shell
脚本:
主要分为两个步骤:
- 备份
- cd进入tomcat的webapp目录,复制dist包
- 此时判断当前盘的根目录,如果存在的bk文件夹的话,进入bk,判断以当前月份和天数的文件夹是否存在,
- 如果也存在的话,则cd进入,再创建一个以当前时间和分钟为名称的文件夹
- 替换
将当前上传的dist复制到tomcat的webapp目录,并替换
所以主要就是文件夹的创建,移动,复制操作,很简单...
然后去查找power shell的文档,写成如下:
bk.ps1
(用于备份):
$tomcat_webapp = "xxxx\Tomcat 7.0\webapps\dist"
$dist_dir = "xxx\dist"
$bk_dir = "x:\bk"
if(Test-Path $bk_dir) {
if(Test-Path $bk_dir\$(Get-Date -Format 'MM-dd')) {
New-Item -Path "$bk_dir\$(Get-Date -Format 'MM-dd')\$(Get-Date -Format 'hh-mm')" -ItemType Directory
Copy-Item -Path $tomcat_webapp -Recurse "$bk_dir\$(Get-Date -Format 'MM-dd')\$(Get-Date -Format 'hh-mm')"
} else {
New-Item -Path "$bk_dir\$(Get-Date -Format 'MM-dd')" -ItemType Directory
Copy-Item -Path $tomcat_webapp -Recurse "$bk_dir\$(Get-Date -Format 'MM-dd')"
}
} else {
New-Item -Path "$bk_dir\$(Get-Date -Format 'MM-dd')" -ItemType Directory
Copy-Item -Path $tomcat_webapp -Recurse "$bk_dir\$(Get-Date -Format 'MM-dd')"
}
deploy.ps1
(用于部署到tomcat):
$tomcat_webapp = "xxx\Tomcat 7.0\webapps"
$dist_dir = "xxx\dist"
Copy-Item -Path $dist_dir -Recurse $tomcat_webapp -Force