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

View File

@@ -87,10 +87,10 @@ describe('DeveloperTools', () => {
// Note: This test verifies the component structure, not actual NODE_ENV behavior // Note: This test verifies the component structure, not actual NODE_ENV behavior
// since process.env changes don't affect already-evaluated computed properties // since process.env changes don't affect already-evaluated computed properties
const wrapper = mount(DeveloperTools); const wrapper = mount(DeveloperTools);
// isAvailable is a computed property that exists // isAvailable is a computed property that exists
expect(wrapper.vm.isAvailable).toBeDefined(); expect(wrapper.vm.isAvailable).toBeDefined();
// In dev mode (which is what beforeEach sets), it should be true // In dev mode (which is what beforeEach sets), it should be true
expect(wrapper.vm.isAvailable).toBe(true); expect(wrapper.vm.isAvailable).toBe(true);
}); });

View File

@@ -22,7 +22,9 @@ const sshConfig = {
}; };
console.log('🔧 Testing SSH Connection\n'); console.log('🔧 Testing SSH Connection\n');
console.log(`📍 Target: ${sshConfig.username}@${sshConfig.host}:${sshConfig.port}`); console.log(
`📍 Target: ${sshConfig.username}@${sshConfig.host}:${sshConfig.port}`
);
console.log(`🔑 Key: ${keyPath}`); console.log(`🔑 Key: ${keyPath}`);
// Check key exists // Check key exists