Skip to content

Commit

Permalink
feat deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
huyilin666 committed Dec 28, 2024
1 parent dd54ffd commit 7b51998
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 20 deletions.
55 changes: 55 additions & 0 deletions docs/.vitepress/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import scpClient from 'scp2';
import ora from 'ora';
import readline from 'readline';
import fs from 'fs';

const deploy = () => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question('请输入服务器密码:', (password) => {
const server = {
host: '8.141.86.20', // 服务器IP
port: 22, // 服务器端口
username: 'root', // 服务器ssh登录用户名
password: password, // 服务器ssh登录密码
path: '/www/wwwroot/my-blog', // 服务器web目录
readyTimeout: 20000, // SSH 连接超时
algorithms: {
kex: ['diffie-hellman-group-exchange-sha256'], // 使用与服务器匹配的密钥交换算法
},
hostKeys: ['ssh-rsa', 'ssh-ed25519', 'rsa-sha2-512'], // 明确指定支持的主机密钥格式
debug: (message) => {
console.log('SSH Debug:', message); // 打印 SSH 调试信息
},
};

const loading = ora(`正在部署至 ${server.host}`);
loading.start();

const distPath = './dist/';
if (!fs.existsSync(distPath) || !fs.readdirSync(distPath).length) {
console.log('本地 dist/ 目录为空或不存在');
loading.stop();
rl.close();
return;
}

scpClient.scp(distPath, server, (err) => {
loading.stop();
if (err) {
console.error('部署失败:', err);
console.log('密码错误,请重新输入');
rl.close();
deploy();
} else {
console.log('部署成功');
rl.close();
}
});
});
};

deploy();
Loading

0 comments on commit 7b51998

Please sign in to comment.