wujingjing
2025-02-17 0f01c4bbce19fa8489a4e835c83cb9415549f681
deploy/deploy.config.js
@@ -1,4 +1,15 @@
const deployJson = require('../customer_list/yw/deploy.json');
const testWebDir = 'E:/Wi/admin/test';
// 忽略同步的目录
const ignoreProj = ['prod'];
// 同步时需要保留的文件路径(相对路径)
const ignoreSyncPath = ['static/config/globalConfig.js'];
// 部署后同步文件到同层其他项目目录,且忽略项目配置文件
const remoteRunAfter = `cd /d ${testWebDir} && powershell -Command "$currentDir = Split-Path -Leaf (Get-Location); $ignoreDirs = @('${ignoreProj.join(
   "','"
)}', $currentDir); $ignoreSyncPaths = @('${ignoreSyncPath.join(
   "','"
)}'); $parentDir = Split-Path (Get-Location) -Parent; Get-ChildItem $parentDir -Directory | Where-Object { -not $ignoreDirs.Contains($_.Name) } | ForEach-Object { $targetDir = $_.FullName; $backupFiles = @{}; foreach ($ignorePath in $ignoreSyncPaths) { $fullIgnorePath = Join-Path $targetDir $ignorePath; if (Test-Path $fullIgnorePath) { $tempPath = Join-Path $env:TEMP ('backup_' + [guid]::NewGuid().ToString()); Copy-Item -Path $fullIgnorePath -Destination $tempPath -Force; $backupFiles[$ignorePath] = $tempPath; } }; Get-ChildItem $targetDir -Recurse | Where-Object { $_.FullName -ne $targetDir } | Remove-Item -Force -Recurse; Get-ChildItem -Path '.' -Recurse -File | Where-Object { $relativePath = $_.FullName.Substring((Get-Location).Path.Length + 1); $shouldCopy = $true; foreach ($ignorePath in $ignoreSyncPaths) { if ($relativePath -like $ignorePath) { $shouldCopy = $false; break; } }; $shouldCopy } | ForEach-Object { $relativePath = $_.FullName.Substring((Get-Location).Path.Length + 1); $targetPath = Join-Path $targetDir $relativePath; $targetParent = Split-Path $targetPath -Parent; if (-not (Test-Path $targetParent)) { New-Item -Path $targetParent -ItemType Directory -Force | Out-Null }; Copy-Item -Path $_.FullName -Destination $targetPath -Force }; foreach ($ignorePath in $ignoreSyncPaths) { if ($backupFiles.ContainsKey($ignorePath)) { $fullIgnorePath = Join-Path $targetDir $ignorePath; $parentFolder = Split-Path $fullIgnorePath -Parent; if (-not (Test-Path $parentFolder)) { New-Item -Path $parentFolder -ItemType Directory -Force | Out-Null }; Move-Item -Path $backupFiles[$ignorePath] -Destination $fullIgnorePath -Force } } }"`;
module.exports = {
   privateKeyPath: 'C:/ssh/id_rsa', // 本地私钥地址,位置一般在C:/Users/xxx/.ssh/id_rsa,非必填,有私钥则配置
   passphrase: '', // 本地私钥密码,非必填,有私钥则配置
@@ -8,16 +19,25 @@
      // 测试环境
      name: '测试环境',
      preRun: '', // 测试环境打包脚本
      host: deployJson.test.host, // 测试服务器地址
      host: '47.100.245.85', // 测试服务器地址
      port: 22, // ssh port,一般默认22
      username: deployJson.test.username, // 登录服务器用户名
      username: 'Administrator', // 登录服务器用户名
      password: '', // 登录服务器密码
      distPath: 'dist', // 本地打包dist目录
      webDir: deployJson.test.path.slice(1), // // 测试环境服务器地址
      webDir: testWebDir, // // 测试环境服务器地址
      bakOld: true, // 是否备份旧的,保留上一份旧的
      // 远程执行命令
      remoteRun: {
         // 部署前执行命令
         before: '',
         // 部署后执行命令
         after: remoteRunAfter,
      },
      // 部署预览
      preview: {
         url: 'http://101.133.133.173:9096/', // 部署后检查部署效果,查看的网页地址
         url: 'https://wi.beng35.com/admin/test', // 部署后检查部署效果,查看的网页地址
         openInBrowser: false, // 部署完成后是否自动打开部署的网页地址
      },
   },
@@ -25,14 +45,14 @@
      // 线上环境
      name: '线上环境',
      preRun: '', // 线上环境打包脚本
      host: deployJson.product.host, // 测试服务器地址
      host: '47.100.245.85', // 测试服务器地址
      port: 22, // ssh port,一般默认22
      username: deployJson.product.username, // 登录服务器用户名
      username:'Administrator', // 登录服务器用户名
      password: '', // 登录服务器密码
      distPath: 'dist', // 本地打包dist目录
      webDir: deployJson.product.path.slice(1), // 测试环境服务器地址
      webDir: 'E:/Wi/admin/prod', // // 测试环境服务器地址
      preview: {
         url: 'http://47.100.245.85:8192/',
         url: 'https://wi.beng35.com/admin/prod',
         openInBrowser: false,
      },
   },