@noahyu/cd-cli 1.3.5 → 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.
Files changed (2) hide show
  1. package/dist/src/index.js +14 -13
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -145,16 +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 inner = [
149
- 'export PS1="x"',
150
- '[ -f /etc/profile ] && . /etc/profile 2>/dev/null || true',
151
- '[ -f ~/.bash_profile ] && . ~/.bash_profile 2>/dev/null || true',
152
- '[ -f ~/.bashrc ] && . ~/.bashrc 2>/dev/null || true',
153
- cmd,
154
- ].join('; ');
155
- const result = await ssh.execCommand(`bash -l -c ${JSON.stringify(inner)}`, {
156
- cwd: config.server.deployPath,
157
- });
148
+ const result = await execNodeCommand(ssh, cmd, { cwd: config.server.deployPath });
158
149
  if (result.stdout) {
159
150
  spinner.stop();
160
151
  console.log(result.stdout);
@@ -192,12 +183,12 @@ async function deploy(config, version) {
192
183
  const { appName, restart = true } = config.pm2;
193
184
  if (restart) {
194
185
  await new Promise((resolve) => setTimeout(resolve, 1000));
195
- const result = await ssh.execCommand(`pm2 restart ${appName}`);
186
+ const result = await execNodeCommand(ssh, `pm2 restart ${appName}`);
196
187
  if (result.code === 0) {
197
188
  spinner.succeed('PM2 应用重启成功');
198
189
  }
199
190
  else {
200
- const startResult = await ssh.execCommand(`pm2 start ${appName}`);
191
+ const startResult = await execNodeCommand(ssh, `pm2 start ${appName}`);
201
192
  if (startResult.code === 0) {
202
193
  spinner.succeed('PM2 应用启动成功');
203
194
  }
@@ -514,7 +505,7 @@ async function performRollback(config, targetVersion, buildDirName) {
514
505
  spinner.start('正在重启 PM2 应用...');
515
506
  const { appName } = config.pm2;
516
507
  await new Promise((resolve) => setTimeout(resolve, 1000));
517
- const result = await ssh.execCommand(`pm2 restart ${appName}`);
508
+ const result = await execNodeCommand(ssh, `pm2 restart ${appName}`);
518
509
  if (result.code === 0) {
519
510
  spinner.succeed('PM2 应用重启成功');
520
511
  }
@@ -634,6 +625,16 @@ async function createSSHConnection(server) {
634
625
  throw new Error(`SSH 连接失败: ${error instanceof Error ? error.message : String(error)}`);
635
626
  }
636
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
+ }
637
638
  async function cleanTempLinks(ssh, deployPath, buildDirName) {
638
639
  try {
639
640
  const result = await ssh.execCommand(`find ${deployPath} -name "${buildDirName}.tmp.*" -type l -delete`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noahyu/cd-cli",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "description": "Global CLI tool for simple project deployment with version management",
5
5
  "type": "module",
6
6
  "main": "./dist/bin/cli.js",