From 6a0acff5c8b0539287c36079de6f9301437427e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=9E=E5=87=A1=E4=B8=BB=E5=84=BF?= <15541157+extraordinary-lord@user.noreply.gitee.com> Date: Wed, 22 Oct 2025 19:24:45 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E5=A2=9Ewindows=E7=89=88=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compile_dev.ps1 | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 compile_dev.ps1 diff --git a/compile_dev.ps1 b/compile_dev.ps1 new file mode 100644 index 0000000..98220f7 --- /dev/null +++ b/compile_dev.ps1 @@ -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 +