UNPKG

forge-deploy-cli

Version:

Professional CLI for local deployments with automatic subdomain routing, SSL certificates, and infrastructure management

141 lines 6.82 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.workspaceCommand = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const workspaceManager_1 = require("../services/workspaceManager"); const config_1 = require("../services/config"); exports.workspaceCommand = new commander_1.Command('workspace') .description('Manage workspace configuration and templates') .addCommand(new commander_1.Command('init') .description('Initialize workspace configuration for complex builds') .option('--template <template>', 'Use a predefined template') .option('--interactive', 'Interactive configuration setup') .action(async (options) => { try { const projectPath = process.cwd(); const configService = new config_1.ConfigService(); const workspaceManager = new workspaceManager_1.WorkspaceManager(projectPath); console.log(chalk_1.default.blue('Forge Workspace Configuration')); console.log(chalk_1.default.gray('Setting up deployment workflow for your project...')); console.log(); let workspaceSetup; if (options.template) { const templates = workspaceManager_1.WorkspaceManager.getWorkspaceTemplates(); const template = templates[options.template]; if (!template) { console.log(chalk_1.default.red(`Template "${options.template}" not found`)); console.log(chalk_1.default.gray('Available templates:')); Object.keys(templates).forEach(name => { console.log(` • ${name}`); }); process.exit(1); } const baseSetup = await workspaceManager.analyzeWorkspace(); workspaceSetup = { ...baseSetup, ...template, preDeploySteps: template.preDeploySteps || [], buildSteps: template.buildSteps || [], postDeploySteps: template.postDeploySteps || [] }; console.log(chalk_1.default.green(`Using template: ${options.template}`)); } else if (options.interactive) { workspaceSetup = await workspaceManager.interactiveSetup(); } else { workspaceSetup = await workspaceManager.analyzeWorkspace(); console.log(chalk_1.default.cyan('Auto-detected workspace configuration')); } // Save configuration const currentConfig = await configService.loadProjectConfig() || {}; currentConfig.workspaceSetup = workspaceSetup; await configService.saveProjectConfig(currentConfig); console.log(); console.log(chalk_1.default.green('Workspace configuration saved to forge.config.json')); // Show summary console.log(); console.log(chalk_1.default.blue('Configuration Summary:')); console.log(` Package Manager: ${workspaceSetup.packageManager}`); console.log(` Pre-deploy Steps: ${workspaceSetup.preDeploySteps?.length || 0}`); console.log(` Build Steps: ${workspaceSetup.buildSteps?.length || 0}`); console.log(` Post-deploy Steps: ${workspaceSetup.postDeploySteps?.length || 0}`); if (workspaceSetup.monorepo) { console.log(` Monorepo Type: ${workspaceSetup.monorepo.type}`); } console.log(); console.log(chalk_1.default.gray('Use "forge deploy --use-workspace-config" to deploy with this configuration')); } catch (error) { console.log(chalk_1.default.red('Failed to initialize workspace configuration')); console.error(error); process.exit(1); } })) .addCommand(new commander_1.Command('list-templates') .description('List available workspace templates') .action(() => { const templates = workspaceManager_1.WorkspaceManager.getWorkspaceTemplates(); console.log(chalk_1.default.blue('Available Workspace Templates:')); console.log(); Object.keys(templates).forEach(name => { const template = templates[name]; console.log(chalk_1.default.cyan(`${name}:`)); if (template.preDeploySteps?.length) { console.log(` Pre-deploy: ${template.preDeploySteps.length} steps`); } if (template.buildSteps?.length) { console.log(` Build: ${template.buildSteps.length} steps`); } if (template.postDeploySteps?.length) { console.log(` Post-deploy: ${template.postDeploySteps.length} steps`); } console.log(); }); console.log(chalk_1.default.gray('Use "forge workspace init --template <name>" to use a template')); })) .addCommand(new commander_1.Command('validate') .description('Validate current workspace configuration') .action(async () => { try { const configService = new config_1.ConfigService(); const config = await configService.loadProjectConfig(); if (!config?.workspaceSetup) { console.log(chalk_1.default.yellow('No workspace configuration found')); console.log(chalk_1.default.gray('Run "forge workspace init" to create one')); return; } const workspaceSetup = config.workspaceSetup; console.log(chalk_1.default.blue('Workspace Configuration Validation')); console.log(); // Validate package manager const packageManager = workspaceSetup.packageManager; console.log(`Package Manager: ${chalk_1.default.green(packageManager)}`); // Validate steps const totalSteps = (workspaceSetup.preDeploySteps?.length || 0) + (workspaceSetup.buildSteps?.length || 0) + (workspaceSetup.postDeploySteps?.length || 0); console.log(`Total Steps: ${chalk_1.default.green(totalSteps)}`); if (workspaceSetup.preDeploySteps?.length) { console.log(`Pre-deploy Steps: ${chalk_1.default.cyan(workspaceSetup.preDeploySteps.length)}`); } if (workspaceSetup.buildSteps?.length) { console.log(`Build Steps: ${chalk_1.default.cyan(workspaceSetup.buildSteps.length)}`); } if (workspaceSetup.postDeploySteps?.length) { console.log(`Post-deploy Steps: ${chalk_1.default.cyan(workspaceSetup.postDeploySteps.length)}`); } console.log(); console.log(chalk_1.default.green('Configuration is valid')); } catch (error) { console.log(chalk_1.default.red('Failed to validate workspace configuration')); console.error(error); process.exit(1); } })); //# sourceMappingURL=workspace.js.map