UNPKG

@logistically/i18n-cli

Version:

Enterprise-grade CLI tool for extracting and managing translations in Logistically microservices

478 lines (353 loc) โ€ข 10.8 kB
# Enterprise-Grade Features This document outlines the enterprise-grade features that have been added to the `@onwello/translation-cli` to make it production-ready for large-scale deployments. ## ๐Ÿข Enterprise Features Overview ### 1. Configuration Management - **Environment-based configuration**: Different settings for development, staging, and production - **Configuration validation**: Automatic validation of configuration settings - **Command-line overrides**: Override any configuration via command-line options - **Environment variables**: Full support for environment variable configuration ### 2. Performance Monitoring - **Real-time metrics**: Track processing speed, memory usage, and CPU usage - **Progress tracking**: Visual progress bars with ETA and speed indicators - **Concurrent processing**: Configurable parallel file processing - **Performance optimization**: Automatic file size filtering and batch processing ### 3. Security & Validation - **Input validation**: Comprehensive validation of all inputs - **Output sanitization**: Automatic sanitization of potentially dangerous content - **Path validation**: Security checks for file paths and traversal attempts - **Content filtering**: Detection and handling of suspicious content ### 4. Advanced Logging - **Structured logging**: JSON and text format support - **Context-aware logging**: Log entries with context and metadata - **File logging**: Log to files with rotation and buffering - **Log levels**: Configurable log levels (debug, info, warn, error) ### 5. Error Handling & Recovery - **Graceful error handling**: Continue processing even when individual files fail - **Comprehensive error reporting**: Detailed error messages with context - **Recovery mechanisms**: Automatic retry and fallback strategies - **Validation reporting**: Detailed validation error and warning reports ## ๐Ÿ”ง Configuration ### Environment Variables ```bash # Environment NODE_ENV=production # development/staging/production LOG_LEVEL=info # debug/info/warn/error LOG_FORMAT=json # text/json LOG_OUTPUT=both # console/file/both LOG_FILE=/var/log/translation-cli.log # Log file path # Performance MAX_CONCURRENCY=8 # Max concurrent file processing MAX_FILE_SIZE=50 # Max file size in MB TIMEOUT=600 # Operation timeout in seconds # Security VALIDATE_INPUTS=true # Enable input validation SANITIZE_OUTPUTS=true # Enable output sanitization MAX_KEY_LENGTH=200 # Max translation key length # Features ENABLE_VALIDATION=true # Enable validation features ENABLE_BACKUP=true # Enable backup features ENABLE_DRY_RUN=true # Enable dry run features ENABLE_PROGRESS_BAR=true # Enable progress bar ``` ### Configuration File Create `.translation-cli.json` in your project root: ```json { "version": "2.0.0", "environment": "production", "logging": { "level": "warn", "format": "json", "output": "both", "filePath": "/var/log/translation-cli.log" }, "performance": { "maxConcurrency": 8, "maxFileSize": 50, "timeout": 600 }, "security": { "validateInputs": true, "sanitizeOutputs": true, "maxKeyLength": 200 }, "features": { "enableValidation": true, "enableBackup": true, "enableDryRun": true, "enableProgressBar": true } } ``` ## ๐Ÿš€ Performance Features ### Concurrent Processing The CLI now supports concurrent file processing to significantly improve performance: ```bash # Process 8 files concurrently translation extract --max-concurrency 8 # Environment variable MAX_CONCURRENCY=8 translation extract ``` ### File Size Filtering Automatically skip files that are too large to process efficiently: ```bash # Skip files larger than 50MB translation extract --max-file-size 50 # Environment variable MAX_FILE_SIZE=50 translation extract ``` ### Progress Tracking Real-time progress bars with speed and ETA information: ```bash # Enable progress bar translation extract --enable-progress-bar # Environment variable ENABLE_PROGRESS_BAR=true translation extract ``` ## ๐Ÿ”’ Security Features ### Input Validation All inputs are validated for security and correctness: ```bash # Enable input validation translation extract --validate-inputs # Environment variable VALIDATE_INPUTS=true translation extract ``` ### Output Sanitization Automatically sanitize outputs to prevent security issues: ```bash # Enable output sanitization translation extract --sanitize-outputs # Environment variable SANITIZE_OUTPUTS=true translation extract ``` ### Path Validation Security checks for file paths to prevent traversal attacks: ```typescript // Automatically validates all file paths const validation = validator.validatePath('/safe/path'); if (!validation.isValid) { // Handle invalid path } ``` ## ๐Ÿ“Š Monitoring & Metrics ### Performance Metrics Track detailed performance metrics: ```typescript const metrics = performanceMonitor.endMonitoring(); console.log(`Duration: ${metrics.duration}ms`); console.log(`Files Processed: ${metrics.filesProcessed}`); console.log(`Total Keys: ${metrics.totalKeys}`); console.log(`Memory Usage: ${metrics.memoryUsage}MB`); console.log(`CPU Usage: ${metrics.cpuUsage}s`); ``` ### Logging with Context Structured logging with context and metadata: ```typescript logger.info('Processing file', 'extraction', { file: 'auth/service.ts', size: '2.5MB', keys: 15 }); ``` ## ๐Ÿ› ๏ธ Configuration Management ### Show Configuration ```bash # Show current configuration translation config show # Show detailed configuration translation config show --verbose ``` ### Validate Configuration ```bash # Validate current configuration translation config validate ``` ### Set Configuration Values ```bash # Set log level translation config set logging.level debug # Set max concurrency translation config set performance.maxConcurrency 8 # Set security settings translation config set security.validateInputs true ``` ### Reset Configuration ```bash # Reset to default configuration translation config reset ``` ## ๐Ÿ” Validation System ### Translation Key Validation ```typescript const validation = validator.validateTranslationKey({ key: 'AUTH.USER_EXISTS', text: 'User already exists', type: 'EXCEPTION', file: '/path/to/file.ts', line: 10 }); if (!validation.isValid) { logger.logValidationErrors(validation.errors, 'extraction'); } ``` ### Content Security ```typescript // Detect suspicious content const validation = validator.validateInputString( '<script>alert("xss")</script>', 'user input' ); if (validation.warnings.length > 0) { logger.logValidationWarnings(validation.warnings, 'security'); } ``` ## ๐Ÿ“ˆ Performance Optimization ### Batch Processing Files are processed in configurable batches for optimal performance: ```typescript // Process files in batches of 8 const batchSize = 8; for (let i = 0; i < files.length; i += batchSize) { const batch = files.slice(i, i + batchSize); await Promise.allSettled(batch.map(processFile)); } ``` ### Memory Management Automatic memory usage tracking and optimization: ```typescript const memoryUsage = process.memoryUsage(); const heapUsedMB = memoryUsage.heapUsed / 1024 / 1024; if (heapUsedMB > 100) { logger.warning('High memory usage detected', 'performance'); } ``` ## ๐Ÿงช Testing ### Enterprise Feature Tests ```bash # Run enterprise feature tests npm run test:enterprise # Run performance tests npm run performance:test # Run validation tests npm run validation:test ``` ### Security Tests ```bash # Run security audit npm run security:audit # Fix security issues npm run security:fix ``` ## ๐Ÿ”„ CI/CD Integration ### GitHub Actions Example ```yaml name: Translation CLI Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' - name: Install dependencies run: npm ci - name: Run tests run: npm test - name: Run enterprise tests run: npm run test:enterprise - name: Security audit run: npm run security:audit - name: Build run: npm run build ``` ## ๐Ÿ“‹ Migration Guide ### From v1.0.0 to v2.0.0 1. **Update package.json**: ```json { "dependencies": { "@onwello/translation-cli": "^2.0.0" } } ``` 2. **Create configuration file**: ```bash translation config show > .translation-cli.json ``` 3. **Update environment variables**: ```bash export NODE_ENV=production export LOG_LEVEL=warn export MAX_CONCURRENCY=8 ``` 4. **Update CI/CD pipelines**: - Add enterprise tests - Add security audits - Add performance monitoring ## ๐ŸŽฏ Best Practices ### Production Deployment 1. **Use production environment**: ```bash NODE_ENV=production translation extract ``` 2. **Enable all security features**: ```bash VALIDATE_INPUTS=true SANITIZE_OUTPUTS=true translation extract ``` 3. **Configure logging**: ```bash LOG_FORMAT=json LOG_OUTPUT=both LOG_FILE=/var/log/translation-cli.log ``` 4. **Set performance limits**: ```bash MAX_CONCURRENCY=8 MAX_FILE_SIZE=50 TIMEOUT=600 ``` ### Development 1. **Use development environment**: ```bash NODE_ENV=development translation extract ``` 2. **Enable verbose logging**: ```bash LOG_LEVEL=debug translation extract -v ``` 3. **Use dry run for testing**: ```bash translation replace --dry-run ``` ## ๐Ÿ†˜ Troubleshooting ### Common Issues 1. **High memory usage**: - Reduce `MAX_CONCURRENCY` - Reduce `MAX_FILE_SIZE` - Enable file filtering 2. **Slow processing**: - Increase `MAX_CONCURRENCY` - Check file sizes - Monitor system resources 3. **Validation errors**: - Check input files - Review configuration - Enable verbose logging ### Debug Mode ```bash # Enable debug logging LOG_LEVEL=debug translation extract -v # Show detailed configuration translation config show --verbose # Validate configuration translation config validate ``` ## ๐Ÿ“ž Support For enterprise support and custom features: - **Email**: enterprise@onwello.com - **Documentation**: https://docs.onwello.com/translation-cli - **Issues**: https://github.com/onwello/i18n-cli/issues - **Enterprise**: https://onwello.com/enterprise --- **Enterprise-Grade Translation CLI v2.0.0** - Built for scale, security, and performance. ๐Ÿš€