🎨 Clean up code formatting and improve readability in deployment script

This commit is contained in:
2026-01-28 05:24:11 +00:00
parent 2206191fd9
commit 02c5a9a9c1

View File

@@ -217,30 +217,30 @@ async function deploy() {
console.log('\n🔨 Building Vue 3 application...'); console.log('\n🔨 Building Vue 3 application...');
console.log(` Source: ${SOURCE_DIR}`); console.log(` Source: ${SOURCE_DIR}`);
console.log(` Output: ${DIST_DIR}`); console.log(` Output: ${DIST_DIR}`);
const { execSync } = await import('child_process'); const { execSync } = await import('child_process');
try { try {
// Check if node_modules exists // Check if node_modules exists
if (!fs.existsSync(path.join(SOURCE_DIR, 'node_modules'))) { if (!fs.existsSync(path.join(SOURCE_DIR, 'node_modules'))) {
console.log(' 📦 Installing dependencies...'); console.log(' 📦 Installing dependencies...');
execSync('npm install', { execSync('npm install', {
cwd: SOURCE_DIR, cwd: SOURCE_DIR,
stdio: 'inherit' stdio: 'inherit'
}); });
} }
// Build the application // Build the application
console.log(' ⚙️ Running build...'); console.log(' ⚙️ Running build...');
execSync('npm run build', { execSync('npm run build', {
cwd: SOURCE_DIR, cwd: SOURCE_DIR,
stdio: 'inherit' stdio: 'inherit'
}); });
// Verify dist directory exists // Verify dist directory exists
if (!fs.existsSync(DIST_DIR)) { if (!fs.existsSync(DIST_DIR)) {
throw new Error('Build failed - dist directory not found'); throw new Error('Build failed - dist directory not found');
} }
console.log(' ✅ Build completed successfully'); console.log(' ✅ Build completed successfully');
} catch (error) { } catch (error) {
throw new Error(`Build failed: ${error.message}`); throw new Error(`Build failed: ${error.message}`);
@@ -292,11 +292,11 @@ async function deploy() {
// Transfer files // Transfer files
console.log('\n📤 Transferring files...'); console.log('\n📤 Transferring files...');
// First transfer the dist directory // First transfer the dist directory
console.log(' 📦 Transferring dist directory...'); console.log(' 📦 Transferring dist directory...');
const distFiles = []; const distFiles = [];
function getDistFiles(dir, baseDir = DIST_DIR) { function getDistFiles(dir, baseDir = DIST_DIR) {
const files = fs.readdirSync(dir, { withFileTypes: true }); const files = fs.readdirSync(dir, { withFileTypes: true });
for (const file of files) { for (const file of files) {
@@ -312,13 +312,13 @@ async function deploy() {
} }
} }
} }
getDistFiles(DIST_DIR); getDistFiles(DIST_DIR);
console.log(` Found ${distFiles.length} files in dist/`); console.log(` Found ${distFiles.length} files in dist/`);
// Create dist directory on remote // Create dist directory on remote
await ssh.execCommand(`mkdir -p ${REMOTE_PATH}/dist`); await ssh.execCommand(`mkdir -p ${REMOTE_PATH}/dist`);
// Transfer dist files // Transfer dist files
let transferred = 0; let transferred = 0;
for (const file of distFiles) { for (const file of distFiles) {
@@ -329,14 +329,18 @@ async function deploy() {
await ssh.putFile(file.local, file.remote); await ssh.putFile(file.local, file.remote);
transferred++; transferred++;
if (transferred % 10 === 0) { if (transferred % 10 === 0) {
console.log(` 📁 Transferred ${transferred}/${distFiles.length} files...`); console.log(
` 📁 Transferred ${transferred}/${distFiles.length} files...`
);
} }
} catch (error) { } catch (error) {
console.log(` ⚠️ Failed to transfer ${path.relative(DIST_DIR, file.local)}: ${error.message}`); console.log(
` ⚠️ Failed to transfer ${path.relative(DIST_DIR, file.local)}: ${error.message}`
);
} }
} }
console.log(` ✅ Transferred ${transferred} files from dist/`); console.log(` ✅ Transferred ${transferred} files from dist/`);
// Now transfer config files // Now transfer config files
const filesToTransfer = [ const filesToTransfer = [
{ {