import { execSync } from "child_process"; export class DependencyInstaller { /** * Cài đặt dependencies từ command string * @param command - Lệnh cài đặt, ví dụ: "npm install express axios" * @throws Error nếu cài đặt thất bại */ static install(command: string): void { if (!command || command.trim() === "") { return; // Không có gì để cài đặt } console.log(`📦 Installing dependencies: ${command}`); try { execSync(command, { stdio: "pipe", // Capture output thay vì in ra console encoding: "utf-8", timeout: 5 * 60 * 1000, // Timeout 5 phút }); console.log(`✅ Dependencies installed successfully`); } catch (error: any) { const errorMessage = error.stderr || error.stdout || error.message; console.error(`❌ Failed to install dependencies: ${errorMessage}`); throw new Error( `Failed to install dependencies with command "${command}": ${errorMessage}` ); } } }