fix(services): Improve logging and enhance MongoDB Compass integration
Some checks failed
Default (tags) / security (push) Failing after 1s
Default (tags) / test (push) Failing after 0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped

This commit is contained in:
2025-08-15 09:37:54 +00:00
parent 05b170cbac
commit 7b9ebfdacb
7 changed files with 160 additions and 163 deletions

View File

@@ -1,6 +1,7 @@
import * as plugins from './mod.plugins.js';
import * as helpers from './helpers.js';
import { ServiceManager } from './classes.servicemanager.js';
import { logger } from '../gitzone.logging.js';
export const run = async (argvArg: any) => {
const serviceManager = new ServiceManager();
@@ -76,8 +77,8 @@ async function handleStart(serviceManager: ServiceManager, service: string) {
break;
default:
helpers.printMessage(`Unknown service: ${service}`, 'red');
helpers.printMessage('Use: mongo, s3, or all', 'yellow');
logger.log('error', `Unknown service: ${service}`);
logger.log('note', 'Use: mongo, s3, or all');
break;
}
}
@@ -104,8 +105,8 @@ async function handleStop(serviceManager: ServiceManager, service: string) {
break;
default:
helpers.printMessage(`Unknown service: ${service}`, 'red');
helpers.printMessage('Use: mongo, s3, or all', 'yellow');
logger.log('error', `Unknown service: ${service}`);
logger.log('note', 'Use: mongo, s3, or all');
break;
}
}
@@ -139,28 +140,28 @@ async function handleRestart(serviceManager: ServiceManager, service: string) {
break;
default:
helpers.printMessage(`Unknown service: ${service}`, 'red');
logger.log('error', `Unknown service: ${service}`);
break;
}
}
async function handleRemove(serviceManager: ServiceManager) {
helpers.printHeader('Removing Containers');
helpers.printMessage('⚠️ This will remove containers but preserve data', 'yellow');
logger.log('note', '⚠️ This will remove containers but preserve data');
const shouldContinue = await plugins.smartinteract.SmartInteract.getCliConfirmation('Continue?', false);
if (shouldContinue) {
await serviceManager.removeContainers();
} else {
helpers.printMessage('Cancelled', 'yellow');
logger.log('note', 'Cancelled');
}
}
async function handleClean(serviceManager: ServiceManager) {
helpers.printHeader('Clean All');
helpers.printMessage('⚠️ WARNING: This will remove all containers and data!', 'red');
helpers.printMessage('This action cannot be undone!', 'red');
logger.log('error', '⚠️ WARNING: This will remove all containers and data!');
logger.log('error', 'This action cannot be undone!');
const smartinteraction = new plugins.smartinteract.SmartInteract();
const confirmAnswer = await smartinteraction.askQuestion({
@@ -174,45 +175,45 @@ async function handleClean(serviceManager: ServiceManager) {
await serviceManager.removeContainers();
console.log();
await serviceManager.cleanData();
helpers.printMessage('All cleaned ✓', 'green');
logger.log('ok', 'All cleaned ✓');
} else {
helpers.printMessage('Cancelled', 'yellow');
logger.log('note', 'Cancelled');
}
}
function showHelp() {
helpers.printHeader('GitZone Services Manager');
helpers.printMessage('Usage: gitzone services [command] [options]', 'green');
logger.log('ok', 'Usage: gitzone services [command] [options]');
console.log();
helpers.printMessage('Commands:', 'yellow');
helpers.printMessage(' start [service] Start services (mongo|s3|all)', undefined);
helpers.printMessage(' stop [service] Stop services (mongo|s3|all)', undefined);
helpers.printMessage(' restart [service] Restart services (mongo|s3|all)', undefined);
helpers.printMessage(' status Show service status', undefined);
helpers.printMessage(' config Show current configuration', undefined);
helpers.printMessage(' compass Show MongoDB Compass connection string', undefined);
helpers.printMessage(' logs [service] Show logs (mongo|s3|all) [lines]', undefined);
helpers.printMessage(' remove Remove all containers', undefined);
helpers.printMessage(' clean Remove all containers and data ⚠️', undefined);
helpers.printMessage(' help Show this help message', undefined);
logger.log('note', 'Commands:');
logger.log('info', ' start [service] Start services (mongo|s3|all)');
logger.log('info', ' stop [service] Stop services (mongo|s3|all)');
logger.log('info', ' restart [service] Restart services (mongo|s3|all)');
logger.log('info', ' status Show service status');
logger.log('info', ' config Show current configuration');
logger.log('info', ' compass Show MongoDB Compass connection string');
logger.log('info', ' logs [service] Show logs (mongo|s3|all) [lines]');
logger.log('info', ' remove Remove all containers');
logger.log('info', ' clean Remove all containers and data ⚠️');
logger.log('info', ' help Show this help message');
console.log();
helpers.printMessage('Features:', 'yellow');
helpers.printMessage(' • Auto-creates .nogit/env.json with smart defaults', undefined);
helpers.printMessage(' • Random ports (20000-30000) to avoid conflicts', undefined);
helpers.printMessage(' • Project-specific containers for multi-project support', undefined);
helpers.printMessage(' • Preserves custom configuration values', undefined);
helpers.printMessage(' • MongoDB Compass connection support', undefined);
logger.log('note', 'Features:');
logger.log('info', ' • Auto-creates .nogit/env.json with smart defaults');
logger.log('info', ' • Random ports (20000-30000) to avoid conflicts');
logger.log('info', ' • Project-specific containers for multi-project support');
logger.log('info', ' • Preserves custom configuration values');
logger.log('info', ' • MongoDB Compass connection support');
console.log();
helpers.printMessage('Examples:', 'yellow');
helpers.printMessage(' gitzone services start # Start all services', undefined);
helpers.printMessage(' gitzone services start mongo # Start only MongoDB', undefined);
helpers.printMessage(' gitzone services stop # Stop all services', undefined);
helpers.printMessage(' gitzone services status # Check service status', undefined);
helpers.printMessage(' gitzone services config # Show configuration', undefined);
helpers.printMessage(' gitzone services compass # Get MongoDB Compass connection', undefined);
helpers.printMessage(' gitzone services logs mongo 50 # Show last 50 lines of MongoDB logs', undefined);
logger.log('note', 'Examples:');
logger.log('info', ' gitzone services start # Start all services');
logger.log('info', ' gitzone services start mongo # Start only MongoDB');
logger.log('info', ' gitzone services stop # Stop all services');
logger.log('info', ' gitzone services status # Check service status');
logger.log('info', ' gitzone services config # Show configuration');
logger.log('info', ' gitzone services compass # Get MongoDB Compass connection');
logger.log('info', ' gitzone services logs mongo 50 # Show last 50 lines of MongoDB logs');
}