UNPKG

fast-deployment

Version:

A lightweight Node.js package for rapid deployment of Vue.js, Next.js, and Nuxt.js applications

56 lines (55 loc) 2.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.deploy = deploy; const promises_1 = __importDefault(require("fs/promises")); const config_1 = require("./config"); const build_1 = require("./build"); const archive_1 = require("./archive"); const ssh_1 = require("./ssh"); /** * Main deployment function that orchestrates the entire process * @returns A promise that resolves when the deployment is complete */ async function deploy() { let archivePath; try { console.log('Starting deployment process...'); // 1. Load configuration const config = (0, config_1.loadConfig)(); console.log(`Loaded configuration for ${config.appType} application`); // 2. Build the application await (0, build_1.buildApplication)(config); // 3. Create archive archivePath = await (0, archive_1.createArchive)(config); console.log(`Created archive at ${archivePath}`); // 4. Deploy to server await (0, ssh_1.deployToServer)(config, archivePath); // 5. Clean up local archive await promises_1.default.unlink(archivePath); console.log(`Cleaned up local archive ${archivePath}`); console.log('Deployment completed successfully!'); } catch (error) { if (error instanceof Error) { console.error(`Deployment failed: ${error.message}`); console.error(error.stack); } else { console.error(`Deployment failed with an unknown error: ${String(error)}`); } // Clean up archive if it was created, even on error if (archivePath) { try { await promises_1.default.unlink(archivePath); console.log(`Cleaned up local archive ${archivePath} after error`); } catch (cleanupError) { console.error(`Failed to clean up archive: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`); } } throw error; } }