forge-deploy-cli
Version:
Professional CLI for local deployments with automatic subdomain routing, SSL certificates, and infrastructure management
372 lines • 17.6 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const inquirer_1 = __importDefault(require("inquirer"));
const dependencies_1 = require("../installers/dependencies");
const autoRestart_1 = require("../services/autoRestart");
const system_1 = require("../utils/system");
const types_1 = require("../types");
exports.setupCommand = new commander_1.Command('setup')
.description('Set up system dependencies and environment')
.option('--platform <platform>', 'Target platform (nodejs, python, php, static)')
.option('--framework <framework>', 'Target framework')
.option('--skip-install', 'Skip dependency installation')
.option('--auto-restart', 'Setup auto-restart service')
.option('--remove-auto-restart', 'Remove auto-restart service')
.option('--status', 'Show current setup status')
.option('--list-platforms', 'List supported platforms')
.option('--list-frameworks', 'List supported frameworks')
.action(async (options) => {
try {
if (options.listPlatforms) {
listPlatforms();
return;
}
if (options.listFrameworks) {
listFrameworks();
return;
}
if (options.status) {
await showSetupStatus();
return;
}
if (options.removeAutoRestart) {
await removeAutoRestart();
return;
}
if (options.autoRestart) {
await setupAutoRestart();
return;
}
console.log(chalk_1.default.blue('Forge CLI Setup'));
console.log(chalk_1.default.gray('Setting up your development environment...'));
console.log();
let platform;
let framework;
if (options.platform) {
platform = options.platform;
if (!Object.values(types_1.DevPlatform).includes(platform)) {
console.log(chalk_1.default.red(`Error: Unsupported platform "${options.platform}"`));
console.log('Run "forge setup --list-platforms" to see supported platforms');
process.exit(1);
}
}
else {
const { selectedPlatform } = await inquirer_1.default.prompt([
{
type: 'list',
name: 'selectedPlatform',
message: 'Select your primary development platform:',
choices: [
{ name: 'Node.js (JavaScript/TypeScript)', value: types_1.DevPlatform.NODEJS },
{ name: 'Python', value: types_1.DevPlatform.PYTHON },
{ name: 'PHP', value: types_1.DevPlatform.PHP },
{ name: 'Static Sites (HTML/CSS/JS)', value: types_1.DevPlatform.STATIC }
]
}
]);
platform = selectedPlatform;
}
if (options.framework) {
framework = options.framework;
if (!Object.values(types_1.Framework).includes(framework)) {
console.log(chalk_1.default.red(`Error: Unsupported framework "${options.framework}"`));
console.log('Run "forge setup --list-frameworks" to see supported frameworks');
process.exit(1);
}
}
else if (platform === types_1.DevPlatform.NODEJS) {
const { selectedFramework } = await inquirer_1.default.prompt([
{
type: 'list',
name: 'selectedFramework',
message: 'Select a Node.js framework (optional):',
choices: [
{ name: 'Next.js', value: types_1.Framework.NEXTJS },
{ name: 'Nuxt.js', value: types_1.Framework.NUXT },
{ name: 'Vue.js', value: types_1.Framework.VUE },
{ name: 'React', value: types_1.Framework.REACT },
{ name: 'Express.js', value: types_1.Framework.EXPRESS },
{ name: 'None/Vanilla Node.js', value: null }
]
}
]);
framework = selectedFramework;
}
if (!options.skipInstall) {
console.log(chalk_1.default.blue('Installing dependencies...'));
console.log(chalk_1.default.gray('This may take a few minutes...'));
console.log();
const installer = new dependencies_1.DependencyInstaller();
if (framework) {
console.log(chalk_1.default.cyan(`Installing ${framework} dependencies for ${platform}...`));
await installer.installSystemDependencies(framework);
}
else {
// Install base dependencies for the platform
console.log(chalk_1.default.cyan(`Installing base dependencies for ${platform}...`));
const defaultFramework = getDefaultFramework(platform);
if (defaultFramework) {
await installer.installSystemDependencies(defaultFramework);
}
}
console.log();
console.log(chalk_1.default.green('Dependencies installed successfully!'));
}
else {
console.log(chalk_1.default.yellow('Skipping dependency installation'));
}
// Simple verification by checking if common tools exist
console.log(chalk_1.default.blue('Verifying installation...'));
const verification = await verifyBasicInstallation(platform, framework);
console.log();
console.log(chalk_1.default.blue('Installation Summary:'));
verification.forEach((item) => {
const status = item.installed ? chalk_1.default.green('✓') : chalk_1.default.red('✗');
console.log(` ${status} ${item.name}: ${item.version || 'Not found'}`);
});
const allInstalled = verification.every((item) => item.installed);
console.log();
if (allInstalled) {
console.log(chalk_1.default.green('Setup completed successfully!'));
console.log(chalk_1.default.gray('You can now run "forge init" to start a new project'));
}
else {
console.log(chalk_1.default.yellow('Setup completed with some issues'));
console.log(chalk_1.default.gray('Some dependencies may need manual installation'));
}
}
catch (error) {
console.log(chalk_1.default.red(`Error: ${error}`));
process.exit(1);
}
});
function listPlatforms() {
console.log(chalk_1.default.blue('Supported Platforms:'));
console.log();
console.log(chalk_1.default.cyan('nodejs') + chalk_1.default.gray(' - Node.js applications (JavaScript/TypeScript)'));
console.log(chalk_1.default.cyan('python') + chalk_1.default.gray(' - Python applications (Django, Flask, FastAPI)'));
console.log(chalk_1.default.cyan('php') + chalk_1.default.gray(' - PHP applications (Laravel, Symfony, WordPress)'));
console.log(chalk_1.default.cyan('static') + chalk_1.default.gray(' - Static websites (HTML/CSS/JS)'));
console.log();
console.log(chalk_1.default.gray('Use: forge setup --platform <platform>'));
}
function listFrameworks() {
console.log(chalk_1.default.blue('Supported Frameworks:'));
console.log();
console.log(chalk_1.default.yellow('Node.js:'));
console.log(chalk_1.default.cyan(' nextjs') + chalk_1.default.gray(' - Next.js React framework'));
console.log(chalk_1.default.cyan(' nuxtjs') + chalk_1.default.gray(' - Nuxt.js Vue framework'));
console.log(chalk_1.default.cyan(' vue') + chalk_1.default.gray(' - Vue.js frontend framework'));
console.log(chalk_1.default.cyan(' react') + chalk_1.default.gray(' - React frontend library'));
console.log(chalk_1.default.cyan(' express') + chalk_1.default.gray(' - Express.js backend framework'));
console.log(chalk_1.default.cyan(' angular') + chalk_1.default.gray(' - Angular frontend framework'));
console.log(chalk_1.default.cyan(' svelte') + chalk_1.default.gray(' - Svelte frontend framework'));
console.log();
console.log(chalk_1.default.yellow('Python:'));
console.log(chalk_1.default.cyan(' django') + chalk_1.default.gray(' - Django web framework'));
console.log(chalk_1.default.cyan(' flask') + chalk_1.default.gray(' - Flask micro framework'));
console.log(chalk_1.default.cyan(' fastapi') + chalk_1.default.gray(' - FastAPI modern framework'));
console.log();
console.log(chalk_1.default.yellow('PHP:'));
console.log(chalk_1.default.cyan(' laravel') + chalk_1.default.gray(' - Laravel web framework'));
console.log(chalk_1.default.cyan(' symfony') + chalk_1.default.gray(' - Symfony web framework'));
console.log(chalk_1.default.cyan(' wordpress') + chalk_1.default.gray(' - WordPress CMS'));
console.log();
console.log(chalk_1.default.gray('Use: forge setup --framework <framework>'));
}
function getDefaultFramework(platform) {
switch (platform) {
case types_1.DevPlatform.NODEJS:
return types_1.Framework.EXPRESS; // Default to Express for Node.js
case types_1.DevPlatform.PYTHON:
return types_1.Framework.FLASK; // Default to Flask for Python
case types_1.DevPlatform.PHP:
return types_1.Framework.LARAVEL; // Default to Laravel for PHP
case types_1.DevPlatform.STATIC:
return types_1.Framework.STATIC;
default:
return null;
}
}
async function verifyBasicInstallation(platform, framework) {
const results = [];
// Check Node.js
try {
const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
const version = execSync('node --version', { encoding: 'utf8' }).trim();
results.push({ name: 'Node.js', installed: true, version });
}
catch {
results.push({ name: 'Node.js', installed: false });
}
// Check pnpm
try {
const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
const version = execSync('pnpm --version', { encoding: 'utf8' }).trim();
results.push({ name: 'pnpm', installed: true, version });
}
catch {
results.push({ name: 'pnpm', installed: false });
}
// Check Git
try {
const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
const version = execSync('git --version', { encoding: 'utf8' }).trim();
results.push({ name: 'Git', installed: true, version });
}
catch {
results.push({ name: 'Git', installed: false });
}
// Check Docker
try {
const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
const version = execSync('docker --version', { encoding: 'utf8' }).trim();
results.push({ name: 'Docker', installed: true, version });
}
catch {
results.push({ name: 'Docker', installed: false });
}
// Platform-specific checks
if (platform === types_1.DevPlatform.PYTHON) {
try {
const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
const version = execSync('python3 --version', { encoding: 'utf8' }).trim();
results.push({ name: 'Python3', installed: true, version });
}
catch {
results.push({ name: 'Python3', installed: false });
}
}
if (platform === types_1.DevPlatform.PHP) {
try {
const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
const version = execSync('php --version', { encoding: 'utf8' }).split('\n')[0];
results.push({ name: 'PHP', installed: true, version });
}
catch {
results.push({ name: 'PHP', installed: false });
}
}
return results;
}
async function setupAutoRestart() {
console.log(chalk_1.default.cyan('Setting up auto-restart service...'));
if (!(0, system_1.isElevated)()) {
console.log(chalk_1.default.yellow('Warning: Auto-restart setup may require administrator/root privileges'));
console.log(chalk_1.default.gray('Some features may not be available without elevated permissions'));
}
try {
await autoRestart_1.AutoRestartService.setupAutoRestart();
console.log(chalk_1.default.green('Auto-restart service configured successfully'));
const { startNow } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'startNow',
message: 'Start the auto-restart service now?',
default: true
}
]);
if (startNow) {
await autoRestart_1.AutoRestartService.startAutoRestart();
}
}
catch (error) {
console.log(chalk_1.default.red(`Failed to setup auto-restart: ${error}`));
}
}
async function removeAutoRestart() {
console.log(chalk_1.default.cyan('Removing auto-restart service...'));
try {
await autoRestart_1.AutoRestartService.removeAutoRestart();
console.log(chalk_1.default.green('Auto-restart service removed successfully'));
}
catch (error) {
console.log(chalk_1.default.red(`Failed to remove auto-restart: ${error}`));
}
}
async function showSetupStatus() {
console.log(chalk_1.default.blue('Forge CLI Setup Status'));
console.log();
const systemInfo = (0, system_1.getSystemInfo)();
console.log(chalk_1.default.blue('System Information:'));
console.log(` ${chalk_1.default.cyan('Platform:')} ${systemInfo.platform} (${systemInfo.arch})`);
console.log(` ${chalk_1.default.cyan('Hostname:')} ${systemInfo.hostname}`);
console.log(` ${chalk_1.default.cyan('Uptime:')} ${Math.floor(systemInfo.uptime / 3600)} hours`);
console.log(` ${chalk_1.default.cyan('Local IP:')} ${systemInfo.localIP}`);
console.log(` ${chalk_1.default.cyan('Elevated:')} ${systemInfo.isElevated ? 'Yes' : 'No'}`);
console.log();
// Check auto-restart status
const autoRestartEnabled = await autoRestart_1.AutoRestartService.isAutoRestartEnabled();
console.log(chalk_1.default.blue('Services:'));
console.log(` ${chalk_1.default.cyan('Auto-restart:')} ${autoRestartEnabled ? chalk_1.default.green('Enabled') : chalk_1.default.red('Disabled')}`);
if (autoRestartEnabled) {
console.log(chalk_1.default.gray(' The CLI will automatically restart after system reboots'));
}
else {
console.log(chalk_1.default.gray(' Run "forge setup --auto-restart" to enable'));
}
console.log();
// Check basic installations
try {
const installations = await verifyBasicInstallation(types_1.DevPlatform.NODEJS);
console.log(chalk_1.default.blue('Dependencies:'));
installations.forEach(dep => {
const status = dep.installed ? chalk_1.default.green('✓') : chalk_1.default.red('✗');
const version = dep.version ? chalk_1.default.gray(`(${dep.version})`) : '';
console.log(` ${status} ${dep.name} ${version}`);
});
console.log();
}
catch (error) {
console.log(chalk_1.default.yellow('Could not verify dependencies'));
}
// Recommendations
console.log(chalk_1.default.blue('Recommendations:'));
if (!autoRestartEnabled) {
console.log(chalk_1.default.yellow(' • Enable auto-restart for better uptime'));
}
if (!systemInfo.isElevated) {
console.log(chalk_1.default.yellow(' • Run with elevated privileges for full functionality'));
}
console.log(chalk_1.default.gray(' • Use "forge deploy" to start deploying your applications'));
}
//# sourceMappingURL=setup.js.map