39 lines
1.5 KiB
PowerShell
39 lines
1.5 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
$LocalRepo = "D:\StampingMES"
|
|
$ServerIP = "10.2.20.122"
|
|
$ServerShare = "\\$ServerIP\MES_Publish"
|
|
$TempZip = "D:\deploy_tmp.zip"
|
|
$TempDir = "D:\deploy_tmp_dir"
|
|
|
|
if (-not (Test-Path $LocalRepo)) {
|
|
Write-Host "Error: Local repository path not found: $LocalRepo" -ForegroundColor Red
|
|
exit
|
|
}
|
|
|
|
Write-Host "1. Pulling latest code from Git..." -ForegroundColor Cyan
|
|
Set-Location $LocalRepo
|
|
git pull 2>$null
|
|
|
|
Write-Host "2. Compressing project files..." -ForegroundColor Cyan
|
|
if (Test-Path $TempDir) { Remove-Item -Path $TempDir -Recurse -Force }
|
|
New-Item -ItemType Directory -Path $TempDir | Out-Null
|
|
|
|
# ★ 白名单模式:只打包这些确定的目录和文件,其他一律不带
|
|
$rcArgs = @(
|
|
"$LocalRepo", "$TempDir",
|
|
"server", "web", "config", "scripts", "sql", "uploads",
|
|
"package.json", "package-lock.json", ".env",
|
|
"/E", "/NFL", "/NDL", "/NJH", "/NJS", "/NC", "/NS"
|
|
)
|
|
Start-Process -FilePath "robocopy" -ArgumentList $rcArgs -Wait -NoNewWindow
|
|
|
|
Compress-Archive -Path "$TempDir\*" -DestinationPath $TempZip -Force
|
|
Remove-Item -Path $TempDir -Recurse -Force
|
|
|
|
Write-Host "3. Pushing to server share directory..." -ForegroundColor Cyan
|
|
Copy-Item -Path $TempZip -Destination "$ServerShare\deploy.zip" -Force
|
|
Remove-Item -Path $TempZip -Force
|
|
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "Deploy package sent successfully!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green |