@noahyu/cd-cli 1.1.0 → 1.1.1
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 +13 -3
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -75,8 +75,10 @@ async function deploy(config) {
|
|
|
75
75
|
spinner.succeed('服务器连接成功');
|
|
76
76
|
await cleanTempLinks(ssh, config.server.deployPath, buildDirName);
|
|
77
77
|
spinner.start('检查部署环境...');
|
|
78
|
-
await handleExistingDeployDir(ssh, config.server.deployPath, buildDirName);
|
|
79
|
-
spinner.
|
|
78
|
+
await handleExistingDeployDir(ssh, config.server.deployPath, buildDirName, spinner);
|
|
79
|
+
if (spinner.isSpinning) {
|
|
80
|
+
spinner.succeed('部署环境检查完成');
|
|
81
|
+
}
|
|
80
82
|
const versionDirName = `${buildDirName}-${version}`;
|
|
81
83
|
const versionPath = join(config.server.deployPath, versionDirName);
|
|
82
84
|
const currentLinkPath = join(config.server.deployPath, buildDirName);
|
|
@@ -486,7 +488,7 @@ async function cleanTempLinks(ssh, deployPath, buildDirName) {
|
|
|
486
488
|
console.warn(chalk.yellow(`⚠️ 清理临时链接时出现警告: ${error}`));
|
|
487
489
|
}
|
|
488
490
|
}
|
|
489
|
-
async function handleExistingDeployDir(ssh, deployPath, buildDirName) {
|
|
491
|
+
async function handleExistingDeployDir(ssh, deployPath, buildDirName, spinner) {
|
|
490
492
|
const currentLinkPath = join(deployPath, buildDirName);
|
|
491
493
|
const checkResult = await ssh.execCommand(`test -e ${currentLinkPath}`);
|
|
492
494
|
if (checkResult.code !== 0) {
|
|
@@ -500,6 +502,7 @@ async function handleExistingDeployDir(ssh, deployPath, buildDirName) {
|
|
|
500
502
|
const fileType = typeResult.stdout.trim();
|
|
501
503
|
if (fileType.includes('directory') || fileType === 'directory') {
|
|
502
504
|
const backupPath = `${currentLinkPath}.backup.${Date.now()}`;
|
|
505
|
+
spinner.stop();
|
|
503
506
|
console.log(chalk.yellow(`⚠️ 检测到已存在的目录: ${currentLinkPath}`));
|
|
504
507
|
console.log(chalk.blue(`📁 将备份到: ${backupPath}`));
|
|
505
508
|
const answers = await inquirer.prompt([
|
|
@@ -513,18 +516,25 @@ async function handleExistingDeployDir(ssh, deployPath, buildDirName) {
|
|
|
513
516
|
if (!answers.proceed) {
|
|
514
517
|
throw new Error('用户取消部署');
|
|
515
518
|
}
|
|
519
|
+
spinner.start('正在备份已存在的目录...');
|
|
516
520
|
const backupResult = await ssh.execCommand(`mv ${currentLinkPath} ${backupPath}`);
|
|
517
521
|
if (backupResult.code !== 0) {
|
|
518
522
|
throw new Error(`备份目录失败: ${backupResult.stderr}`);
|
|
519
523
|
}
|
|
524
|
+
spinner.stop();
|
|
520
525
|
console.log(chalk.green(`✅ 目录已备份到: ${backupPath}`));
|
|
521
526
|
}
|
|
522
527
|
else {
|
|
523
528
|
const backupPath = `${currentLinkPath}.backup.${Date.now()}`;
|
|
529
|
+
spinner.stop();
|
|
530
|
+
console.log(chalk.yellow(`⚠️ 检测到已存在的文件: ${currentLinkPath}`));
|
|
531
|
+
console.log(chalk.blue(`📁 将备份到: ${backupPath}`));
|
|
532
|
+
spinner.start('正在备份已存在的文件...');
|
|
524
533
|
const backupResult = await ssh.execCommand(`mv ${currentLinkPath} ${backupPath}`);
|
|
525
534
|
if (backupResult.code !== 0) {
|
|
526
535
|
throw new Error(`备份文件失败: ${backupResult.stderr}`);
|
|
527
536
|
}
|
|
537
|
+
spinner.stop();
|
|
528
538
|
console.log(chalk.green(`✅ 文件已备份到: ${backupPath}`));
|
|
529
539
|
}
|
|
530
540
|
}
|