🔨 Add Vue 3 build process and dist directory transfer to deployment script
This commit is contained in:
@@ -47,7 +47,8 @@ const SSH_HOSTS = {
|
|||||||
|
|
||||||
const REMOTE_PATH = '/volume1/docker/pokedex-online/base';
|
const REMOTE_PATH = '/volume1/docker/pokedex-online/base';
|
||||||
const CONTAINER_NAME = 'pokedex-online';
|
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
|
* Parse command line arguments
|
||||||
@@ -212,6 +213,39 @@ async function deploy() {
|
|||||||
});
|
});
|
||||||
console.log('✅ Connected successfully');
|
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
|
// Check if container exists and capture current image
|
||||||
console.log('\n📦 Checking for existing container...');
|
console.log('\n📦 Checking for existing container...');
|
||||||
console.log(` Container name: ${CONTAINER_NAME}`);
|
console.log(` Container name: ${CONTAINER_NAME}`);
|
||||||
@@ -258,11 +292,53 @@ async function deploy() {
|
|||||||
|
|
||||||
// Transfer files
|
// Transfer files
|
||||||
console.log('\n📤 Transferring 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 = [
|
const filesToTransfer = [
|
||||||
{
|
|
||||||
local: path.join(SOURCE_DIR, 'index.html'),
|
|
||||||
remote: `${REMOTE_PATH}/index.html`
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
local: path.join(SOURCE_DIR, 'Dockerfile'),
|
local: path.join(SOURCE_DIR, 'Dockerfile'),
|
||||||
remote: `${REMOTE_PATH}/Dockerfile`
|
remote: `${REMOTE_PATH}/Dockerfile`
|
||||||
|
|||||||
Reference in New Issue
Block a user