@noahyu/cd-cli 1.3.4 → 1.3.6
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.
- package/dist/src/index.js +14 -12
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -145,15 +145,7 @@ async function deploy(config, version) {
|
|
|
145
145
|
if (config.afterDeploy) {
|
|
146
146
|
for (const cmd of config.afterDeploy) {
|
|
147
147
|
spinner.start(`执行部署后命令: ${cmd}`);
|
|
148
|
-
const
|
|
149
|
-
'[ -f /etc/profile ] && . /etc/profile 2>/dev/null || true',
|
|
150
|
-
'[ -f ~/.bash_profile ] && . ~/.bash_profile 2>/dev/null || true',
|
|
151
|
-
'[ -f ~/.bashrc ] && . ~/.bashrc 2>/dev/null || true',
|
|
152
|
-
cmd,
|
|
153
|
-
].join('; ');
|
|
154
|
-
const result = await ssh.execCommand(`bash -c ${JSON.stringify(wrappedCmd)}`, {
|
|
155
|
-
cwd: config.server.deployPath,
|
|
156
|
-
});
|
|
148
|
+
const result = await execNodeCommand(ssh, cmd, { cwd: config.server.deployPath });
|
|
157
149
|
if (result.stdout) {
|
|
158
150
|
spinner.stop();
|
|
159
151
|
console.log(result.stdout);
|
|
@@ -191,12 +183,12 @@ async function deploy(config, version) {
|
|
|
191
183
|
const { appName, restart = true } = config.pm2;
|
|
192
184
|
if (restart) {
|
|
193
185
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
194
|
-
const result = await ssh
|
|
186
|
+
const result = await execNodeCommand(ssh, `pm2 restart ${appName}`);
|
|
195
187
|
if (result.code === 0) {
|
|
196
188
|
spinner.succeed('PM2 应用重启成功');
|
|
197
189
|
}
|
|
198
190
|
else {
|
|
199
|
-
const startResult = await ssh
|
|
191
|
+
const startResult = await execNodeCommand(ssh, `pm2 start ${appName}`);
|
|
200
192
|
if (startResult.code === 0) {
|
|
201
193
|
spinner.succeed('PM2 应用启动成功');
|
|
202
194
|
}
|
|
@@ -513,7 +505,7 @@ async function performRollback(config, targetVersion, buildDirName) {
|
|
|
513
505
|
spinner.start('正在重启 PM2 应用...');
|
|
514
506
|
const { appName } = config.pm2;
|
|
515
507
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
516
|
-
const result = await ssh
|
|
508
|
+
const result = await execNodeCommand(ssh, `pm2 restart ${appName}`);
|
|
517
509
|
if (result.code === 0) {
|
|
518
510
|
spinner.succeed('PM2 应用重启成功');
|
|
519
511
|
}
|
|
@@ -633,6 +625,16 @@ async function createSSHConnection(server) {
|
|
|
633
625
|
throw new Error(`SSH 连接失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
634
626
|
}
|
|
635
627
|
}
|
|
628
|
+
async function execNodeCommand(ssh, cmd, options) {
|
|
629
|
+
const inner = [
|
|
630
|
+
'export PS1="x"',
|
|
631
|
+
'[ -f /etc/profile ] && . /etc/profile 2>/dev/null || true',
|
|
632
|
+
'[ -f ~/.bash_profile ] && . ~/.bash_profile 2>/dev/null || true',
|
|
633
|
+
'[ -f ~/.bashrc ] && . ~/.bashrc 2>/dev/null || true',
|
|
634
|
+
cmd,
|
|
635
|
+
].join('; ');
|
|
636
|
+
return ssh.execCommand(`bash -l -c ${JSON.stringify(inner)}`, options);
|
|
637
|
+
}
|
|
636
638
|
async function cleanTempLinks(ssh, deployPath, buildDirName) {
|
|
637
639
|
try {
|
|
638
640
|
const result = await ssh.execCommand(`find ${deployPath} -name "${buildDirName}.tmp.*" -type l -delete`);
|