ares-ssh-deploy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +471 -0
  3. package/dist/index.cjs +1 -0
  4. package/dist/index.d.cts +3 -0
  5. package/dist/index.d.mts +3 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.mjs +1 -0
  8. package/dist/types/index.d.ts +67 -0
  9. package/dist/utils/childProcess.cjs +1 -0
  10. package/dist/utils/childProcess.d.cts +103 -0
  11. package/dist/utils/childProcess.d.mts +103 -0
  12. package/dist/utils/childProcess.d.ts +103 -0
  13. package/dist/utils/childProcess.mjs +1 -0
  14. package/dist/utils/common.cjs +1 -0
  15. package/dist/utils/common.d.cts +45 -0
  16. package/dist/utils/common.d.mts +45 -0
  17. package/dist/utils/common.d.ts +45 -0
  18. package/dist/utils/common.mjs +1 -0
  19. package/dist/utils/deploy-linux-bastion.cjs +1 -0
  20. package/dist/utils/deploy-linux-bastion.d.cts +120 -0
  21. package/dist/utils/deploy-linux-bastion.d.mts +120 -0
  22. package/dist/utils/deploy-linux-bastion.d.ts +120 -0
  23. package/dist/utils/deploy-linux-bastion.mjs +1 -0
  24. package/dist/utils/deploy-windows-server.cjs +1 -0
  25. package/dist/utils/deploy-windows-server.d.cts +66 -0
  26. package/dist/utils/deploy-windows-server.d.mts +66 -0
  27. package/dist/utils/deploy-windows-server.d.ts +66 -0
  28. package/dist/utils/deploy-windows-server.mjs +1 -0
  29. package/dist/utils/logger.cjs +1 -0
  30. package/dist/utils/logger.d.cts +5 -0
  31. package/dist/utils/logger.d.mts +5 -0
  32. package/dist/utils/logger.d.ts +5 -0
  33. package/dist/utils/logger.mjs +1 -0
  34. package/dist/utils/ssh.cjs +1 -0
  35. package/dist/utils/ssh.d.cts +226 -0
  36. package/dist/utils/ssh.d.mts +226 -0
  37. package/dist/utils/ssh.d.ts +226 -0
  38. package/dist/utils/ssh.mjs +1 -0
  39. package/package.json +31 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # ares-ssh-deploy
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 初始化
package/README.md ADDED
@@ -0,0 +1,471 @@
1
+ # ssh-deploy-tools
2
+
3
+ 基于 SSH 协议的自动化部署工具,支持部署项目到远程 Windows Server 服务器,或者通过堡垒机部署项目到内部 Linux 服务器。
4
+
5
+ ## 功能特性
6
+
7
+ - **双平台支持**: 支持部署到 Windows Server 和 Linux 服务器
8
+ - **堡垒机部署**: 支持通过堡垒机部署到内部 Linux 服务器
9
+ - **安全传输**: 基于 SSH 协议进行安全文件传输
10
+ - **备份机制**: 部署前自动备份远程服务器现有文件
11
+ - **临时目录**: 使用临时目录策略,确保部署过程原子性
12
+ - **健康检查**: 支持健康检查开关控制(仅限堡垒机模式)
13
+ -
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ # 作为依赖安装
19
+ npm install ares-ssh-deploy
20
+
21
+ # 或使用 pnpm
22
+ pnpm add ares-ssh-deploy
23
+ ```
24
+
25
+ ## 使用方法
26
+
27
+ ### 1. 部署到 Windows Server
28
+
29
+ ```typescript
30
+ import { deployToWindowsServer } from 'ares-ssh-deploy';
31
+
32
+ // 前端项目打包配置
33
+ const buildConfig = {
34
+ build: true, // 是否构建项目
35
+ mode: 'production', // 构建模式
36
+ projectDir: 'C:\\workspace\\webstormProjects\\test\\' // 项目目录
37
+ };
38
+
39
+ // 服务器配置
40
+ const targetConfig = {
41
+ host: '192.168.1.158',
42
+ port: 22,
43
+ username: 'username',
44
+ password: 'password',
45
+ localDeployDir: 'C:\\deploy_static\\deploy-tool-test\\', // 本地待部署目录
46
+ remoteDir: 'D:\\nginx-1.20.2\\html\\deploy-tool-test\\', // 远程目标目录
47
+ remoteDirTemp: 'D:\\nginx-1.20.2\\html\\deploy-tool-test-temp\\' // 远程临时目录
48
+ };
49
+
50
+ // 执行部署
51
+ deployToWindowsServer(buildConfig, targetConfig);
52
+
53
+ ```
54
+ 以上的配置项为可选,可以在 `.env.windows-server` 文件中定义, 从配置文件中读取配置项, 执行部署方法时可不传参。
55
+
56
+
57
+ ### 2. 通过堡垒机部署到 Linux 服务器
58
+
59
+ ```typescript
60
+ import {deployToLinuxBastionInternalServer} from 'ares-ssh-deploy';
61
+
62
+ // 前端项目打包配置
63
+ const buildConfig = {
64
+ build: true, // 是否构建项目
65
+ mode: 'production', // 构建模式
66
+ projectDir: 'C:\\workspace\\webstormProjects\\test\\' // 项目目录
67
+ };
68
+ // 堡垒机配置
69
+ const bastionConfig = {
70
+ host: 'bastion-host.com',
71
+ port: 22,
72
+ username: 'bastion-user',
73
+ password: 'bastion-password'
74
+ };
75
+ // 堡垒机内部服务器配置
76
+ const targetConfig = {
77
+ host: 'internal-linux-server.com',
78
+ port: 22,
79
+ username: 'target-user',
80
+ password: 'target-password',
81
+ localDeployDir: 'C:\\deploy_static\\deploy-tool-test\\', // 本地待部署目录
82
+ remoteDir: '/usr/share/nginx/html/deploy-tool-test/', // 远程部署目录
83
+ remoteDirTemp: '/usr/share/nginx/html/deploy-tool-test-temp/', // 远程临时目录
84
+ remoteBackupDir: '/usr/share/nginx/deploy-tool-test-backup/', // 远程备份目录
85
+ remoteHealthDir: '/usr/share/nginx/html/health/', // 健康检查目录
86
+ remoteHealthFile: '/usr/share/nginx/html/health/index.html', // 健康检查文件
87
+ remoteHideHealthFileDir: '/usr/share/nginx/html/health/hide/', // 健康检查隐藏目录
88
+ remoteHealthHiddenFile: '/usr/share/nginx/html/health/hide/index.html', // 健康检查隐藏文件
89
+ };
90
+
91
+ // 执行部署
92
+ const success = await deployToLinuxBastionInternalServer(buildConfig, bastionConfig, targetConfig);
93
+ ```
94
+
95
+ 以上的配置项为可选,可以在 `.env.linux-aliyun-bastion` 文件中定义, 从配置文件中读取配置项, 执行部署方法时可不传参。
96
+
97
+
98
+ ### 3. 控制健康检查
99
+
100
+ ```typescript
101
+ import { enableLinuxBastionHealthCheck, disableLinuxBastionHealthCheck } from 'ares-ssh-deploy';
102
+
103
+ // 关闭健康检查
104
+ disableLinuxBastionHealthCheck(bastionConfig, targetConfig);
105
+
106
+ // 启用健康检查
107
+ enableLinuxBastionHealthCheck(bastionConfig, targetConfig);
108
+ ```
109
+
110
+ 同部署代码, 可以不传参, 而是通过配置文件读取参数。
111
+
112
+
113
+ ### 4. 示例
114
+ ```
115
+ test/
116
+ ├── .env
117
+ ├── .env.linux-aliyun-bastion
118
+ ├── .env.windows-server
119
+ ├── deploy-linux-bastion.js
120
+ ├── deploy-windows-server.js
121
+ ├── package.json
122
+
123
+ ```
124
+
125
+ #### 示例代码 `.env`
126
+ ```env
127
+ ```
128
+
129
+ #### 示例代码 `.env.linux-aliyun-bastion`
130
+ ```env
131
+ # 日志级别
132
+ LOG_LEVEL=info
133
+
134
+ # 是否构建前端项目
135
+ BUILD_PROJECT=false
136
+
137
+ # 构建模式
138
+ BUILD_MODE=test
139
+
140
+ # 项目目录
141
+ PROJECT_DIR=C:\\workspace\\webstormProjects\\test\\
142
+
143
+ # 本地待部署目录
144
+ LOCAL_DEPLOY_DIR=C:\\deploy_static\\deploy-tool-test\\
145
+
146
+ # 本地下载目录
147
+ LOCAL_DOWNLOAD_DIR=C:\\Users\\ares wei\\Downloads\\deploy-tool-test\\
148
+
149
+ # 堡垒机SSH配置
150
+ BASTION_SSH_HOST=bastion-host.com
151
+ BASTION_SSH_USER=bastion-user
152
+ BASTION_SSH_PASSWORD=bastion-password
153
+ BASTION_SSH_PORT=bastion-port
154
+ BASTION_SSH_PRIVATE_KEY=
155
+
156
+ # 目标SSH配置
157
+ TARGET_SSH_HOST=172.16.0.52
158
+ TARGET_SSH_USER=root
159
+ TARGET_SSH_PASSWORD=
160
+ TARGET_SSH_PORT=22
161
+ TARGET_SSH_PRIVATE_KEY=
162
+
163
+ # 目标服务器相关目录
164
+ TARGET_BK_DIR=/usr/share/nginx/deploy-tool-test-backup/
165
+ TARGET_DIR=/usr/share/nginx/html/deploy-tool-test/
166
+ TARGET_DIR_TEMP=/usr/share/nginx/html/deploy-tool-test-temp/
167
+
168
+ # 目标服务器健康检查相关目录及文件
169
+ TARGET_HEALTH_DIR=/usr/share/nginx/html/health/
170
+ TARGET_HIDE_HEALTH_FILE_DIR=/usr/share/nginx/html/health/hide/
171
+ TARGET_HEALTH_FILE=/usr/share/nginx/html/health/index.html
172
+ TARGET_HEALTH_HIDDEN_FILE=/usr/share/nginx/html/health/hide/index.html
173
+ ```
174
+
175
+ #### 示例代码 `.env.lwindows-server`
176
+ ```env
177
+ # 日志级别
178
+ LOG_LEVEL=info
179
+
180
+ # 是否构建前端项目
181
+ BUILD_PROJECT=false
182
+
183
+ # 构建模式
184
+ BUILD_MODE=test
185
+
186
+ # 项目目录
187
+ PROJECT_DIR=C:\\workspace\\webstormProjects\\test\\
188
+
189
+ # 本地待部署目录
190
+ LOCAL_DEPLOY_DIR=C:\\deploy_static\\deploy-tool-test\\
191
+
192
+ # 本地下载目录
193
+ LOCAL_DOWNLOAD_DIR=C:\\Users\\ares wei\\Downloads\\deploy-tool-test\\
194
+
195
+ # 目标SSH配置
196
+ TARGET_SSH_HOST=192.168.1.158
197
+ TARGET_SSH_USER=username
198
+ TARGET_SSH_PASSWORD=password
199
+ TARGET_SSH_PORT=22
200
+ TARGET_SSH_PRIVATE_KEY=
201
+
202
+ # 目标服务器相关目录
203
+ TARGET_BK_DIR=D:\\nginx-1.20.2\\html\\deploy-tool-test-backup\\
204
+ TARGET_DIR=D:\\nginx-1.20.2\\html\\deploy-tool-test\\
205
+ TARGET_DIR_TEMP=D:\\nginx-1.20.2\\html\\deploy-tool-test-temp\\
206
+
207
+ ```
208
+
209
+ #### 示例代码 `deploy-linux-bastion.js`
210
+ ```javascript
211
+ import {deployToLinuxBastionInternalServer} from 'ares-ssh-deploy'
212
+
213
+ deployToLinuxBastionInternalServer()
214
+ ```
215
+
216
+ #### 示例代码 `deploy-windows-server.js`
217
+ ```javascript
218
+ import {deployToWindowsServer} from 'ares-ssh-deploy'
219
+
220
+ deployToWindowsServer()
221
+ ```
222
+
223
+ #### 示例代码 `package.json`
224
+ ```json
225
+ {
226
+ "name": "test",
227
+ "version": "1.0.0",
228
+ "description": "",
229
+ "main": "index.js",
230
+ "type": "module",
231
+ "scripts": {
232
+ "deploy:windows-server": "dotenvx run --env-file=.env.windows-server -- node deploy-windows-server.js",
233
+ "deploy:linux-aliyun-bastion": "dotenvx run --env-file=.env.linux-aliyun-bastion -- node deploy-linux-bastion.js"
234
+ },
235
+ "dependencies": {
236
+ "ares-ssh-deploy": "^1.0.0"
237
+ }
238
+ }
239
+ ```
240
+
241
+
242
+ ## 配置选项说明
243
+
244
+ ### SSH 客户端配置 (SSHClientConfig)
245
+ - `host`: 服务器地址
246
+ - `port`: SSH 端口号,默认 22
247
+ - `username`: 用户名
248
+ - `password`: 密码
249
+ - `privateKey`: 私钥文件路径(可选,用于密钥认证)
250
+
251
+ ### 部署配置 (BuildConfig)
252
+ - `build`: 是否执行构建,默认 false
253
+ - `mode`: 构建模式,如 production、development
254
+ - `projectDir`: 项目根目录
255
+
256
+ ### 目标服务器配置 (TargetSSHClientConfig)
257
+ - `localDeployDir`: 本地待部署目录
258
+ - `localDownloadDir`: 本地下载目录(用于本地备份)
259
+ - `remoteBackupDir`: 远程备份目录
260
+ - `remoteDir`: 远程目标目录(最终部署位置)
261
+ - `remoteDirTemp`: 远程临时目录(部署过程中的临时存储)
262
+ - `remoteHealthDir`: 健康检查目录
263
+ - `remoteHealthFile`: 健康检查文件路径
264
+ - `remoteHideHealthFileDir`: 隐藏健康检查文件的目录
265
+ - `remoteHealthHiddenFile`: 隐藏的健康检查文件路径
266
+
267
+ ## 部署流程
268
+
269
+ ### Windows Server 部署流程
270
+ 1. 检查本地部署目录是否存在
271
+ 2. 如需构建,则执行项目构建
272
+ 3. 连接到远程 Windows Server
273
+ 4. 检查并创建远程目标目录和临时目录
274
+ 5. 清空远程临时目录
275
+ 6. 上传本地文件到远程临时目录
276
+ 7. 清空远程目标目录
277
+ 8. 将临时目录文件移动到目标目录
278
+ 9. 断开连接
279
+
280
+ ### Linux 堡垒机部署流程
281
+ 1. 检查本地部署目录是否存在
282
+ 2. 如需构建,则执行项目构建
283
+ 3. 连接到堡垒机
284
+ 4. 检查并创建远程目标目录、临时目录和备份目录
285
+ 5. 在远程服务器上备份现有文件
286
+ 6. 清空远程临时目录
287
+ 7. 上传本地文件到远程临时目录
288
+ 8. (可选)隐藏健康检查文件使服务暂时不可用
289
+ 9. 清空远程目标目录
290
+ 10. 将临时目录文件移动到目标目录
291
+ 11. (可选)恢复健康检查文件使服务可用
292
+ 12. 断开连接
293
+
294
+ ## 已测试使用环境
295
+
296
+ - 本地环境:Windows 10/11
297
+ - 测试环境:Windows Server
298
+ - 生产环境:阿里云堡垒机(Linux)+ 内部 Linux 服务器
299
+
300
+ ## 已测试部署流程
301
+
302
+ 1. 部署本地前端项目到 Windows Server 服务器的 Nginx 服务
303
+ 2. 通过堡垒机部署项目到内部 Linux 服务器
304
+
305
+ ## 常见问题
306
+
307
+ ### Q: 部署流程是否可配置?
308
+ A: 目前已封装的部署流程方法`deployToWindowsServer`和`deployToLinuxBastionInternalServer`可满足大多数场景,如果需要自定义部署流程,请根据工具方法自行封装。
309
+
310
+
311
+ ## 部分实用工具函数 API
312
+
313
+ 以下是在 `utils` 目录中提供的实用工具函数:
314
+
315
+ ### 通用工具函数 (common.js)
316
+
317
+ #### `getBastionConfig(config?)`
318
+ 获取堡垒机配置,合并环境变量和传入的配置参数
319
+
320
+ - **参数**:
321
+ - `config` (BastionSSHClientConfig, 可选): 用户自定义的堡垒机配置
322
+ - **返回值**: `BastionSSHClientConfig` - 合并后的堡垒机配置
323
+
324
+ #### `getBastionTargetConfig(config?)`
325
+ 获取堡垒机内部 Linux 服务器配置
326
+
327
+ - **参数**:
328
+ - `config` (TargetSSHClientConfig, 可选): 用户自定义的目标服务器配置
329
+ - **返回值**: `TargetSSHClientConfig` - 合并后的目标服务器配置
330
+
331
+ #### `getBastionChannelConfig(config?)`
332
+ 获取堡垒机连接内部服务器的通道配置
333
+
334
+ - **参数**:
335
+ - `config` (TargetSSHClientConfig, 可选): 目标服务器配置
336
+ - **返回值**: `BastionChannelConfig` - 通道配置
337
+
338
+ #### `getWindowsServerTargetConfig(config?)`
339
+ 获取 Windows Server 目标服务器配置
340
+
341
+ - **参数**:
342
+ - `config` (TargetSSHClientConfig, 可选): 用户自定义的目标服务器配置
343
+ - **返回值**: `TargetSSHClientConfig` - 合并后的 Windows Server 配置
344
+
345
+ #### `getBuildConfig(config?)`
346
+ 获取构建项目配置
347
+
348
+ - **参数**:
349
+ - `config` (BuildConfig): 用户自定义的构建配置
350
+ - **返回值**: `BuildConfig` - 合并后的构建配置
351
+
352
+ #### `buildProject(bConfig)`
353
+ 执行项目构建
354
+
355
+ - **参数**:
356
+ - `bConfig` (BuildConfig): 构建配置
357
+ - **返回值**: `Promise<any>` - 构建结果
358
+
359
+ ### SSH 工具函数 (ssh.js)
360
+
361
+ #### `getSSHClient(config)`
362
+ 获取连接到 Windows Server 的 SSH 客户端
363
+
364
+ - **参数**:
365
+ - `config` (TargetSSHClientConfig): 目标服务器配置
366
+ - **返回值**: `Promise<NodeSSH>` - SSH 客户端实例
367
+
368
+ #### `getBastionSSHClient(config)`
369
+ 获取连接到堡垒机的 SSH 客户端
370
+
371
+ - **参数**:
372
+ - `config` (BastionSSHClientConfig): 堡垒机配置
373
+ - **返回值**: `Promise<NodeSSH>` - SSH 客户端实例
374
+
375
+ #### `execRemoteWindowServerCommand(ssh, command)`
376
+ 在远程 Windows Server 上执行命令
377
+
378
+ - **参数**:
379
+ - `ssh` (NodeSSH): SSH 客户端实例
380
+ - `command` (string): 要执行的命令
381
+ - **返回值**: `Promise<SSHExecCommandResponse>` - 命令执行结果
382
+
383
+ #### `makeDirectoryOnRemoteWindowServer(ssh, config)`
384
+ 在远程 Windows Server 上创建目录
385
+
386
+ - **参数**:
387
+ - `ssh` (NodeSSH): SSH 客户端实例
388
+ - `config` (MakeDirectoryConfig): 目录创建配置
389
+ - **返回值**: `Promise<void>`
390
+
391
+ #### `putDirectoryToRemoteWindowServer(ssh, config)`
392
+ 上传目录到远程 Windows Server
393
+
394
+ - **参数**:
395
+ - `ssh` (NodeSSH): SSH 客户端实例
396
+ - `config` (UploadDownloadConfig): 上传配置
397
+ - **返回值**: `Promise<any>` - 上传结果
398
+
399
+ #### `getDirectoryFromRemoteWindowServer(ssh, config)`
400
+ 从远程 Windows Server 下载目录
401
+
402
+ - **参数**:
403
+ - `ssh` (NodeSSH): SSH 客户端实例
404
+ - `config` (UploadDownloadConfig): 下载配置
405
+ - **返回值**: `Promise<any>` - 下载结果
406
+
407
+ #### `clearRemoteWindowServerDir(ssh, path)`
408
+ 清空远程 Windows Server 上的目录
409
+
410
+ - **参数**:
411
+ - `ssh` (NodeSSH): SSH 客户端实例
412
+ - `path` (string): 目录路径
413
+ - **返回值**: `Promise<any>` - 执行结果
414
+
415
+ #### `execIntraServerCommand(bastionSSH, channelConfig, targetConfig, command)`
416
+ 在堡垒机内部服务器上执行命令
417
+
418
+ - **参数**:
419
+ - `bastionSSH` (NodeSSH): 堡垒机 SSH 客户端实例
420
+ - `channelConfig` (BastionChannelConfig): 通道配置
421
+ - `targetConfig` (TargetSSHClientConfig): 目标服务器配置
422
+ - `command` (string): 要执行的命令
423
+ - **返回值**: `Promise<SSHExecCommandResponse>` - 命令执行结果
424
+
425
+ #### `makeDirectoryOnIntraServer(bastionSSH, channelConfig, targetConfig, config)`
426
+ 在堡垒机内部服务器上创建目录
427
+
428
+ - **参数**:
429
+ - `bastionSSH` (NodeSSH): 堡垒机 SSH 客户端实例
430
+ - `channelConfig` (BastionChannelConfig): 通道配置
431
+ - `targetConfig` (TargetSSHClientConfig): 目标服务器配置
432
+ - `config` (MakeDirectoryConfig): 目录创建配置
433
+ - **返回值**: `Promise<void>`
434
+
435
+ #### `putDirectoryToIntraServer(bastionSSH, channelConfig, targetConfig, config)`
436
+ 上传目录到堡垒机内部服务器
437
+
438
+ - **参数**:
439
+ - `bastionSSH` (NodeSSH): 堡垒机 SSH 客户端实例
440
+ - `channelConfig` (BastionChannelConfig): 通道配置
441
+ - `targetConfig` (TargetSSHClientConfig): 目标服务器配置
442
+ - `config` (UploadDownloadConfig): 上传配置
443
+ - **返回值**: `Promise<any>` - 上传结果
444
+
445
+ #### `getDirectoryFromIntraServer(bastionSSH, channelConfig, targetConfig, config)`
446
+ 从堡垒机内部服务器下载目录
447
+
448
+ - **参数**:
449
+ - `bastionSSH` (NodeSSH): 堡垒机 SSH 客户端实例
450
+ - `channelConfig` (BastionChannelConfig): 通道配置
451
+ - `targetConfig` (TargetSSHClientConfig): 目标服务器配置
452
+ - `config` (UploadDownloadConfig): 下载配置
453
+ - **返回값**: `Promise<any>` - 下载结果
454
+
455
+ ### 子进程工具函数 (childProcess.js)
456
+
457
+ #### `execCommandUnderDirectory(directory, command)`
458
+ 在指定目录下执行命令
459
+
460
+ - **参数**:
461
+ - `directory` (string): 目标目录
462
+ - `command` (string): 要执行的命令
463
+ - **返回值**: `Promise<any>` - 命令执行结果
464
+
465
+ #### `execProjectPNPMCommand(projectDir, command)`
466
+ 在项目目录下执行 pnpm 命令
467
+
468
+ - **参数**:
469
+ - `projectDir` (string): 项目目录
470
+ - `command` (string): pnpm 命令
471
+ - **返回값**: `Promise<any>` - 命令执行结果
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const dotenvx=require("@dotenvx/dotenvx"),utils_deployWindowsServer=require("./utils/deploy-windows-server.cjs"),utils_deployLinuxBastion=require("./utils/deploy-linux-bastion.cjs");dotenvx.config(),exports.deployToWindowsServer=utils_deployWindowsServer.deployToWindowsServer,exports.deployToLinuxBastionInternalServer=utils_deployLinuxBastion.deployToLinuxBastionInternalServer,exports.disableLinuxBastionHealthCheck=utils_deployLinuxBastion.disableLinuxBastionHealthCheck,exports.enableLinuxBastionHealthCheck=utils_deployLinuxBastion.enableLinuxBastionHealthCheck;
@@ -0,0 +1,3 @@
1
+ export { deployToWindowsServer } from './utils/deploy-windows-server.cjs';
2
+ export { deployToLinuxBastionInternalServer, disableLinuxBastionHealthCheck, enableLinuxBastionHealthCheck } from './utils/deploy-linux-bastion.cjs';
3
+ import 'node-ssh';
@@ -0,0 +1,3 @@
1
+ export { deployToWindowsServer } from './utils/deploy-windows-server.mjs';
2
+ export { deployToLinuxBastionInternalServer, disableLinuxBastionHealthCheck, enableLinuxBastionHealthCheck } from './utils/deploy-linux-bastion.mjs';
3
+ import 'node-ssh';
@@ -0,0 +1,3 @@
1
+ export { deployToWindowsServer } from './utils/deploy-windows-server.js';
2
+ export { deployToLinuxBastionInternalServer, disableLinuxBastionHealthCheck, enableLinuxBastionHealthCheck } from './utils/deploy-linux-bastion.js';
3
+ import 'node-ssh';
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{config as e}from"@dotenvx/dotenvx";export{deployToWindowsServer}from"./utils/deploy-windows-server.mjs";export{deployToLinuxBastionInternalServer,disableLinuxBastionHealthCheck,enableLinuxBastionHealthCheck}from"./utils/deploy-linux-bastion.mjs";e();
@@ -0,0 +1,67 @@
1
+ import type { SFTPWrapper } from 'ssh2'
2
+
3
+ export {};
4
+
5
+ declare global {
6
+
7
+ type Recordable<K extends string | number | symbol = string, T = any> = Record<
8
+ K extends null | undefined ? string : K,
9
+ T
10
+ >
11
+
12
+ interface SSHClientConfig {
13
+ host?: string
14
+ port?: number | string
15
+ username?: string
16
+ password?: string
17
+ privateKey?: string
18
+ [key: string]: any
19
+ }
20
+ interface BastionSSHClientConfig extends SSHClientConfig {
21
+ [key: string]: any
22
+ }
23
+ interface TargetSSHClientConfig extends SSHClientConfig {
24
+ localDeployDir?: string
25
+ localDownloadDir?: string
26
+
27
+ remoteBackupDir?: string
28
+ remoteDir?: string
29
+ remoteDirTemp?: string
30
+
31
+ remoteHealthDir?: string
32
+ remoteHideHealthFileDir?: string
33
+ remoteHealthFile?: string
34
+ remoteHealthHiddenFile?: string
35
+ [key: string]: any
36
+ }
37
+ interface BastionChannelConfig {
38
+ srcIP?: string
39
+ srcPort?: number | string
40
+ dstIP?: string
41
+ dstPort?: number | string
42
+ [key: string]: any
43
+ }
44
+ interface IntraServerSSHClientConfig {
45
+ username?: string
46
+ password?: string
47
+ [key: string]: any
48
+ }
49
+ interface UploadDownloadConfig {
50
+ localDir?: string
51
+ remoteDir?: string
52
+ [key: string]: any
53
+ }
54
+ interface MakeDirectoryConfig {
55
+ path: string
56
+ method?: 'sftp' | 'exec'
57
+ givenSftp?: SFTPWrapper
58
+ [key: string]: any
59
+ }
60
+
61
+ interface BuildConfig {
62
+ build?: boolean
63
+ mode?: string
64
+ projectDir?: string
65
+ [key: string]: any
66
+ }
67
+ }
@@ -0,0 +1 @@
1
+ "use strict";const u=require("fs/promises"),a=require("os"),f=require("iconv-lite"),child_process=require("child_process"),utils_logger=require("./logger.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const u__default=_interopDefaultCompat(u),a__default=_interopDefaultCompat(a),f__default=_interopDefaultCompat(f);async function renameDirectory(e,o){try{utils_logger.logger.info(`\u5F00\u59CB\u91CD\u547D\u540D\u6587\u4EF6\u5939: ${e} -> ${o}`),await u__default.rename(e,o),utils_logger.logger.info(`\u6587\u4EF6\u5939\u91CD\u547D\u540D\u5B8C\u6210: ${e} -> ${o}`)}catch(r){throw utils_logger.logger.error(`\u91CD\u547D\u540D\u6587\u4EF6\u5939\u5931\u8D25: ${e} -> ${o}`,r),r}}async function execCommand(e,o={}){return new Promise((r,i)=>{const c=a__default.platform()==="win32",s={cwd:process.cwd(),encoding:c?"buffer":"utf8",...o};try{utils_logger.logger.info(`\u6267\u884C\u547D\u4EE4 ${e}`),child_process.exec(e,s,function(d,t,n){c&&(Buffer.isBuffer(t)?t=f__default.decode(t,"GBK"):t=t.toString(),Buffer.isBuffer(n)?n=f__default.decode(n,"GBK"):n=n.toString()),utils_logger.logger.info(`\u6267\u884C\u547D\u4EE4 ${e} \u5B8C\u6210`),n&&utils_logger.logger.error(`\u6267\u884C\u547D\u4EE4 ${e} \u53D1\u751F\u5F02\u5E38`,n),r({stdout:t,stderr:n})})}catch(d){i(d)}})}async function execCDCommand(e){const o=`cd ${e}`;return execCommand(o)}async function execPNPMCommand(e,o){const r=`pnpm ${e}`;return execCommand(r,{cwd:o})}async function execProjectPNPMCommand(e,o){return execPNPMCommand(o,e)}async function execCommandUnderDirectory(e,o){return execCommand(o,{cwd:e})}async function spawnCommand(e,o=[],r={}){return new Promise((i,c)=>{const s=a__default.platform()==="win32",d={cwd:process.cwd(),shell:!0,...r};try{utils_logger.logger.info(`\u6267\u884C\u547D\u4EE4 ${e}`);const t=child_process.spawn(e,[...o],d);t.stdout.on("data",n=>{s&&(n=f__default.decode(n,"GBK")),console.info("stdout: ",n)}),t.stderr.on("data",n=>{s&&(n=f__default.decode(n,"GBK")),console.error("stderr: ",n),c(n)}),t.on("close",n=>{console.info(`child process exited with code ${n}`),i(`close with code ${n}`)})}catch(t){c(t)}})}async function spawnCDCommand(e){return spawnCommand("cd",[e])}async function spawnPNPMCommand(e,o){return spawnCommand("pnpm",[e],{cwd:o})}async function spawnProjectPNPMCommand(e,o){return execPNPMCommand(o,e)}async function spawnCommandUnderDirectory(e,o,r=[]){return spawnCommand(o,[...r],{cwd:e})}exports.execCDCommand=execCDCommand,exports.execCommand=execCommand,exports.execCommandUnderDirectory=execCommandUnderDirectory,exports.execPNPMCommand=execPNPMCommand,exports.execProjectPNPMCommand=execProjectPNPMCommand,exports.renameDirectory=renameDirectory,exports.spawnCDCommand=spawnCDCommand,exports.spawnCommand=spawnCommand,exports.spawnCommandUnderDirectory=spawnCommandUnderDirectory,exports.spawnPNPMCommand=spawnPNPMCommand,exports.spawnProjectPNPMCommand=spawnProjectPNPMCommand;
@@ -0,0 +1,103 @@
1
+ import { ExecOptions, SpawnOptions } from 'child_process';
2
+
3
+ /**
4
+ * @author: ares
5
+ * @date: 2025/8/29 下午4:10
6
+ * @description: 使用fs.rename重命名文件夹
7
+ * @param oldPath 原文件夹路径
8
+ * @param newPath 新文件夹路径
9
+ * @returns {Promise<void>}
10
+ */
11
+ declare function renameDirectory(oldPath: string, newPath: string): Promise<void>;
12
+ /**
13
+ * @author: ares
14
+ * @date: 2025/8/28 下午1:34
15
+ * @description: 用exec执行命令
16
+ * @param command
17
+ * @param config
18
+ * @returns {Promise<*>}
19
+ */
20
+ declare function execCommand(command: string, config?: ExecOptions): Promise<any>;
21
+ /**
22
+ * @author: ares
23
+ * @date: 2025/8/28 下午1:27
24
+ * @description: 用exec执行CD命令
25
+ * @param path
26
+ * @returns {Promise<*>}
27
+ */
28
+ declare function execCDCommand(path: string): Promise<any>;
29
+ /**
30
+ * @author: ares
31
+ * @date: 2025/8/28 下午1:27
32
+ * @description: 用exec执行PNPM命令
33
+ * @param script
34
+ * @param projectDir
35
+ * @returns {Promise<*>}
36
+ */
37
+ declare function execPNPMCommand(script: string, projectDir: string): Promise<any>;
38
+ /**
39
+ * @author: ares
40
+ * @date: 2025/8/28 下午1:27
41
+ * @description: 用exec执行项目的PNPM命令
42
+ * @param projectDir
43
+ * @param script
44
+ * @returns {Promise<*>}
45
+ */
46
+ declare function execProjectPNPMCommand(projectDir: string, script: string): Promise<any>;
47
+ /**
48
+ * @author: ares
49
+ * @date: 2025/8/28 下午1:42
50
+ * @description: 在指定目录下用exec执行命令
51
+ * @param dir
52
+ * @param command
53
+ * @returns {Promise<*>}
54
+ */
55
+ declare function execCommandUnderDirectory(dir: string, command: string): Promise<any>;
56
+ /**
57
+ * @author: ares
58
+ * @date: 2025/8/28 下午2:49
59
+ * @description: 用spawn执行命令
60
+ * @param command
61
+ * @param args
62
+ * @param config
63
+ * @returns {Promise<*>}
64
+ */
65
+ declare function spawnCommand(command: any, args?: string[], config?: SpawnOptions): Promise<any>;
66
+ /**
67
+ * @author: ares
68
+ * @date: 2025/8/28 下午1:27
69
+ * @description: 用spawn执行CD命令
70
+ * @param path
71
+ * @returns {Promise<*>}
72
+ */
73
+ declare function spawnCDCommand(path: string): Promise<any>;
74
+ /**
75
+ * @author: ares
76
+ * @date: 2025/8/28 下午1:27
77
+ * @description: 执行PNPM命令
78
+ * @param script
79
+ * @param projectDir
80
+ * @returns {Promise<*>}
81
+ */
82
+ declare function spawnPNPMCommand(script: string, projectDir: string): Promise<any>;
83
+ /**
84
+ * @author: ares
85
+ * @date: 2025/8/28 下午1:27
86
+ * @description: 用spawn执行项目的PNPM命令
87
+ * @param projectDir
88
+ * @param script
89
+ * @returns {Promise<*>}
90
+ */
91
+ declare function spawnProjectPNPMCommand(projectDir: string, script: string): Promise<any>;
92
+ /**
93
+ * @author: ares
94
+ * @date: 2025/8/28 下午1:42
95
+ * @description: 在指定目录下用spawn执行命令
96
+ * @param dir
97
+ * @param command
98
+ * @param args
99
+ * @returns {Promise<*>}
100
+ */
101
+ declare function spawnCommandUnderDirectory(dir: string, command: string, args?: string[]): Promise<any>;
102
+
103
+ export { execCDCommand, execCommand, execCommandUnderDirectory, execPNPMCommand, execProjectPNPMCommand, renameDirectory, spawnCDCommand, spawnCommand, spawnCommandUnderDirectory, spawnPNPMCommand, spawnProjectPNPMCommand };