forge-deploy-cli
Version:
Professional CLI for local deployments with automatic subdomain routing, SSL certificates, and infrastructure management
356 lines • 15.6 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DependencyInstaller = void 0;
const child_process_1 = require("child_process");
const chalk_1 = __importDefault(require("chalk"));
const types_1 = require("../types");
class DependencyInstaller {
constructor() {
this.platform = process.platform;
}
async installSystemDependencies(framework, targetPlatform) {
console.log(chalk_1.default.blue('Installing system dependencies...'));
// Install base dependencies
await this.installBaseDependencies();
// Install platform-specific dependencies
if (targetPlatform) {
await this.installPlatformDependencies(targetPlatform);
}
else {
// Auto-detect best platform for framework
const platform = this.detectBestPlatform(framework);
await this.installPlatformDependencies(platform);
}
// Install framework-specific dependencies
await this.installFrameworkDependencies(framework);
console.log(chalk_1.default.green('System dependencies installed successfully!'));
}
async installBaseDependencies() {
console.log(chalk_1.default.gray('Installing base dependencies...'));
try {
// Install Node.js if not present
await this.ensureNodeJs();
// Install pnpm if not present
await this.ensurePnpm();
// Install Git if not present
await this.ensureGit();
// Install Docker if not present
await this.ensureDocker();
// Install common build tools
await this.installBuildTools();
}
catch (error) {
console.error(chalk_1.default.red('Failed to install base dependencies:'), error);
throw error;
}
}
async installPlatformDependencies(platform) {
console.log(chalk_1.default.gray(`Installing ${platform} dependencies...`));
switch (platform) {
case types_1.Platform.NGINX:
await this.installNginx();
break;
case types_1.Platform.PM2:
await this.installPM2();
break;
case types_1.Platform.DOCKER:
await this.installDockerCompose();
break;
case types_1.Platform.SYSTEMD:
await this.setupSystemd();
break;
}
}
async installFrameworkDependencies(framework) {
console.log(chalk_1.default.gray(`Installing ${framework} dependencies...`));
switch (framework) {
case types_1.Framework.NEXTJS:
await this.installNextJsDependencies();
break;
case types_1.Framework.REACT:
await this.installReactDependencies();
break;
case types_1.Framework.VUE:
await this.installVueDependencies();
break;
case types_1.Framework.NUXT:
await this.installNuxtDependencies();
break;
case types_1.Framework.SVELTE:
await this.installSvelteDependencies();
break;
case types_1.Framework.ANGULAR:
await this.installAngularDependencies();
break;
case types_1.Framework.EXPRESS:
await this.installExpressDependencies();
break;
case types_1.Framework.FASTIFY:
await this.installFastifyDependencies();
break;
case types_1.Framework.NEST:
await this.installNestDependencies();
break;
case types_1.Framework.DJANGO:
await this.installDjangoDependencies();
break;
case types_1.Framework.FLASK:
await this.installFlaskDependencies();
break;
case types_1.Framework.LARAVEL:
await this.installLaravelDependencies();
break;
case types_1.Framework.STATIC:
// No additional dependencies needed for static sites
break;
}
}
detectBestPlatform(framework) {
// Frontend frameworks work well with nginx
if ([types_1.Framework.REACT, types_1.Framework.VUE, types_1.Framework.ANGULAR, types_1.Framework.SVELTE, types_1.Framework.STATIC].includes(framework)) {
return types_1.Platform.NGINX;
}
// Node.js frameworks work well with PM2
if ([types_1.Framework.NEXTJS, types_1.Framework.NUXT, types_1.Framework.EXPRESS, types_1.Framework.FASTIFY, types_1.Framework.NEST].includes(framework)) {
return types_1.Platform.PM2;
}
// Python frameworks work well with systemd
if ([types_1.Framework.DJANGO, types_1.Framework.FLASK].includes(framework)) {
return types_1.Platform.SYSTEMD;
}
// PHP frameworks work well with nginx
if ([types_1.Framework.LARAVEL].includes(framework)) {
return types_1.Platform.NGINX;
}
// Default to Docker for unknown cases
return types_1.Platform.DOCKER;
}
async ensureNodeJs() {
try {
(0, child_process_1.execSync)('node --version', { stdio: 'ignore' });
console.log(chalk_1.default.green('Node.js is already installed'));
}
catch {
console.log(chalk_1.default.yellow('Installing Node.js...'));
await this.installNodeJs();
}
}
async ensureGit() {
try {
(0, child_process_1.execSync)('git --version', { stdio: 'ignore' });
console.log(chalk_1.default.green('Git is already installed'));
}
catch {
console.log(chalk_1.default.yellow('Installing Git...'));
await this.installGit();
}
}
async ensureDocker() {
try {
(0, child_process_1.execSync)('docker --version', { stdio: 'ignore' });
console.log(chalk_1.default.green('Docker is already installed'));
}
catch {
console.log(chalk_1.default.yellow('Installing Docker...'));
await this.installDocker();
}
}
async ensurePnpm() {
try {
(0, child_process_1.execSync)('pnpm --version', { stdio: 'ignore' });
console.log(chalk_1.default.green('pnpm is already installed'));
}
catch {
console.log(chalk_1.default.yellow('Installing pnpm...'));
await this.installPnpm();
}
}
async installNodeJs() {
if (this.platform === 'win32') {
console.log(chalk_1.default.blue('Please install Node.js from https://nodejs.org/'));
throw new Error('Node.js installation required');
}
else if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install node', { stdio: 'inherit' });
}
else {
// Linux
(0, child_process_1.execSync)('curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -', { stdio: 'inherit' });
(0, child_process_1.execSync)('sudo apt-get install -y nodejs', { stdio: 'inherit' });
}
}
async installGit() {
if (this.platform === 'win32') {
console.log(chalk_1.default.blue('Please install Git from https://git-scm.com/'));
throw new Error('Git installation required');
}
else if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install git', { stdio: 'inherit' });
}
else {
(0, child_process_1.execSync)('sudo apt-get update && sudo apt-get install -y git', { stdio: 'inherit' });
}
}
async installDocker() {
if (this.platform === 'win32') {
console.log(chalk_1.default.blue('Please install Docker Desktop from https://docker.com/'));
throw new Error('Docker installation required');
}
else if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install --cask docker', { stdio: 'inherit' });
}
else {
(0, child_process_1.execSync)('curl -fsSL https://get.docker.com -o get-docker.sh', { stdio: 'inherit' });
(0, child_process_1.execSync)('sh get-docker.sh', { stdio: 'inherit' });
(0, child_process_1.execSync)('sudo usermod -aG docker $USER', { stdio: 'inherit' });
}
}
async installPnpm() {
if (this.platform === 'win32') {
console.log(chalk_1.default.blue('Please install pnpm from https://pnpm.js.org/'));
throw new Error('pnpm installation required');
}
else {
(0, child_process_1.execSync)('npm install -g pnpm', { stdio: 'inherit' });
}
}
async installBuildTools() {
if (this.platform === 'darwin') {
try {
(0, child_process_1.execSync)('xcode-select --install', { stdio: 'ignore' });
}
catch {
// Xcode tools already installed
}
}
else if (this.platform === 'linux') {
(0, child_process_1.execSync)('sudo apt-get install -y build-essential', { stdio: 'inherit' });
}
}
async installNginx() {
console.log(chalk_1.default.gray('Installing Nginx...'));
if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install nginx', { stdio: 'inherit' });
}
else if (this.platform === 'linux') {
(0, child_process_1.execSync)('sudo apt-get update && sudo apt-get install -y nginx', { stdio: 'inherit' });
}
else {
console.log(chalk_1.default.yellow('Please install Nginx manually on Windows'));
}
}
async installPM2() {
console.log(chalk_1.default.gray('Installing PM2...'));
(0, child_process_1.execSync)('pnpm add -g pm2', { stdio: 'inherit' });
}
async installDockerCompose() {
console.log(chalk_1.default.gray('Installing Docker Compose...'));
if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install docker-compose', { stdio: 'inherit' });
}
else if (this.platform === 'linux') {
(0, child_process_1.execSync)('sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose', { stdio: 'inherit' });
(0, child_process_1.execSync)('sudo chmod +x /usr/local/bin/docker-compose', { stdio: 'inherit' });
}
}
async setupSystemd() {
console.log(chalk_1.default.gray('Setting up Systemd configuration...'));
// Systemd is typically pre-installed on Linux systems
if (this.platform !== 'linux') {
console.log(chalk_1.default.yellow('Systemd is only available on Linux systems'));
}
}
// Framework-specific dependency installations
async installNextJsDependencies() {
console.log(chalk_1.default.gray('Installing Next.js build dependencies...'));
// Next.js will be installed via package.json
}
async installReactDependencies() {
console.log(chalk_1.default.gray('Installing React build dependencies...'));
// React dependencies will be handled via package.json
}
async installVueDependencies() {
console.log(chalk_1.default.gray('Installing Vue.js build dependencies...'));
(0, child_process_1.execSync)('pnpm add -g @vue/cli', { stdio: 'inherit' });
}
async installNuxtDependencies() {
console.log(chalk_1.default.gray('Installing Nuxt.js build dependencies...'));
(0, child_process_1.execSync)('pnpm add -g create-nuxt-app', { stdio: 'inherit' });
}
async installSvelteDependencies() {
console.log(chalk_1.default.gray('Installing Svelte build dependencies...'));
// Svelte dependencies will be handled via package.json
}
async installAngularDependencies() {
console.log(chalk_1.default.gray('Installing Angular build dependencies...'));
(0, child_process_1.execSync)('pnpm add -g @angular/cli', { stdio: 'inherit' });
}
async installExpressDependencies() {
console.log(chalk_1.default.gray('Installing Express.js dependencies...'));
(0, child_process_1.execSync)('pnpm add -g express-generator', { stdio: 'inherit' });
}
async installFastifyDependencies() {
console.log(chalk_1.default.gray('Installing Fastify dependencies...'));
(0, child_process_1.execSync)('pnpm add -g fastify-cli', { stdio: 'inherit' });
}
async installNestDependencies() {
console.log(chalk_1.default.gray('Installing NestJS dependencies...'));
(0, child_process_1.execSync)('pnpm add -g @nestjs/cli', { stdio: 'inherit' });
}
async installDjangoDependencies() {
console.log(chalk_1.default.gray('Installing Django dependencies...'));
try {
(0, child_process_1.execSync)('python3 --version', { stdio: 'ignore' });
}
catch {
if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install python3', { stdio: 'inherit' });
}
else if (this.platform === 'linux') {
(0, child_process_1.execSync)('sudo apt-get install -y python3 python3-pip', { stdio: 'inherit' });
}
}
(0, child_process_1.execSync)('pip3 install django gunicorn', { stdio: 'inherit' });
}
async installFlaskDependencies() {
console.log(chalk_1.default.gray('Installing Flask dependencies...'));
try {
(0, child_process_1.execSync)('python3 --version', { stdio: 'ignore' });
}
catch {
if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install python3', { stdio: 'inherit' });
}
else if (this.platform === 'linux') {
(0, child_process_1.execSync)('sudo apt-get install -y python3 python3-pip', { stdio: 'inherit' });
}
}
(0, child_process_1.execSync)('pip3 install flask gunicorn', { stdio: 'inherit' });
}
async installLaravelDependencies() {
console.log(chalk_1.default.gray('Installing Laravel dependencies...'));
try {
(0, child_process_1.execSync)('php --version', { stdio: 'ignore' });
}
catch {
if (this.platform === 'darwin') {
(0, child_process_1.execSync)('brew install php', { stdio: 'inherit' });
}
else if (this.platform === 'linux') {
(0, child_process_1.execSync)('sudo apt-get install -y php php-cli php-fpm php-mysql php-xml php-mbstring', { stdio: 'inherit' });
}
}
try {
(0, child_process_1.execSync)('composer --version', { stdio: 'ignore' });
}
catch {
(0, child_process_1.execSync)('curl -sS https://getcomposer.org/installer | php', { stdio: 'inherit' });
(0, child_process_1.execSync)('sudo mv composer.phar /usr/local/bin/composer', { stdio: 'inherit' });
}
}
}
exports.DependencyInstaller = DependencyInstaller;
//# sourceMappingURL=dependencies.js.map