From 2206191fd90b12f54a7f6311c1a2acda912f86a5 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Wed, 28 Jan 2026 05:24:06 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Add=20Vue=203=20build=20process?= =?UTF-8?q?=20and=20dist=20directory=20transfer=20to=20deployment=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/utils/deploy-pokedex.js | 86 +++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/code/utils/deploy-pokedex.js b/code/utils/deploy-pokedex.js index 6c76717..63e0de7 100644 --- a/code/utils/deploy-pokedex.js +++ b/code/utils/deploy-pokedex.js @@ -47,7 +47,8 @@ const SSH_HOSTS = { const REMOTE_PATH = '/volume1/docker/pokedex-online/base'; const CONTAINER_NAME = 'pokedex-online'; -const SOURCE_DIR = path.resolve(__dirname, '../websites/pokedex.online/apps'); +const SOURCE_DIR = path.resolve(__dirname, '../websites/pokedex.online'); +const DIST_DIR = path.join(SOURCE_DIR, 'dist'); /** * Parse command line arguments @@ -212,6 +213,39 @@ async function deploy() { }); console.log('āœ… Connected successfully'); + // Build Vue 3 application + console.log('\nšŸ”Ø Building Vue 3 application...'); + console.log(` Source: ${SOURCE_DIR}`); + console.log(` Output: ${DIST_DIR}`); + + const { execSync } = await import('child_process'); + try { + // Check if node_modules exists + if (!fs.existsSync(path.join(SOURCE_DIR, 'node_modules'))) { + console.log(' šŸ“¦ Installing dependencies...'); + execSync('npm install', { + cwd: SOURCE_DIR, + stdio: 'inherit' + }); + } + + // Build the application + console.log(' āš™ļø Running build...'); + execSync('npm run build', { + cwd: SOURCE_DIR, + stdio: 'inherit' + }); + + // Verify dist directory exists + if (!fs.existsSync(DIST_DIR)) { + throw new Error('Build failed - dist directory not found'); + } + + console.log(' āœ… Build completed successfully'); + } catch (error) { + throw new Error(`Build failed: ${error.message}`); + } + // Check if container exists and capture current image console.log('\nšŸ“¦ Checking for existing container...'); console.log(` Container name: ${CONTAINER_NAME}`); @@ -258,11 +292,53 @@ async function deploy() { // Transfer files console.log('\nšŸ“¤ Transferring files...'); + + // First transfer the dist directory + console.log(' šŸ“¦ Transferring dist directory...'); + const distFiles = []; + + function getDistFiles(dir, baseDir = DIST_DIR) { + const files = fs.readdirSync(dir, { withFileTypes: true }); + for (const file of files) { + const fullPath = path.join(dir, file.name); + if (file.isDirectory()) { + getDistFiles(fullPath, baseDir); + } else { + const relativePath = path.relative(baseDir, fullPath); + distFiles.push({ + local: fullPath, + remote: `${REMOTE_PATH}/dist/${relativePath.replace(/\\/g, '/')}` + }); + } + } + } + + getDistFiles(DIST_DIR); + console.log(` Found ${distFiles.length} files in dist/`); + + // Create dist directory on remote + await ssh.execCommand(`mkdir -p ${REMOTE_PATH}/dist`); + + // Transfer dist files + let transferred = 0; + for (const file of distFiles) { + try { + // Create remote directory for this file + const remoteDir = path.dirname(file.remote); + await ssh.execCommand(`mkdir -p ${remoteDir}`); + await ssh.putFile(file.local, file.remote); + transferred++; + if (transferred % 10 === 0) { + console.log(` šŸ“ Transferred ${transferred}/${distFiles.length} files...`); + } + } catch (error) { + console.log(` āš ļø Failed to transfer ${path.relative(DIST_DIR, file.local)}: ${error.message}`); + } + } + console.log(` āœ… Transferred ${transferred} files from dist/`); + + // Now transfer config files const filesToTransfer = [ - { - local: path.join(SOURCE_DIR, 'index.html'), - remote: `${REMOTE_PATH}/index.html` - }, { local: path.join(SOURCE_DIR, 'Dockerfile'), remote: `${REMOTE_PATH}/Dockerfile`