|
@@ -3,13 +3,17 @@ const { isNullES } = require('js-fast-way')
|
|
|
|
|
|
//获取参数
|
|
//获取参数
|
|
const args = process.argv[2]
|
|
const args = process.argv[2]
|
|
-const serverIp = process.argv[3]
|
|
|
|
|
|
+const serverAddress = process.argv[3]
|
|
const username = process.argv[4]
|
|
const username = process.argv[4]
|
|
const password = process.argv[5]
|
|
const password = process.argv[5]
|
|
const fileName = process.argv[6]
|
|
const fileName = process.argv[6]
|
|
const filePath = process.argv[7]
|
|
const filePath = process.argv[7]
|
|
const url = process.argv[8]
|
|
const url = process.argv[8]
|
|
|
|
|
|
|
|
+// 解析服务器地址和端口
|
|
|
|
+const [serverIp, port] = serverAddress.split(':');
|
|
|
|
+const sshPort = port || '22'; // 如果没有指定端口,默认使用22
|
|
|
|
+
|
|
// 检查命令是否可用
|
|
// 检查命令是否可用
|
|
function commandExists(command) {
|
|
function commandExists(command) {
|
|
try {
|
|
try {
|
|
@@ -40,12 +44,12 @@ function uploadServer() {
|
|
const sshCommand = `cd ${filePath} && rm -rf static && unzip -o ${fileName}`;
|
|
const sshCommand = `cd ${filePath} && rm -rf static && unzip -o ${fileName}`;
|
|
if (process.platform === 'win32') {
|
|
if (process.platform === 'win32') {
|
|
// Windows
|
|
// Windows
|
|
- runCommand(`pscp -pw ${password} ./zip/${fileName} ${username}@${serverIp}:${filePath}`);
|
|
|
|
- runCommand(`plink -ssh ${username}@${serverIp} -pw ${password} -batch "${sshCommand}"`);
|
|
|
|
|
|
+ runCommand(`pscp -P ${sshPort} -pw ${password} ./zip/${fileName} ${username}@${serverIp}:${filePath}`);
|
|
|
|
+ runCommand(`plink -P ${sshPort} -ssh ${username}@${serverIp} -pw ${password} -batch "${sshCommand}"`);
|
|
} else {
|
|
} else {
|
|
// Mac/Linux
|
|
// Mac/Linux
|
|
- runCommand(`sshpass -p "${password}" scp ./zip/${fileName} ${username}@${serverIp}:${filePath}`);
|
|
|
|
- runCommand(`sshpass -p "${password}" ssh ${username}@${serverIp} "${sshCommand}"`);
|
|
|
|
|
|
+ runCommand(`sshpass -p "${password}" scp -P ${sshPort} ./zip/${fileName} ${username}@${serverIp}:${filePath}`);
|
|
|
|
+ runCommand(`sshpass -p "${password}" ssh -p ${sshPort} ${username}@${serverIp} "${sshCommand}"`);
|
|
}
|
|
}
|
|
console.log('编译打包后自动部署到服务器上完成');
|
|
console.log('编译打包后自动部署到服务器上完成');
|
|
console.log(`服务器上的地址:${url}`);
|
|
console.log(`服务器上的地址:${url}`);
|
|
@@ -57,10 +61,10 @@ function delPublic() {
|
|
const sshCommand = `cd ${filePath} && rm -rf plugins`;
|
|
const sshCommand = `cd ${filePath} && rm -rf plugins`;
|
|
if (process.platform === 'win32') {
|
|
if (process.platform === 'win32') {
|
|
// Windows
|
|
// Windows
|
|
- runCommand(`plink -ssh ${username}@${serverIp} -pw ${password} -batch "${sshCommand}"`);
|
|
|
|
|
|
+ runCommand(`plink -P ${sshPort} -ssh ${username}@${serverIp} -pw ${password} -batch "${sshCommand}"`);
|
|
} else {
|
|
} else {
|
|
// Mac/Linux
|
|
// Mac/Linux
|
|
- runCommand(`sshpass -p "${password}" ssh ${username}@${serverIp} "${sshCommand}"`);
|
|
|
|
|
|
+ runCommand(`sshpass -p "${password}" ssh -p ${sshPort} ${username}@${serverIp} "${sshCommand}"`);
|
|
}
|
|
}
|
|
console.log('plugins 等目录移除完成');
|
|
console.log('plugins 等目录移除完成');
|
|
}
|
|
}
|