wujingjing
2024-12-31 7357a3709ebeb22f28c17a21f103d0c715213b34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
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: '', // 本地私钥密码,非必填,有私钥则配置
    projectName: '', // 项目名称
    // 根据需要进行配置,如只需部署prod线上环境,请删除dev测试环境配置,反之亦然,支持多环境部署
    dev: {
        // 测试环境
        name: '测试环境',
        preRun: '', // 测试环境打包脚本
        host: '47.100.245.85', // 测试服务器地址
        port: 22, // ssh port,一般默认22
        username: 'Administrator', // 登录服务器用户名
        password: '', // 登录服务器密码
        distPath: 'dist', // 本地打包dist目录
        webDir: testWebDir, // // 测试环境服务器地址
 
        bakOld: true, // 是否备份旧的,保留上一份旧的
        // 远程执行命令
        remoteRun: {
            // 部署前执行命令
            before: '',
            // 部署后执行命令
            after: remoteRunAfter,
        },
        // 部署预览
        preview: {
            url: 'https://wi.beng35.com/admin/test', // 部署后检查部署效果,查看的网页地址
 
            openInBrowser: false, // 部署完成后是否自动打开部署的网页地址
        },
    },
    prod: {
        // 线上环境
        name: '线上环境',
        preRun: '', // 线上环境打包脚本
        host: '47.100.245.85', // 测试服务器地址
        port: 22, // ssh port,一般默认22
        username:'Administrator', // 登录服务器用户名
        password: '', // 登录服务器密码
        distPath: 'dist', // 本地打包dist目录
        webDir: 'E:/Wi/admin/prod', // // 测试环境服务器地址
        preview: {
            url: 'https://wi.beng35.com/admin/prod',
            openInBrowser: false,
        },
    },
    // 再还有多余的环境按照这个格式写即可
};