UNPKG

forge-deploy-cli

Version:

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

195 lines 7.68 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.configCommand = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = __importDefault(require("inquirer")); const config_1 = require("../services/config"); exports.configCommand = new commander_1.Command('config') .description('Manage configuration settings') .option('--set <key=value>', 'Set a configuration value') .option('--get <key>', 'Get a configuration value') .option('--list', 'List all configuration values') .option('--global', 'Operate on global configuration') .option('--project', 'Operate on project configuration') .action(async (options) => { try { const configService = new config_1.ConfigService(); if (options.list) { await listConfiguration(configService, options.global, options.project); } else if (options.get) { await getConfiguration(configService, options.get, options.global, options.project); } else if (options.set) { await setConfiguration(configService, options.set, options.global, options.project); } else { // Interactive configuration await interactiveConfig(configService); } } catch (error) { console.log(chalk_1.default.red(`Error: ${error}`)); process.exit(1); } }); async function listConfiguration(configService, global, project) { if (global || (!global && !project)) { console.log(chalk_1.default.blue('Global Configuration:')); const globalConfig = await configService.loadGlobalConfig(); if (globalConfig) { Object.entries(globalConfig).forEach(([key, value]) => { if (key === 'apiKey' && value) { console.log(` ${chalk_1.default.cyan(key)}: ${chalk_1.default.gray('***masked***')}`); } else { console.log(` ${chalk_1.default.cyan(key)}: ${chalk_1.default.white(value)}`); } }); } else { console.log(chalk_1.default.gray(' No global configuration found')); } console.log(); } if (project || (!global && !project)) { console.log(chalk_1.default.blue('Project Configuration:')); const projectConfig = await configService.loadProjectConfig(); if (projectConfig) { Object.entries(projectConfig).forEach(([key, value]) => { console.log(` ${chalk_1.default.cyan(key)}: ${chalk_1.default.white(value)}`); }); } else { console.log(chalk_1.default.gray(' No project configuration found')); console.log(chalk_1.default.gray(' Run "forge init" to initialize a project')); } } } async function getConfiguration(configService, key, global, project) { let config = null; if (global) { config = await configService.loadGlobalConfig(); } else if (project) { config = await configService.loadProjectConfig(); } else { // Try project first, then global config = await configService.loadProjectConfig() || await configService.loadGlobalConfig(); } if (!config) { console.log(chalk_1.default.yellow('No configuration found')); return; } const value = config[key]; if (value !== undefined) { if (key === 'apiKey' && value) { console.log(chalk_1.default.gray('***masked***')); } else { console.log(chalk_1.default.white(value)); } } else { console.log(chalk_1.default.yellow(`Configuration key "${key}" not found`)); } } async function setConfiguration(configService, keyValue, global, project) { const [key, ...valueParts] = keyValue.split('='); const value = valueParts.join('='); if (!key || !value) { console.log(chalk_1.default.red('Error: Invalid format. Use --set key=value')); return; } if (global) { const existingConfig = await configService.loadGlobalConfig() || {}; existingConfig[key] = value; await configService.saveGlobalConfig(existingConfig); console.log(chalk_1.default.green(`Global configuration updated: ${key}`)); } else if (project) { const existingConfig = await configService.loadProjectConfig(); if (!existingConfig) { console.log(chalk_1.default.red('Error: No project configuration found')); console.log('Run "forge init" to initialize a project'); return; } existingConfig[key] = value; await configService.saveProjectConfig(existingConfig); console.log(chalk_1.default.green(`Project configuration updated: ${key}`)); } else { console.log(chalk_1.default.yellow('Please specify --global or --project flag')); } } async function interactiveConfig(configService) { console.log(chalk_1.default.blue('Interactive Configuration')); console.log(chalk_1.default.gray('Configure your Forge CLI settings')); console.log(); const { configType } = await inquirer_1.default.prompt([ { type: 'list', name: 'configType', message: 'Which configuration would you like to modify?', choices: [ { name: 'Global Configuration', value: 'global' }, { name: 'Project Configuration', value: 'project' }, { name: 'View All Settings', value: 'view' } ] } ]); if (configType === 'view') { await listConfiguration(configService, false, false); return; } if (configType === 'global') { const globalConfig = await configService.loadGlobalConfig() || {}; const { apiUrl } = await inquirer_1.default.prompt([ { type: 'input', name: 'apiUrl', message: 'API URL:', default: globalConfig.apiUrl || 'https://api.forgecli.tech' } ]); await configService.saveGlobalConfig({ ...globalConfig, apiUrl }); console.log(chalk_1.default.green('Global configuration saved')); } else if (configType === 'project') { const projectConfig = await configService.loadProjectConfig(); if (!projectConfig) { console.log(chalk_1.default.red('Error: No project configuration found')); console.log('Run "forge init" to initialize a project'); return; } const answers = await inquirer_1.default.prompt([ { type: 'input', name: 'projectName', message: 'Project name:', default: projectConfig.projectName }, { type: 'input', name: 'buildCommand', message: 'Build command:', default: projectConfig.buildCommand }, { type: 'input', name: 'outputDirectory', message: 'Output directory:', default: projectConfig.outputDirectory } ]); const updatedConfig = { ...projectConfig, ...answers }; await configService.saveProjectConfig(updatedConfig); console.log(chalk_1.default.green('Project configuration saved')); } } //# sourceMappingURL=config.js.map