add:新增windows版部署脚本

This commit is contained in:
非凡主儿 2025-10-22 19:24:45 +08:00
parent 868afea22e
commit 6a0acff5c8

101
compile_dev.ps1 Normal file
View File

@ -0,0 +1,101 @@
# Windows PowerShell deployment script
$BRANCH_NAME = "dev"
# Project name
$PROJECT_NAME = "video-flow-$BRANCH_NAME-frontend"
# Log file path
$LOGFILE = "build_and_copy.log"
# Record start time
$startMessage = "Build process started at $(Get-Date)"
$startMessage | Tee-Object -FilePath $LOGFILE
# Get current branch name
$current_branch = git rev-parse --abbrev-ref HEAD
# Check if on dev branch, working directory is clean, and in sync with remote
if ($current_branch -ne $BRANCH_NAME) {
Write-Host "Current branch is not dev branch" -ForegroundColor Red
exit 1
}
# Check if working directory is clean
$gitStatus = git status --porcelain
if ($gitStatus) {
Write-Host "Working directory is not clean" -ForegroundColor Red
exit 1
}
# Check if local branch is in sync with remote
$localHead = git rev-parse HEAD
$remoteHead = git rev-parse origin/$BRANCH_NAME
if ($localHead -ne $remoteHead) {
Write-Host "Local branch is not in sync with remote branch" -ForegroundColor Red
exit 1
}
# Check current branch and run corresponding build command
if ($current_branch -eq $BRANCH_NAME) {
$buildMessage = "On dev branch, building project..."
$buildMessage | Tee-Object -FilePath $LOGFILE -Append
$PROFILE_ENV = $BRANCH_NAME
# Install dependencies and build (production mode with development environment variables)
yarn install
$env:NODE_ENV = "production"
npx --yes env-cmd -f .env.development yarn build
# Prepare dist directory
if (Test-Path "dist") {
Remove-Item -Path "dist" -Recurse -Force
}
New-Item -ItemType Directory -Path "dist" -Force | Out-Null
if (Test-Path ".next\cache") {
Remove-Item -Path ".next\cache" -Recurse -Force
}
Copy-Item -Path ".next" -Destination "dist\.next" -Recurse -Force
Copy-Item -Path "public" -Destination "dist\public" -Recurse -Force
Copy-Item -Path "package.json" -Destination "dist\package.json" -Force
Copy-Item -Path "package-lock.json" -Destination "dist\package-lock.json" -Force
} else {
Write-Host "On non-dev branch ($current_branch), exiting" -ForegroundColor Yellow
exit 1
}
# Create tar package
$tarFileName = "$PROJECT_NAME-$PROFILE_ENV.tar.gz"
tar -czvf $tarFileName dist
# Record end time
$endMessage = "Build process completed at $(Get-Date)"
$endMessage | Tee-Object -FilePath $LOGFILE -Append
# Upload to nexus
$uploadMessage = "upload to nexus at $(Get-Date)"
$uploadMessage | Tee-Object -FilePath $LOGFILE -Append
$nexusUrl = "https://repo.qikongjian.com/repository/frontend-tar-files/$tarFileName"
$credentials = 'admin:YZ9Gq6=8\*G|?:,'
$encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($credentials))
try {
Invoke-WebRequest -Uri $nexusUrl -Method Put -InFile $tarFileName -Headers @{
Authorization = "Basic $encodedCredentials"
}
Write-Host "Upload successful" -ForegroundColor Green
} catch {
Write-Host "Upload failed: $_" -ForegroundColor Red
exit 1
}
# Clean up build files
Remove-Item -Path "dist" -Recurse -Force
Remove-Item -Path $tarFileName -Force
Write-Host "Deployment completed" -ForegroundColor Green