🛠️ Improve code readability by reformatting console logs and removing unnecessary whitespace

This commit is contained in:
2026-01-30 04:53:23 +00:00
parent 9fdfbb22d8
commit 52cf322a00
3 changed files with 32 additions and 22 deletions

View File

@@ -223,22 +223,24 @@ async function deploy() {
console.log('\n🔐 Connecting to Synology...');
const keyPath = expandTilde(sshConfig.privateKeyPath);
console.log(` 🔑 Using SSH key: ${keyPath}`);
console.log(` 📍 Target: ${sshConfig.username}@${sshConfig.host}:${sshConfig.port}`);
console.log(
` 📍 Target: ${sshConfig.username}@${sshConfig.host}:${sshConfig.port}`
);
// Verify key file exists
if (!fs.existsSync(keyPath)) {
throw new Error(`SSH key file not found: ${keyPath}`);
}
try {
const privateKeyContent = fs.readFileSync(keyPath, 'utf8');
const keySize = privateKeyContent.length;
console.log(` 📂 Key file size: ${keySize} bytes`);
if (keySize === 0) {
throw new Error('SSH key file is empty');
}
// Use node-ssh with private key directly
await ssh.connect({
host: sshConfig.host,
@@ -253,13 +255,21 @@ async function deploy() {
console.error('\n❌ SSH Connection Failed');
console.error(`Error: ${connError.message}`);
console.error('\nPossible causes:');
console.error('1. SSH public key not added to ~/.ssh/authorized_keys on the server');
console.error(
'1. SSH public key not added to ~/.ssh/authorized_keys on the server'
);
console.error('2. SSH key has wrong permissions (should be 600)');
console.error('3. SSH user home directory permissions are wrong');
console.error('\nVerify the key works manually:');
console.error(` ssh -i ${keyPath} ${sshConfig.username}@${sshConfig.host} -p ${sshConfig.port} "whoami"`);
console.error('\nIf that fails, the public key needs to be added on the server:');
console.error(` cat ~/.ssh/${path.basename(keyPath)}.pub | ssh ${sshConfig.username}@${sshConfig.host} -p ${sshConfig.port} "cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"`);
console.error(
` ssh -i ${keyPath} ${sshConfig.username}@${sshConfig.host} -p ${sshConfig.port} "whoami"`
);
console.error(
'\nIf that fails, the public key needs to be added on the server:'
);
console.error(
` cat ~/.ssh/${path.basename(keyPath)}.pub | ssh ${sshConfig.username}@${sshConfig.host} -p ${sshConfig.port} "cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"`
);
throw new Error(`SSH connection failed: ${connError.message}`);
}
@@ -346,7 +356,7 @@ async function deploy() {
// First transfer the dist directory
console.log(' 📦 Transferring dist directory...');
// Count files for reporting
let fileCount = 0;
function countFiles(dir) {
@@ -369,16 +379,16 @@ async function deploy() {
// Transfer dist directory using rsync
try {
console.log(` 📡 Transferring dist directory via rsync...`);
const { execSync } = await import('child_process');
const expandedKeyPath = expandTilde(sshConfig.privateKeyPath);
// Use rsync with SSH for reliable transfer
// Key options:
// - IdentitiesOnly=yes: Only use specified key, not ssh-agent keys
// - rsync-path: Ensure we use the correct rsync binary on remote
const rsyncCmd = `rsync -av --delete -e "ssh -p ${sshConfig.port} -i ${expandedKeyPath} -o StrictHostKeyChecking=no -o IdentitiesOnly=yes" "${DIST_DIR}/" "${sshConfig.username}@${sshConfig.host}:${REMOTE_PATH}/dist/" --rsync-path="/usr/bin/rsync"`;
try {
execSync(rsyncCmd, {
stdio: 'inherit',
@@ -402,16 +412,16 @@ async function deploy() {
// Use rsync for server files with exclusions
try {
console.log(` 📡 Transferring server files via rsync...`);
const { execSync } = await import('child_process');
const expandedKeyPath = expandTilde(sshConfig.privateKeyPath);
// Use rsync with SSH for reliable transfer and exclusions
// Key options:
// - IdentitiesOnly=yes: Only use specified key, not ssh-agent keys
// - rsync-path: Ensure we use the correct rsync binary on remote
const rsyncCmd = `rsync -av --delete --exclude='node_modules' --exclude='tests' --exclude='.git' --exclude='dist' --exclude='build' -e "ssh -p ${sshConfig.port} -i ${expandedKeyPath} -o StrictHostKeyChecking=no -o IdentitiesOnly=yes" "${serverDir}/" "${sshConfig.username}@${sshConfig.host}:${REMOTE_PATH}/server/" --rsync-path="/usr/bin/rsync"`;
try {
execSync(rsyncCmd, {
stdio: 'inherit',
@@ -461,9 +471,7 @@ async function deploy() {
`Failed to transfer ${fileName}: ${catResult.stderr}`
);
}
console.log(
`${fileName} (${fs.statSync(file.local).size} bytes)`
);
console.log(`${fileName} (${fs.statSync(file.local).size} bytes)`);
} catch (error) {
throw new Error(`Failed to transfer ${fileName}: ${error.message}`);
}